Commit 29e0b2df by Jan Hrabal

db

parent 660b9f0a
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
......
...@@ -31,8 +31,7 @@ CREATE TABLE APP_USER ( ...@@ -31,8 +31,7 @@ CREATE TABLE APP_USER (
ROLE VARCHAR(100), ROLE VARCHAR(100),
UNIT_ID INT8, UNIT_ID INT8,
CONSTRAINT PK_APP_USER PRIMARY KEY(ID), CONSTRAINT PK_APP_USER PRIMARY KEY(ID)
CONSTRAINT FK_APP_USER_UNIT FOREIGN KEY (UNIT_ID) REFERENCES UNIT(ID)
); );
CREATE INDEX APP_USER_EMAIL_IDX ON APP_USER(lower(EMAIL)); CREATE INDEX APP_USER_EMAIL_IDX ON APP_USER(lower(EMAIL));
...@@ -96,7 +95,7 @@ CREATE TABLE SECTION ( ...@@ -96,7 +95,7 @@ CREATE TABLE SECTION (
NAME VARCHAR, NAME VARCHAR,
CONSTRAINT PK_RATING PRIMARY KEY(ID) CONSTRAINT PK_SECTION PRIMARY KEY(ID)
); );
...@@ -105,15 +104,17 @@ CREATE TABLE RATING ( ...@@ -105,15 +104,17 @@ CREATE TABLE RATING (
SECTION_ID INT8, SECTION_ID INT8,
DEVICE_ID VARCHAR, DEVICE_ID VARCHAR,
KEY VARCHAR,
CREATED TIMESTAMP,
RATING INT, RATING INT,
CONSTRAINT PK_RATING PRIMARY KEY(ID), CONSTRAINT PK_RATING PRIMARY KEY(ID),
CONSTRAINT FK_RATING_SECTION FOREIGN KEY (SECTION_ID) REFERENCES SECTION(ID) CONSTRAINT FK_RATING_SECTION FOREIGN KEY (SECTION_ID) REFERENCES SECTION(ID)
); );
CREATE INDEX RATING_SECTION_IDX ON RATING(SECTION_ID); CREATE INDEX RATING_SECTION_IDX ON RATING(SECTION_ID);
CREATE INDEX RATING_KEY_IDX ON RATING(KEY);
......
package com.jh.radegast; package com.jh.radegast;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.LocaleResolver;
import com.jh.common.template.ThymeleafTemplateService;
import com.jh.common.web.FallbackLocaleResolver;
@SpringBootApplication @SpringBootApplication
@EnableJpaRepositories @EnableJpaRepositories
...@@ -15,5 +22,22 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -15,5 +22,22 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@ComponentScan(basePackages = {"com.jh"}) @ComponentScan(basePackages = {"com.jh"})
public class RateItApplication { public class RateItApplication {
public static void main(String[] args) {
SpringApplication.run(RateItApplication.class, args);
}
//hack :-(
@Bean
@Primary
public LocaleResolver localeResolver() {
return new FallbackLocaleResolver();
}
@Bean
public ThymeleafTemplateService templateService() {
return new ThymeleafTemplateService();
}
} }
/*
* Created on 25. 7. 2017 17:35:12
*
*/
package com.jh.radegast;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
/**
* The Class RepositoryConfig.
*/
@Configuration
@ConfigurationProperties(prefix = "spring.datasource")
@EntityScan(basePackages = {"com.jh"})
public class RepositoryConfig extends HikariConfig {
@Bean
@Primary
public DataSource dataSource() {
return new HikariDataSource(this);
}
}
package com.jh.radegast;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import com.jh.common.security.UserAuthenticationProvider;
import com.jh.common.security.ReactApplicationSecurityContext;
/**
* The Class SecurityConfig.
*/
@Configuration
public class SecurityConfig extends ReactApplicationSecurityContext {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/auth/signup").permitAll()
.antMatchers("/api/auth/**").permitAll()
.antMatchers("/api/ratings").permitAll()
.antMatchers("/api/**").authenticated()
.anyRequest().permitAll()
.and()
.addFilterBefore(authFilter(), UsernamePasswordAuthenticationFilter.class)
.logout()
.clearAuthentication(true)
.permitAll();
http.csrf().disable();
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint());
http.headers().frameOptions().sameOrigin();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
}
/**
* @param auth
* @throws Exception
* @see com.jh.common.security.ReactApplicationSecurityContext#configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
super.configure(auth);
auth.authenticationProvider(userAuthenticationProvider());
}
/**
* User authentication provider.
*
* @return the user authentication provider
*/
@Bean
public UserAuthenticationProvider userAuthenticationProvider() {
return new UserAuthenticationProvider();
}
}
package com.jh.radegast.api; package com.jh.radegast.api;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import com.jh.radegast.model.Rating;
import com.jh.radegast.rating.RatingService;
@Controller @Controller
@RequestMapping("/api") @RequestMapping("/api")
public class RatingApiController { public class RatingApiController {
@Autowired
private RatingService service;
@RequestMapping(path = "ratings", method = RequestMethod.POST) @RequestMapping(path = "ratings", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
public void bulkRating() { public void bulkRating(@RequestBody Collection<Rating> ratings) {
service.saveBulk(ratings);
} }
} }
...@@ -22,6 +22,9 @@ public class Rating extends AbstractIdEntity { ...@@ -22,6 +22,9 @@ public class Rating extends AbstractIdEntity {
@Column(name = "RATING") @Column(name = "RATING")
private Integer rating; private Integer rating;
@Column(name = "KEY")
private String key;
@Transient @Transient
private Section section; private Section section;
...@@ -60,4 +63,12 @@ public class Rating extends AbstractIdEntity { ...@@ -60,4 +63,12 @@ public class Rating extends AbstractIdEntity {
this.section = section; this.section = section;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
} }
package com.jh.radegast.rating; package com.jh.radegast.rating;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.hibernate.Session; import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.jh.common.jpa.AbstractHibernateRepository; import com.jh.common.jpa.AbstractHibernateRepository;
...@@ -12,10 +15,23 @@ import com.jh.radegast.model.Rating; ...@@ -12,10 +15,23 @@ import com.jh.radegast.model.Rating;
@Repository @Repository
public class RatingRepository extends AbstractHibernateRepository { public class RatingRepository extends AbstractHibernateRepository {
public void saveBulk(Collection<Rating> ratings) { public void saveBulk(Collection<Rating> ratings) {
Session session = getSession(); if (ratings == null || ratings.isEmpty()) {
//TODO implement properly return;
}
for (Rating r : ratings) {
save(r);
}
}
public List<Rating> fetchByKeys(Set<String> keySet) {
if (keySet == null || keySet.isEmpty()) {
return Collections.emptyList();
}
return criteria(Rating.class).add(Restrictions.in("key", keySet)).list();
} }
......
package com.jh.radegast.rating; package com.jh.radegast.rating;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -11,13 +17,41 @@ import com.jh.radegast.model.Rating; ...@@ -11,13 +17,41 @@ import com.jh.radegast.model.Rating;
@Service @Service
public class RatingService { public class RatingService {
private static final Logger LOG = LoggerFactory.getLogger(RatingService.class);
@Autowired @Autowired
private RatingRepository repo; private RatingRepository repo;
@Transactional @Transactional
public void saveBulk(Collection<Rating> ratings) { public void saveBulk(Collection<Rating> ratings) {
repo.saveBulk(ratings); if (ratings == null || ratings.isEmpty()) {
return;
}
Map<String, Rating> ratingsToSave = new HashMap<>();
for (Rating r : ratings) {
ratingsToSave.put(r.getKey(), r);
}
List<Rating> existing = repo.fetchByKeys(ratingsToSave.keySet());
if (existing != null && !existing.isEmpty()) {
StringJoiner sj = new StringJoiner(", ");
int duplicated = 0;
for (Rating r : existing) {
ratingsToSave.remove(r.getKey());
sj.add(r.getKey());
duplicated++;
}
LOG.info("Ignoring {} duplicated records: {}", duplicated, sj);
}
Collection<Rating> values = ratingsToSave.values();
LOG.info("Storing {} ratings", values.size());
repo.saveBulk(values);
} }
} }
/*
* Created on 31. 7. 2017 16:49:36
*
*/
package com.jh.radegast.security;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jh.common.security.AuthService;
import com.jh.common.security.ResetPassword;
import com.jh.common.security.Signup;
import com.jh.common.security.controller.AuthError;
import com.jh.common.utils.Utils;
/**
* The Class AppUserAuthService.
*
* @author Jan Hrabal
*/
@Service
public class AppUserAuthService implements AuthService {
/** The sleep. */
@Value("${auth.login.sleep:250}")
private Integer sleep;
/**
* @param username
* @param password
* @return
* @throws BadCredentialsException
* @see com.jh.common.security.AuthService#authenticate(java.lang.String, java.lang.String)
*/
@Override
public Authentication authenticate(String username, String password) throws BadCredentialsException {
Utils.sleep(sleep);
throw new BadCredentialsException("Bad username or password");
}
@Override
public void generateResetToken(String login) {
}
@Override
@Transactional
public List<AuthError> resetPassword(ResetPassword signup) {
Objects.requireNonNull(signup);
List<AuthError> errors = new ArrayList<>();
return errors;
}
@Override
public List<AuthError> register(Signup signup) {
return Collections.emptyList();
}
}
# local data store
attachment.store.path=C:/data/radegast
# local fonts dir
pdf.fonts.dir=C:/data/fonts
# disable caching for development
global.caching=false
# log sql in DEV
spring.jpa.show-sql=true
logging.level.org.hibernate.SQL=debug
#logging.level.org.hibernate.type=trace
# email config
#spring.mail.host=127.0.0.1
#spring.mail.port=25
#localEmail.scheduled.cron=* 0/15 * * * *
localEmail.scheduled.interval.ms=120000
\ No newline at end of file
# application manifest
application.name=@project.artifactId@
build.version=@project.version@
build.timestamp=@timestamp@
app.locales=en,cs,de
# logging
logging.level.org.hibernate=WARN
logging.level.org.hibernate.SQL=WARN
# server port config
server.port=7070
# datasource
spring.datasource.jdbcUrl=jdbc:postgresql://postgresdb:5432/radegast
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.open-in-view=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.id.new_generator_mappings=true
spring.jpa.properties.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
localEmail.scheduled.interval.ms=10000
security.basic.enabled=false
# email config
#spring.mail.host=mailserver
spring.mail.host=host.docker.internal
#spring.mail.host=docker.for.win.localhost
spring.mail.port=25
#spring.mail.username=username
#spring.mail.password=password
spring.mail.properties.mail.smtp.starttls.enable=false
spring.mail.properties.mail.smtp.starttls.required=false
spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
email.sender.from=info@inodio.com
# attachments (docker-wise)
attachment.store.path=/var/data
spring.http.multipart.max-file-size=10MB
spring.http.multipart.max-request-size=10MB
# pdf fonts (docker-wise)
pdf.fonts.dir=/var/fonts
# auth
auth.html.style.href=/p.css
# notifications
notifications.services=google
# OAuth2 services
oauth2.google.clientId=1081116390533-777ar4t5iqhn4712tfubgprnus3ej791.apps.googleusercontent.com
oauth2.google.clientSecret=SOs-KGO-sNvz7wN0jmVIEmeq
Manifest-Version: 1.0 Manifest-Version: 1.0
Built-By: Jan
Build-Jdk: 10.0.2
Implementation-Title: RateIT Implementation-Title: RateIT
Implementation-Version: 0.0.1 Implementation-Version: 0.0.1
Built-By: jh
Implementation-Vendor-Id: com.jh Implementation-Vendor-Id: com.jh
Build-Jdk: 1.8.0_144
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/boot-react/redegast ot-starter-parent/boot-react/radegast
Created-By: Maven Integration for Eclipse Created-By: Maven Integration for Eclipse
#Generated by Maven Integration for Eclipse
#Mon Jul 08 09:32:30 CEST 2019
version=0.0.1
groupId=com.jh
m2e.projectName=radegast
m2e.projectLocation=C\:\\Users\\jh\\git\\radegast\\backend
artifactId=redegast
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>redegast</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>RateIT</name>
<parent>
<groupId>com.jh</groupId>
<artifactId>boot-react</artifactId>
<version>0.0.4</version>
<relativePath>../boot-react</relativePath>
</parent>
<properties>
<!-- dependency versions -->
<frontend-maven-plugin-version>1.0</frontend-maven-plugin-version>
<node-version>v8.1.3</node-version>
<npm-version>5.0.3</npm-version>
<boot-common.version>0.0.4</boot-common.version>
</properties>
<dependencies>
<dependency>
<groupId>com.jh</groupId>
<artifactId>boot-react-common</artifactId>
<version>${boot-common.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- barcodes -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.1</version>
</dependency>
<!-- jaxb -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Build an executable JAR -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<version>${project.version}</version>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- docker build -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.14</version>
<configuration>
<authConfig>
<username>jhdockerhub</username>
<password>Nedele+30</password>
</authConfig>
<retries>0</retries>
<rm>false</rm>
<imageName>jhdockerhub/${project.artifactId}</imageName>
<imageTags>${project.version}</imageTags>
<baseImage>openjdk:8-jre-alpine</baseImage>
<volumes>
<volume>/tmp</volume>
</volumes>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<env>
<HOSTNAME_BASE>https://www.inodio.com</HOSTNAME_BASE>
<MAILSERVER_IP>185.8.237.132</MAILSERVER_IP>
<PROFILE>prod</PROFILE>
</env>
<exposes>
<expose>7070</expose>
</exposes>
<entryPoint>["sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -Dfile.encoding=UTF-8 -Dspring.profiles.active=default -Dliquibase.scan.packages=liquibase.change,liquibase.changelog,liquibase.database,liquibase.parser,liquibase.precondition,liquibase.datatype,liquibase.serializer,liquibase.sqlgenerator,liquibase.executor,liquibase.snapshot,liquibase.logging,liquibase.diff,liquibase.structure,liquibase.structurecompare,liquibase.lockservice,liquibase.sdk.database,liquibase.ext -Dhostname.base=$HOSTNAME_BASE -Dspring.mail.host=$MAILSERVER_IP -Dspring.profiles.active=$PROFILE -jar /${project.build.finalName}.jar"]</entryPoint>
</configuration>
</plugin>
<!-- clean after docker images -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>prune-images</id>
<phase>package</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>system</argument>
<argument>prune</argument>
<argument>-f</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
...@@ -43,9 +43,14 @@ class App extends React.PureComponent { ...@@ -43,9 +43,14 @@ class App extends React.PureComponent {
body.push(buffer.shift()); body.push(buffer.shift());
} }
if (!body.length) {
// do nothing
return;
}
try { try {
let response = await fetch('https://radegast.janhrabal.com/api/ratings/bulk', { let response = await fetch('https://radegast.janhrabal.com/api/ratings', {
method: "POST", method: "POST",
body: JSON.stringify(body) body: JSON.stringify(body)
}); });
......
@echo off
set ldt=
set datetime=
set PG_DUMP=C:\Software\PostgreSQL\9.6\bin\pg_dump.exe
set GZIP=C:\Software\7-Zip\7z.exe
set TMP_DIR=C:\temp\backups
set APP_NAME=suite
set DB_NAME=suite
set DATA_SRC_DIR=C:\data\%APP_NAME%
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set DATETIME=%ldt:~0,4%%ldt:~4,2%%ldt:~6,2%%ldt:~8,2%%ldt:~10,2%
set ARCHIVE=%APP_NAME%_%DATETIME%
echo %DATETIME%
mkdir %TMP_DIR%
mkdir %TMP_DIR%\%ARCHIVE%
mkdir %TMP_DIR%\%ARCHIVE%\db
mkdir %TMP_DIR%\%ARCHIVE%\data
REM create DB dump
%PG_DUMP% --host 127.0.0.1 --port 5432 --username "postgres" --no-password --format plain --no-owner --create --clean --inserts --no-privileges --no-tablespaces --no-unlogged-table-data --file "%TMP_DIR%\%ARCHIVE%\db\db.sql" "%DB_NAME%"
REM copy stored data
xcopy %DATA_SRC_DIR% %TMP_DIR%\%ARCHIVE%\data /s /e /y
REM zip it all
%GZIP% -ttar a dummy %TMP_DIR%\%ARCHIVE%\* -so | %GZIP% -si -tgzip a %TMP_DIR%\%ARCHIVE%.tgz
rd /s/q "%TMP_DIR%\%ARCHIVE%"
echo Backup created - file %TMP_DIR%\%ARCHIVE%.tgz
\ No newline at end of file
#!/bin/sh
PG_DUMP=pg_dump
TMP_DIR=/tmp/backups
APP_NAME=suite
DB_NAME=${APP_NAME}
DATA_SRC_DIR="/app/data/${APP_NAME}"
DATETIME=`date '+%Y%m%d%H%M'`
ARCHIVE="${APP_NAME}_${DATETIME}"
ARCHIVE_DIR="${TMP_DIR}/${ARCHIVE}"
ARCHIVE_DATA_DIR="${ARCHIVE_DIR}/data"
ARCHIVE_DB_DIR="${ARCHIVE_DIR}/db"
mkdir "${TMP_DIR}"
mkdir "${ARCHIVE_DIR}"
mkdir "${ARCHIVE_DATA_DIR}"
mkdir "${ARCHIVE_DB_DIR}"
chmod -R 777 "${ARCHIVE_DIR}"
OLD_PWD=`pwd`
cd $ARCHIVE_DIR;
$PG_DUMP --host 127.0.0.1 --port 5432 --username "postgres" --no-password --format plain --no-owner --create --clean --inserts --no-privileges --no-tablespaces --no-unlogged-table-data --file "./db.sql" "${DB_NAME}"
mv "./db.sql" "db/db.sql"
cp -R "${DATA_SRC_DIR}/." data
tar -cvf - data db | gzip > "../${ARCHIVE}.tgz"
rm -rf "${ARCHIVE_DIR}"
cd $OLD_PWD
echo "Backup created - file ${ARCHIVE_DIR}.tgz"
#!/bin/sh
docker stop suite
docker rm suite
docker pull jhdockerhub/suite:latest
docker run -p127.0.0.1:3007:7070 -d --restart=unless-stopped --link postgresdb:postgresdb -v /app/data/suite:/var/data -v /app/fonts:/var/fonts --log-opt max-size=5m -e HOSTNAME_BASE=https://www.inodio.com -e MAILSERVER_IP=185.8.237.132 -e PROFILE=prod --name suite jhdockerhub/suite:latest
\ No newline at end of file
@echo off
setlocal enableextensions disabledelayedexpansion
set TMP_DIR=C:\temp\backups
set APP_NAME=suite
set ARCHIVE=%APP_NAME%_%1.tgz
IF NOT [%1]==[] GOTO :specified
set "ARCHIVE_="
for /f "delims=" %%a in ('dir /b /o-d "%TMP_DIR%\%APP_NAME%_*.tgz" 2^>nul') do (
if not defined ARCHIVE_ set "ARCHIVE=%%a"
if not defined ARCHIVE_ set "ARCHIVE_=%%a"
)
:specified
set PSQL=C:\Software\PostgreSQL\9.6\bin\psql.exe
set GZIP=C:\Software\7-Zip\7z.exe
echo Using file %ARCHIVE%
set DATA_SRC_DIR=C:\data\%APP_NAME%
docker stop %APP_NAME%
%GZIP% x -so %TMP_DIR%\%ARCHIVE% | %GZIP% x -si -o%TMP_DIR%\%ARCHIVE%_tmp -ttar
xcopy %TMP_DIR%\%ARCHIVE%_tmp\data %DATA_SRC_DIR% /s /e /y
%PSQL% -U postgres -d template1 < %TMP_DIR%\%ARCHIVE%_tmp\db\db.sql
rd /s/q "%TMP_DIR%\%ARCHIVE%_tmp"
docker start %APP_NAME%
echo Backup %ARCHIVE% restored
rem C:\Software\PostgreSQL\9.6\bin\psql.exe -U postgres -d template1 < C:\temp\db.sql
\ No newline at end of file
#!/bin/sh
PSQL=psql
TMP_DIR=/tmp/backups
APP_NAME=suite
DB_NAME=${APP_NAME}
DATA_SRC_DIR="/app/data/${APP_NAME}"
if [ -z "$1" ]
then
ARCHIVE_PATH="$(ls ${TMP_DIR}/${APP_NAME}* | sort -V | tail -n 1)"
ARCHIVE="$(basename ${ARCHIVE_PATH})"
else
DATETIME=$1
ARCHIVE="${APP_NAME}_${DATETIME}.tgz"
fi
echo Using archive ${ARCHIVE}
ARCHIVE_DIR="${TMP_DIR}/${ARCHIVE}_tmp"
ARCHIVE_DATA_DIR="${ARCHIVE_DIR}/data"
ARCHIVE_DB_DIR="${ARCHIVE_DIR}/db"
OLD_PWD=`pwd`
mkdir $ARCHIVE_DIR
cd $TMP_DIR
echo `pwd`
# unzip
tar xf "${ARCHIVE}" -C $ARCHIVE_DIR
cd $ARCHIVE_DIR
# stop application
echo Shutting down application ${APP_NAME}
docker stop ${APP_NAME}
# copy data
/bin/cp -rf "./data/." $DATA_SRC_DIR
# restore DB
$PSQL -U postgres --host 127.0.0.1 -d template1 < "./db/db.sql"
# start app
echo Starting application ${APP_NAME}
docker start ${APP_NAME} &
cd $OLD_PWD
# remove unzipped data
rm -rf $ARCHIVE_DIR
@echo off
set PSQL=C:\Software\PostgreSQL\9.6\bin\psql.exe
set GZIP=C:\Software\7-Zip\7z.exe
set TMP_DIR=C:\temp\db.sql
set APP_NAME=suite
set ARCHIVE=%APP_NAME%_%1
set DATA_SRC_DIR=C:\data\%APP_NAME%
rem %GZIP% x -so %TMP_DIR%\%ARCHIVE%.tgz | %GZIP% x -si -o%TMP_DIR%\%ARCHIVE% -ttar
rem xcopy %TMP_DIR%\%ARCHIVE%\data %DATA_SRC_DIR% /s /e /y
%PSQL% -U postgres -d template1 < %TMP_DIR%
rem rd /s/q "%TMP_DIR%\%ARCHIVE%"
rem echo Backup %ARCHIVE% restored
rem C:\Software\PostgreSQL\9.6\bin\psql.exe -U postgres -d template1 < C:\temp\db.sql
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment