压缩指定SQL文件并删除N天前的压缩备份文件BAT

  1. 云栖社区>
  2. 博客>
  3. 正文

压缩指定SQL文件并删除N天前的压缩备份文件BAT

天飞 2016-05-11 15:01:17 浏览1469
展开阅读全文

公司PHP部门提的小要求。

有时间就搜索了一下网络,作了一个简易实现。

前提是要安装WINRAR罗~~:)

脚本:

复制代码
 1 #get right date format file
 2 
 3 set filename1=p_%date:~10,4%-%date:~4,2%-%date:~7,2%.sql
 4 #echo %filename1%
 5 set filename2=p_slave_%date:~10,4%-%date:~4,2%-%date:~7,2%.sql
 6 #echo %filename2%
 7 
 8 #winrar today's sql file
 9 
10 "C:\Program Files\WinRAR\rar.exe" a -df -m4 %filename1%.rar %filename1%
11 "C:\Program Files\WinRAR\rar.exe" a -df -m4 %filename2%.rar %filename2%
12 
13 #delete rar file older than 14 days
14 
15 forfiles -p "C:\xampp\htdocs\p\data" -s -m *.rar /D -14 /C "cmd /c del @path"
复制代码

 

截图:

参考贴:

http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days

Enjoy:

forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"

See forfile documentation for more details.

For more goodies refer to An A-Z Index of the Windows XP command line

If you don't have forfiles installed on your machine, get it from Microsoft FTP server. Place it to C:\WINDOWS\system32\forfiles.exe Recent versions of Windows and Windows Server have it installed by default.

Update Win7: Syntax has changed a little therefore the updated command is:

forfiles -p "C:\what\ever" -s -m *.* /D -<number of days> /C "cmd /c del @path"

网友评论

登录后评论
0/500
评论
天飞
+ 关注