fix: mysql备份代码

This commit is contained in:
republicline 2024-10-15 10:02:14 +08:00
parent 5243f35dd6
commit 73d3af71aa
4 changed files with 18 additions and 8 deletions

View File

@ -4,7 +4,6 @@ import com.rax.common.security.annotation.EnableRaxResourceServer;
import com.rax.common.swagger.annotation.EnableRaxDoc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

View File

@ -66,7 +66,7 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
.le(SysLog::getCreateTime, lastDayOfMonth)
.eq(sysLog.getLogType() != null, SysLog::getLogType, sysLog.getLogType())
.orderByDesc(SysLog::getCreateTime).list();
}else {
} else {
list = this.lambdaQuery()
.eq(SysLog::getHospitalId, currentHospital)
.eq(sysLog.getLogType() != null, SysLog::getLogType, sysLog.getLogType())
@ -120,7 +120,11 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
userLambdaQueryWrapper.eq(SysUser::getUsername, sysLog.getCreateBy());
SysUser sysUser = sysUserMapper.selectOne(userLambdaQueryWrapper);
// 设置到日志对象中
sysLog.setHospitalId(sysUser.getHospitalId());
if (sysUser != null) {
sysLog.setHospitalId(sysUser.getHospitalId());
}else {
return Boolean.FALSE;
}
}
baseMapper.insert(sysLog);
return Boolean.TRUE;

View File

@ -1,5 +1,9 @@
package com.rax.admin.timmer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.File;
import java.sql.*;
import java.text.SimpleDateFormat;
@ -12,14 +16,17 @@ import java.util.concurrent.TimeUnit;
* @author: republicline
* @description: mysql定时备份
*/
@Slf4j
@Component
public class MySqlTimer {
public static void main(String[] args) throws Exception {
backup();
MySqlTimer mySqlTimer = new MySqlTimer();
mySqlTimer.backup();
}
public static void backup() throws Exception {
@Scheduled(cron = "0 0 15 * * 1")
public void backup() throws Exception {
String connectionUrl = "jdbc:mysql://110.41.142.124:3306";
String ip = "110.41.142.124";
String port = "3306";
@ -62,7 +69,7 @@ public class MySqlTimer {
* @param dbName 数据库名
* @throws Exception
*/
public static void dbBackUpMysql(String ip, String port, String username, String pwd, String path, String dbName) throws Exception {
public void dbBackUpMysql(String ip, String port, String username, String pwd, String path, String dbName) throws Exception {
//mysqldump -uroot -pldeSpQEL0Pbz5A61dCNb --host=123.56.234.243 --port=3309 edc > /opt/2024-10-08/edc.sql
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String time = simpleDateFormat.format(new Date());

View File

@ -165,7 +165,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
url: jdbc:mysql://localhost:3306/rax_backend1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true # 一期
url: jdbc:mysql://110.41.142.124:3306/rax_backend1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true # 一期
# url: jdbc:mysql://localhost:3306/rax_backend?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true # 二期
server: