SQL Server automatic backup, automatic compression, automatic deletion of old backups

Source: Internet
Author: User
Tags diff

Preparation tools:
SqlServer2008
WinRar

1. Set up maintenance schedule scheduled backups for SQL Server
This is a simple operation, and you can follow the wizard to add a maintenance plan.

2. Automatic compression scripts

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

The format of the backup file is: Database_backup_2015_05_15_010001_5555338.bak,
The compressed file format is: Data_2015_06_15.rar this style.

3. Automatic deletion of old backups
Set up a scheduled task to remove the old backup before compressing it. The VBS script is invoked here through the bat script because the VBS script is relatively well-written.

Autodeleteold.bat

cscript d:/bak/autoDeleteOldBak.vbs

Autodeleteoldbak.vbs

ConstRemaincount =1           ' Keep a few dayDimFso,dc,file,files,folder,subfolders,subfolderSetfso=CreateObject("Scripting.FileSystemObject")SetFolder=fso.getfolder ("D:\bak")Dimtodaytoday= Now for  eachTempfileinchFolder.filesDimArr arr=Split(Tempfile,"_backup_")if UBound(arr) >0  Then        DimTempdate,diff tempdate=Cdate(Replace( Left(Arr (1),Ten),"_","-")) diff=DateDiff("D", Tempdate,today)if(Diff>remaincount) ThenFso.deletefile (Tempfile),true        End if    End ifNextSetfso= Nothing

If you have another FTP server, you can compress the files and synchronize them remotely to another server.

SQL Server automatic backup, automatic compression, automatic deletion of old backups

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.