SqlServer自動備份、自動壓縮、自動刪除舊備份,sqlserver備份壓縮

來源:互聯網
上載者:User

SqlServer自動備份、自動壓縮、自動刪除舊備份,sqlserver備份壓縮

準備工具:
SqlServer2008
WinRar

1.給SqlServer設定維護計劃定時備份
這個操作比較簡單,按嚮導新增維護計劃即可。

2.自動壓縮指令碼

c:\Progra~2\WinRar\winRar.exe a D:\bak\database_buckup_%date:~0,4%_%date:~5,2%_%date:~8,2% d:\bak\database_*%date:~0,4%_%date:~5,2%_%date:~8,2%_*.bak 

備份檔案的格式是:database_backup_2015_05_15_010001_5555338.bak,
壓縮檔格式是:data_2015_06_15.rar這種樣式。

3.自動刪除舊的備份
設定一個計劃任務,在壓縮前把老的備份刪除。這裡通過bat指令碼調用vbs指令碼,因為vbs指令碼相對好寫一點。

autoDeleteOld.bat

cscript d:/bak/autoDeleteOldBak.vbs

autoDeleteOldBak.vbs

const reMainCount = 1           '保留幾dayDim fso,dc,file,files,folder,subfolders,subfolderset fso=createobject("Scripting.FileSystemObject")set folder=fso.getfolder("D:\bak")Dim todaytoday=Nowfor each tempFile in folder.files    dim arr    arr=Split( tempFile,"_backup_")    if UBound(arr)>0 then        dim tempDate,diff        tempDate=Cdate( Replace( Left(arr(1),10),"_","-"))        diff= DateDiff("d",tempDate,today)        if (diff>reMainCount) then            fso.deleteFile(tempFile),true        end if    end ifnextset fso=nothing

如果另外有ftp伺服器,可以壓縮檔後,遠程同步到另一台伺服器上。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.