perf:数据库备份

This commit is contained in:
曾文豪
2023-05-11 17:16:21 +08:00
parent 3de3ac4cff
commit 33649ed3f9

View File

@@ -40,13 +40,12 @@ public class DbBackupConfig {
String dbName = TieshengDbUtil.getTableSchema(url);
try {
String saveFile = StrUtil.format("{}{}/{}.sql.gz", getPath(), dbName, DateUtil.format(new Date(), format));
String saveFile = StrUtil.format("{}{}/{}.sql", getPath(), dbName, DateUtil.format(new Date(), format));
FileUtil.mkParentDirs(saveFile);
String cmd = StrUtil.format("mysqldump -u {} --password={} --databases {} " +
"--compress --skip-opt --result-file {} ", username, password, dbName, saveFile);
LogFactory.get().info("cmd: " + cmd);
String forStr = RuntimeUtil.execForStr(cmd);
LogFactory.get().info("dbBackup: " + forStr);
RuntimeUtil.execForStr(cmd);
RuntimeUtil.execForStr(StrUtil.format("gzip -9 {}", saveFile));
} catch (Exception e) {
LogFactory.get().info(e);
}