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

Source: Internet
Author: User

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

Preparation tools:
SqlServer2008
WinRar

1. Set a scheduled backup for SqlServer
This operation is relatively simple. Simply add a maintenance plan according to the wizard.

2. Automatic compression of 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 backup file format is database_backup_2015_05_15_0100020.5555338.bak,
The compressed file format is data_2015_06_15.rar.

3. automatically delete the old backup
Set a scheduled task and delete the old backup before compression. The bat script is used to call the vbs script because the vbs script is relatively easy to write.

AutoDeleteOld. bat

cscript d:/bak/autoDeleteOldBak.vbs

AutoDeleteOldBak. vbs

Const reMainCount = 1' reserved several 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 = 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

If there is another ftp server, you can compress the file and remotely synchronize it to another server.

Related Article

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.