perf:测试数据库备份
This commit is contained in:
@@ -17,3 +17,13 @@ deploy-jar:
|
|||||||
- git commit -m "deploy $CI_PROJECT_NAME $CI_COMMIT_TAG"
|
- git commit -m "deploy $CI_PROJECT_NAME $CI_COMMIT_TAG"
|
||||||
- git push origin master
|
- git push origin master
|
||||||
|
|
||||||
|
build-jar:
|
||||||
|
stage: package
|
||||||
|
tags:
|
||||||
|
- hzkepai
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == "master"
|
||||||
|
script:
|
||||||
|
- mvn clean package -Dmaven.test.skip=true
|
||||||
|
- cd springboot-ademo
|
||||||
|
- nohup java -Xms=64m -Xmx=64m -Dspring.profiles.active=test -jar springboot-ademo-1.0.0.jar
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
server:
|
server:
|
||||||
compression:
|
compression:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
port: 8100
|
||||||
|
|
||||||
## Spring配置
|
## Spring配置
|
||||||
spring:
|
spring:
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.tiesheng.database.config;
|
package com.tiesheng.database.config;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.RuntimeUtil;
|
import cn.hutool.core.util.RuntimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.tiesheng.database.utls.TieshengDbUtil;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -33,10 +35,12 @@ public class DbBackupConfig {
|
|||||||
String url = SpringUtil.getProperty("spring.datasource.url");
|
String url = SpringUtil.getProperty("spring.datasource.url");
|
||||||
String username = SpringUtil.getProperty("spring.datasource.username");
|
String username = SpringUtil.getProperty("spring.datasource.username");
|
||||||
String password = SpringUtil.getProperty("spring.datasource.password");
|
String password = SpringUtil.getProperty("spring.datasource.password");
|
||||||
|
String dbName = TieshengDbUtil.getTableSchema(url);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RuntimeUtil.exec(StrUtil.format("mysqldump -u{} -p{} {} > {}{}.sql", username, password, username,
|
String saveFile = StrUtil.format("{}{}/{}.sql", getPath(), dbName, DateUtil.format(new Date(), format));
|
||||||
getPath(), DateUtil.format(new Date(), format)
|
FileUtil.mkParentDirs(saveFile);
|
||||||
|
RuntimeUtil.exec(StrUtil.format("mysqldump -u{} -p{} {} > {}", username, password, dbName, saveFile
|
||||||
));
|
));
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.tiesheng.database.utls;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
public class TieshengDbUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过url获取table_schema
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getTableSchema(String url) {
|
||||||
|
return StrUtil.sub(url, url.lastIndexOf('/') + 1, StrUtil.indexOf(url, '?'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user