使用小巧强大的7z(不到1M),实现差异文件备份.
::This script backup the data from srvdatacn01
::It's an ancremental backups tools, One base file and diff files for each day.
::The files be deleted at srvdatacn01 are still keep saved at archived diff files, until them be deleted.
::Make sure you DateTime format is "yyyy-mm-dd", which could be use as one filenme(exclude / \ * :)
::Add C:\Program Files\7-Zip\ to environment variables path
:: Delete the diff archive files which over 7 days
:: Command forfiles doesn't support UNC path, so need map the path to driver first
if not exist \\srvdatacn02\d (
NET USE Y: \\srvdatacn02\d
)
forfiles /P Y: /M backup_srvdatacn01*diff*.zip /C "cmd /c del /q/f @path" /D -7
NET USE Y: /D
call :backup "folder1","folder2","folder3","folder4","folder5"
:backup
for %%i in (%*) do (
if not exist "d:\backup_srvdatacn01_%%~i_base.7z" (
7z a "d:\backup_srvdatacn01_%%~i_base.7z" "\\srvdatacn01\%%~i\*" -xr!Thumbs.db -mx9
) else (
7z u "d:\backup_srvdatacn01_%%~i_base.7z" "\\srvdatacn01\%%~i\*" -u- -up0q1r2x2y2z0w0!"d:\backup_srvdatacn01_%%~i_diff_%date:/=_%_%time::=_%.7z" -xr!Thumbs.db -mx9
7z u "d:\backup_srvdatacn01_%%~i_base.7z" "\\srvdatacn01\%%~i\*" -up0q0r2x2y2z1w1 -xr!Thumbs.db -mx9
)
)
goto:eof
** forfiles 需要使用盘符映射**
删除N天以前的文件
forfiles /P Y: /M backup_srvdatacn01*diff*.zip /C "cmd /c del /q/f @path" /D -7
将差异文件写入diff包
7z u "d:\backup_srvdatacn01_%%~i_base.7z" "\\srvdatacn01\%%~i\*" -u- -up0q1r2x2y2z0w0!"d:\backup_srvdatacn01_%%~i_diff_%date:/=_%_%time::=_%.7z" -xr!Thumbs.db -mx9
更新基础包
7z u "d:\backup_srvdatacn01_%%~i_base.7z" "\\srvdatacn01\%%~i\*" -up0q0r2x2y2z1w1 -xr!Thumbs.db -mx9
来源:oschina
链接:https://my.oschina.net/u/565627/blog/3078930