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
相关文章
|
7月前
oralce check 命令
oralce check 命令
49 1
|
存储
rman备份失败:ORA-00245: control file backup failed; target is likely on a local file system
rman备份失败:ORA-00245: control file backup failed; target is likely on a local file system
161 0
|
Oracle 关系型数据库 Shell
[20171121]rman backup as copy 2.txt
[20171121]rman backup as copy 2.txt --//昨天测试backup as copy ,备份时备份文件的文件头什么时候更新.是最后完成后还是顺序写入备份文件.
1013 0
|
Oracle 关系型数据库 Linux
[20171121]rman backup as copy.txt
[20171121]rman backup as copy.txt --//上个星期做数据文件块头恢复时,提到使用rman备份数据文件时,文件头数据库信息是最后写入备份集文件的,在filesperset=1的情况 --//下写入备份集文件中的倒数第2块就是文件头的备份.
1227 0