Administrator
2021-01-19 fbed4c7738db69c0d6a30c10f6944268ba28ea9e
BattMonitor_FBS9100S_DataBaseBackUp/src/com/backup/DataBaseBackUpThread.java
@@ -10,6 +10,7 @@
import java.util.regex.Pattern;
import com.base.Com;
import com.config.AppConfig;
import com.sql.MysqlConnPool;
import main.main_FBS9100S_DataBaseBackUp;
@@ -24,9 +25,12 @@
   private MysqlConnPool pool;
   private String savePath = System.getProperty("user.dir")+ File.separator+"mysql_backup";         //备份数据库的根目录
   private MyRunTime runtime = null;
   private AppConfig appcfg;
   
   public DataBaseBackUpThread(MysqlConnPool conn_pool){
   public DataBaseBackUpThread(MysqlConnPool conn_pool,AppConfig appcfg){
      this.pool = conn_pool;
      this.appcfg = appcfg;
      this.runtime = new MyRunTime(this.pool);
      
      DataBaseBackUpThread_SQL.createBackupTable(pool);                                              //初始化数据库表
@@ -55,7 +59,7 @@
            //System.out.println();
            
            //12点59分开始备份所有的数据库
            if(countTimeLong(nowTime, normTime)<30 && countTimeLong(lastRecodTime, nowTime) >= 7*24*60*60) {
            if(countTimeLong(nowTime, normTime)<30 || countTimeLong(lastRecodTime, nowTime) >= 7*24*60*60) {
               System.out.println("开始备份所有的数据库"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
               this.list = DataBaseBackUpThread_SQL.searchAllDataBaseAndTable(pool);
               String path = savePath+File.separator+REGULAR_BACKUP_PATHNAME;
@@ -73,9 +77,17 @@
               lastRecodTime = nowTime;
               DataBaseBackUpThread_SQL.inseartBackupTable(pool,list);
               
               HzipSocket SocketClient = new HzipSocket();
               SocketClient.init(path);                     //发送数据库备份文件到远程服务器
               ZipUtil zipUtil = new ZipUtil();
               String zipName = path+".zip";
               File zipFile = zipUtil.createZip(zipName, new File(path));   //压缩数据库文件
               HzipSocket SocketClient = new HzipSocket(appcfg);
               SocketClient.init(zipName);                     //发送数据库备份文件到远程服务器
               System.out.println("远程备份数据库完成" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
               if(zipFile.exists() && zipFile.length() > 1*1024 && new File(path).exists()) {
                  deleteDir(new File(path));
               }
            }
            
            //查询所有需要备份指定数据库的记录
@@ -102,8 +114,15 @@
                     table.setBack_en(DatabaseTable.MYSQL_BACKUP_OVER);                              //备份完成
                     DataBaseBackUpThread_SQL.UpdateDataBaseState(pool, table);
                  }
               }
               }
               if( count > 0) {
                  ZipUtil zipUtil = new ZipUtil();
                  String zipName = path+".zip";
                  File zipFile = zipUtil.createZip(zipName, new File(path));   //压缩数据库文件
                  if(zipFile.exists() && zipFile.length() > 1*1024 && new File(path).exists()) {
                     deleteDir(new File(path));
                  }
                  System.out.println("开始备份"+count+"个表    at "+Com.getDateTimeFormat(nowTime, Com.DTF_YMD_h_m_s));
               }
            }