perf:增加数据库备份
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>springboot-ademo</module>
|
<module>springboot-ademo</module>
|
||||||
<module>springboot-db-migration</module>
|
<module>springboot-database</module>
|
||||||
<module>springboot-login</module>
|
<module>springboot-login</module>
|
||||||
<module>springboot-web</module>
|
<module>springboot-web</module>
|
||||||
<module>springboot-util</module>
|
<module>springboot-util</module>
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-db-migration</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
<version>0.5.0</version>
|
<version>0.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<version>0.5.0</version>
|
<version>0.5.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-db-migration</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.tiesheng.database;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@ComponentScan({
|
||||||
|
"com.tiesheng.database.**.*"
|
||||||
|
})
|
||||||
|
public class DatabaseAutoConfigurer {
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.tiesheng.database.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.RuntimeUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "tiesheng.db-backup")
|
||||||
|
public class DbBackupConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库备份的路径
|
||||||
|
*/
|
||||||
|
private String path = "/root/backup/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备份文件的时间格式
|
||||||
|
*/
|
||||||
|
private String format = "yyyyMMdd";
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void dbBackup() {
|
||||||
|
String url = SpringUtil.getProperty("spring.datasource.url");
|
||||||
|
String username = SpringUtil.getProperty("spring.datasource.username");
|
||||||
|
String password = SpringUtil.getProperty("spring.datasource.password");
|
||||||
|
|
||||||
|
try {
|
||||||
|
RuntimeUtil.exec(StrUtil.format("mysqldump -u{} -p{} {} > {}{}.sql", username, password, username,
|
||||||
|
getPath(), DateUtil.format(new Date(), format)
|
||||||
|
));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tiesheng.migration.config;
|
package com.tiesheng.database.config;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tiesheng.migration.service;
|
package com.tiesheng.database.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
@@ -9,7 +9,7 @@ import cn.hutool.core.util.IdUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.Db;
|
import cn.hutool.db.Db;
|
||||||
import cn.hutool.db.Entity;
|
import cn.hutool.db.Entity;
|
||||||
import com.tiesheng.migration.config.DbMigrationConfig;
|
import com.tiesheng.database.config.DbMigrationConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.tiesheng.migration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
@ComponentScan({
|
|
||||||
"com.tiesheng.migration.**.*"
|
|
||||||
})
|
|
||||||
public class MigrationAutoConfigurer {
|
|
||||||
}
|
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-db-migration</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.tiesheng.core;
|
package com.tiesheng.core;
|
||||||
|
|
||||||
import com.tiesheng.core.service.TieshengWebConfigurer;
|
import com.tiesheng.core.service.TieshengWebConfigurer;
|
||||||
|
import com.tiesheng.database.DatabaseAutoConfigurer;
|
||||||
import com.tiesheng.login.LoginAutoConfigurer;
|
import com.tiesheng.login.LoginAutoConfigurer;
|
||||||
import com.tiesheng.message.MessageAutoConfigurer;
|
import com.tiesheng.message.MessageAutoConfigurer;
|
||||||
import com.tiesheng.migration.MigrationAutoConfigurer;
|
|
||||||
import com.tiesheng.util.UtilAutoConfigurer;
|
import com.tiesheng.util.UtilAutoConfigurer;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ import java.lang.annotation.*;
|
|||||||
MessageAutoConfigurer.class,
|
MessageAutoConfigurer.class,
|
||||||
CoreAutoConfigurer.class,
|
CoreAutoConfigurer.class,
|
||||||
LoginAutoConfigurer.class,
|
LoginAutoConfigurer.class,
|
||||||
MigrationAutoConfigurer.class
|
DatabaseAutoConfigurer.class
|
||||||
})
|
})
|
||||||
public @interface EnableTieshengWeb {
|
public @interface EnableTieshengWeb {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user