delete_old_backup.bat-阿里云开发者社区

开发者社区> 数据库> 正文
登录阅读全文

delete_old_backup.bat

简介:

  在前面forfiles命令批量删除N天前文件 这篇文章里面讲述了如何在SQL Server 2000中使用forfile删除N天前备份文件,但是现在又有新需求:

  需求描述:通过数据库维护计划将备份生成在本地磁盘M(M盘位于单独的SAN存储,该SAN存储专门用于保留备份),完整备份保留2 天,事务日志备份保留2天,但是M:\DB_BACKUP\FULL_BACKUP目录下只能保留最新的一份完整备份,旧的备份必须移动到M: \DB_BACKUP\OLD_BACKUP,这样我就可以通过Symantec Backup Exec只将FULL_BAKCUP和LOG_BACKUP目录收上磁带。否则通过Symantec Backup Exec将备份收上磁带时,将出现冗余。一来需要消耗更多的磁带,最麻烦的是因为SAN存储和磁带机位于不同地域的机房,虽然通过1G的光纤连接,但是由 于我们磁带机只有两个Drive,只能并行跑两个作业,所以必须减少冗余,防止作业被滞留到白天,影响网络带宽,所以必须修改手头几台SQL Server 2000的备份策略,修改delete_old_backup.bat命令

            M:\DB_BACKUP\FULL_BACKUP

            M:\DB_BACKUP\LOG_BACKUP

            M:\DB_BACKUP\LOG_BACKUP

image

 

 

delete_old_backup.bat 脚本如下所示:

echo  --**************************************************************-- >>delete_old_backup.log
 
echo  --Delete the backup log start at %Date% - %time% -->>delete_old_backup.log
 
rem Keep the backup log days definition.
 
set LogKeepDays=2
 
rem delete the old backup log files LogKeepDays ago.
 
set LogPath=M:\DB_BACKUP\
 
forfiles -p%LogPath% -m*.txt -d-%LogKeepDays% -c"cmd /c del /q @FILE" >> delete_old_backup.log
 
echo Delete the backup log End at %Date% - %time% >>delete_old_backup.log
 
 
 
echo --Delete the folder old_bakcup full backup start at %Date% - %time% -- >>delete_old_backup.log
 
set OldBackupPath=M:\DB_BACKUP\OLD_BACKUP
 
set OldBkKeepDays=1
 
forfiles -p%OldBackupPath% -m*.bak -d-%OldBkKeepDays% -c"cmd /c del /q @FILE" >> delete_old_backup.log
 
echo --Delete the folder old_bakcup full backup end at %Date% - %time% -->>delete_old_backup.log
 
 
 
echo Move the full backup start at %Date% - %time% >>delete_old_backup.log
 
set FullBkKeepDays=1
 
set FullBackupPath=M:\DB_BACKUP\FULL_BACKUP
 
forfiles -p%FullBackupPath% -m*.bak -d-%FullBkKeepDays% -c"cmd /c move @FILE M:\DB_BACKUP\OLD_BACKUP" >> delete_old_backup.log
 
echo Move the full backup End at %Date% - %time% >>delete_old_backup.log
 
 
echo Delete the log backup start at %Date% - %time% >>delete_old_backup.log
 
set LogBackupPath=M:\DB_BACKUP\LOG_BACKUP
 
set LogBkKeepDays=2
 
forfiles -p%LogBackupPath% -m*.TRN -d-%LogBkKeepDays% -c"cmd /c del /q @FILE" >> delete_old_backup.log
 
 
echo Delete the log backup Stop at %Date% - %time% >>delete_old_backup.log
 
echo  --****************************************-- >>delete_old_backup.log

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

其他文章