rem auther:yangxiaomin rem date:20190319 rem ******auto copy start******** @echo off
rem 删除临时目录下的所有压缩文件 del /f /s /q "D:\Auto_Copy_Backup_Temp\*.*"
rem 获取当前系统时间,形如:"2019-03-19-16-10-23" set "Ymd=%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%"
rem 删除系统时间中的空格,形如:"2019-03-19-0-00-00" set "today=%Ymd: =%"
rem 压缩命令目录,本例使用7z工具压缩 set "Zip=D:\Program Files\7-Zip\7z.exe"
rem 拷贝到局域网的其他机器ip及共享文件夹 set "destinition=\\ip\TZIWB_DB_Backup\"
rem 如果需要在共享目录下按照子目录的方式存储,则使用以下命令自动创建子目录,例如按照日期创建子目录 rem "destinition=\\ip\TZIWB_DB_Backup\%today%" rem if not exist %destinition% ( rem md %destinition% rem )
rem 找到业务数据库的最新备份 SET "DatabaseBackupPath_Product=D:\SQLSVRDATA\Backup\TZIWB_Product" FOR /F "delims=|" %%I IN ('DIR "%DatabaseBackupPath_Product%\*.bak" /B /O:D') DO SET NewestProductFile=%%I
rem 找到job数据库的最新备份 SET "DatabaseBackupPath_ProductJobs=D:\SQLSVRDATA\Backup\TZIWB_Product_Jobs" FOR /F "delims=|" %%I IN ('DIR "%DatabaseBackupPath_ProductJobs%\*.bak" /B /O:D') DO SET NewestProductJobsFile=%%I
rem 找到普元工作流数据库的最新备份 SET "DatabaseBackupPath_PrimetonBps=D:\MySQLDATA\Backup\primeton_bps_product" FOR /F "delims=|" %%I IN ('DIR "%DatabaseBackupPath_PrimetonBps%\*.sql" /B /O:D') DO SET NewestPrimetonBpsFile=%%I
rem 找到工作流审核数据库的最新备份 SET "DatabaseBackupPath_TzwfBps=D:\MySQLDATA\Backup\tzwf_bps_product" FOR /F "delims=|" %%I IN ('DIR "%DatabaseBackupPath_TzwfBps%\*.sql" /B /O:D') DO SET NewestTzwfFile=%%I
rem 使用7z工具压缩以上四个数据库备份文件 "%Zip%" a "D:\Auto_Copy_Backup_Temp\%today%.zip" "%DatabaseBackupPath_Product%\%NewestProductFile%" "%DatabaseBackupPath_ProductJobs%\%NewestProductJobsFile%" "%DatabaseBackupPath_PrimetonBps%\%NewestPrimetonBpsFile%" "%DatabaseBackupPath_TzwfBps%\%NewestTzwfFile%"
rem 拷贝上一步压缩的文件到目标目录 copy "D:\Auto_Copy_Backup_Temp\%today%.zip" "%destinition%"