Backup files through Windows Scheduled Tasks and DOS batch processing

Source: Internet
Author: User

Objective:

1. Plan to back up 1 times every half-hour every day, starting 8 o'clock every day, performing 12 hours, 20 o'clock end.

2. Delete the historical backup files regularly, because there are multiple time periods daily backups, only the last backup of the day is retained before deletion.

Description

Since the deleted operation only really works on the first execution of a day, you can split the following commands into two scheduled tasks to execute separately, and of course they can be executed together. Specific to the efficiency of implementation.

Implement:

1. Save the following code as Back.bat, modify the source file path and the backup directory

@echo Offrem backup file set under the specified directory"ymd=%date:~,4%-%date:~5,2%-%date:~8,2%"Set"sfm=%time:~,2%%time:~3,2%"the path after REM backup is C:\backup\2017-09-07\1430. Bak. Echo F| Xcopy"source file path" "C:\backup\%Ymd%\%Sfm%.bak">nul 2>Nulrem Deletes the specified number of days before the specified path, whichever is the date string contained in the file name, for example:2009-12-25) of the file. REM Specifies the storage path of the file to be deleted set Srcdir=C:\backuprem Specifies the number of days set Daysago=5>>"%temp%/dstdate.vbs"Echo lastdate=date ()-%daysago%>>"%temp%/dstdate.vbs"Echo Fmtdate=right (Year (lastdate), 4) ^& right ("0"^& month (lastdate), 2) ^& right ("0"^& Day (lastdate), 2)>>"%temp%/dstdate.vbs"Echo WScript.Echo Fmtdate for/F%%ainch(' Cscript/nologo"%temp%/dstdate.vbs"‘) Do(Set"dstdate=%%a") Set Dstdate=%dstdate:~0,4%-%dstdate:~4,2%-%dstdate:~6,2%setlocal enabledelayedexpansion for/F"delims="%%ainch(' Dir/b/s/ad"%srcdir%"‘) Do(Set"Filedate=%%~na"    if "! filedate!"Leq"%dstdate%" (        ifExist"%%a"(REM Delete before you back up the last file to the History folder move"%%a\2000.bak" "c:\backup\history\! filedate!. Bak"Rd/s/q"%%a")) endlocal:: Exit

2. Set up Windows Scheduled Tasks, refer to http://blog.csdn.net/woshixuye/article/details/18050769

Backup files through Windows Scheduled Tasks and DOS batch processing

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.