Batch files to automate rolling 3-generation weekly full and incremental backups

Discussion in 'Acronis True Image Product Line' started by The Gold Tooth, Aug 5, 2008.

Thread Status:
Not open for further replies.
  1. The Gold Tooth

    The Gold Tooth Registered Member

    Joined:
    Feb 25, 2008
    Posts:
    27
    INTRODUCTION: I present herein the method I use to automate the creation of a rolling, 3-generation set of weekly full and incremental backups, each weekly generation consisting of a full drive image and seven incremental images. I do this through the use of batch files and True Image's Pre/Post Command facility. I know that you're supposed to be able to do this using the Secure Zone, etc., but I prefer to keep things visible and simple.

    HARDWARE & SOFTWARE: Pentium D 3.2GHz, 3.25GB RAM, Windows XP Professional SP3, Acronis True Image Home 11.0, Second Copy 7.1.0.3, PerfectDisk 2008.

    Hard drives: 3 internal (C: 250GB, E: 250GB, L: 750GB), 1 external (M: 500GB)

    The C: drive contains the system and important data. E:, L:, and M: are backup drives.

    BACKUP STRATEGY: I backup the C: drive using two products: True Image (TI) to create drive images, and Second Copy (SC), a popular and flexible file backup utility, to backup individual files and folders. The SC backups run approximately every 6 hours or when invoked by the batch files below. There are three TI jobs scheduled as follows:

    C: Full: Creates a full image, runs on Mondays at 3:00 a.m. Prior to creating the image, the job performs a defrag of the C: drive using PerfectDisk 2008.

    C: Incremental: Creates an incremental image, runs every day except Monday at 1:30 a.m.

    C: Incremental Monday: Creates an incremental image, runs on Mondays at 1:30 a.m.​

    The only difference between C: Incremental and C: Incremental Monday is that the former turns the computer off after it has completed, whereas, because the C: Full job must run immediately afterwards, the latter does not.

    IMAGING JOBS & BATCH FILES: With the use of batch files and TI’s Pre/Post Command facility I have automated the creation and maintenance of three generations of rolling backups: Son (this week’s backup set), Father (last week’s), and Grandfather (the backup set of two weeks ago).

    The batch files described below are executed by the three TI backup jobs as follows:

    C: Full: PRE = PreWeeklyBackup.bat, POST = PostBackup.bat

    C: Incremental: PRE = PreDailyBackup.bat, POST = PostBackup.bat

    C: Incremental Monday: PRE = PreDailyBackup.bat, POST = PostDailyBackupMonday.bat

    The batch files are as simple as I can make them and contain no loops or symbolic substitution. Occasionally they are required to terminate running processes. For information and debugging purposes they also occasionally write messages to the Windows Event Log (replace “XXXX” in these statements with a character string of your own choosing that will allow you easily to locate the relevant entries in the application event log).

    BACKUP DIRECTORY STRUCTURE: The three backup drives E:, L:, and M: each contain an identical directory structure used to store both file backups and image backups. Drive images and file and folder backups are initially written to the E: drive. Later, the relevant content of the E: drive is copied (if it has changed) to the L: and M: drives.

    The directory structure is as follows (E: drive used as an example):

    E:
    \Backups​
    \Files​
    \SC_Archive
    \SC_Backups
    \Images​
    \Gen_0
    \Gen_Minus_1
    \Gen_Minus_2

    SC stores the latest file and folder backups in the directory SC_Backups. SC_Archive is used to store the previous ‘n’ versions of these files and folders. Collectively, these file and folder backups are addressed as a single profile group called “Folder Backups,” and this profile group is executed immediately before any TI job is run. Another profile group called “Mass Backups” synchronizes the E: Backups directory structure with the identical structure on L: and M:.

    PREWEEKLYBACKUP.BAT

    echo off
    rem
    rem Write start message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Execution of batch file PreWeeklyBackup.bat started."
    rem
    rem Complete idle tasks.
    rem
    rem rundll32.exe advapi32.dll,ProcessIdleTasks
    rem
    rem Point to root of C: drive.
    rem
    cd /d c:\
    rem
    rem Force termination of the Second Copy process.
    rem
    taskkill /im seccopy.exe /f /t
    rem
    rem Run all Second Copy folder backups, closing Second Copy when finished.
    rem
    "c:\Program Files\SecCopy\seccopy.exe" "Folder Backups" /ExitWhenIdle
    rem
    rem Son = backup generation 0
    rem Father = backup generation -1
    rem Grandfather = backup generation -2
    rem
    rem Delete E: grandfather files and directory.
    rem
    rd /s /q e:\Backups\Images\Gen_Minus_2
    rem
    rem Rename E: father directory to grandfather.
    rem
    move e:\Backups\Images\Gen_Minus_1 e:\Backups\Images\Gen_Minus_2
    rem
    rem Rename E: son directory to father.
    rem
    move e:\Backups\Images\Gen_0 e:\Backups\Images\Gen_Minus_1
    rem
    rem Make new E: son directory.
    rem
    md e:\Backups\Images\Gen_0
    rem
    rem Delete L: grandfather files and directory.
    rem
    rd /s /q l:\Backups\Images\Gen_Minus_2
    rem
    rem Rename L: father directory to grandfather.
    rem
    move l:\Backups\Images\Gen_Minus_1 l:\Backups\Images\Gen_Minus_2
    rem
    rem Rename L: son directory to father.
    rem
    move l:\Backups\Images\Gen_0 l:\Backups\Images\Gen_Minus_1
    rem
    rem Make new L: son directory.
    rem
    md l:\Backups\Images\Gen_0
    rem
    rem Delete M: grandfather files and directory.
    rem
    rd /s /q m:\Backups\Images\Gen_Minus_2
    rem
    rem Rename M: father directory to grandfather.
    rem
    move m:\Backups\Images\Gen_Minus_1 m:\Backups\Images\Gen_Minus_2
    rem
    rem Rename M: son directory to father.
    rem
    move m:\Backups\Images\Gen_0 m:\Backups\Images\Gen_Minus_1
    rem
    rem Make new M: son directory.
    rem
    md m:\Backups\Images\Gen_0
    rem
    rem Write message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Defrag of C: started."
    rem
    rem Defragment C: drive
    rem
    "c:\Program Files\RAXCO\PerfectDisk\PDCmd.exe" /SP /WAIT C:
    rem
    rem Write message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Defrag of C: ended."
    rem
    rem Create listing of all directories on the C: drive.
    rem
    tree > e:\Backups\Images\Gen_0\dirlist.txt
    rem
    rem Create listing of all files on the C: drive.
    rem
    dir /s /ogn /tc > e:\Backups\Images\Gen_0\filelist.txt
    rem
    rem Make a copy of the DOS editor so that the directory and file lists can be read.
    rem
    xcopy c:\i386\edit.com e:\Backups\Images\Gen_0\
    rem
    rem Write end message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Execution of batch file PreWeeklyBackup.bat ended."


    POSTBACKUP.BAT

    echo off
    rem
    rem Write start message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Execution of PostBackup.bat started."
    rem
    rem Complete idle tasks.
    rem
    rem rundll32.exe advapi32.dll,ProcessIdleTasks
    rem
    rem Copy image and file backups to external and internal drives.
    rem
    "c:\Program Files\SecCopy\seccopy.exe" "Mass Backups" /ExitWhenIdle
    rem
    rem Write end message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Execution of PostBackup.bat ended. Shutdown command will be issued."
    rem
    rem Shutdown the computer.
    rem
    c:\windows\system32\shutdown.exe -s -f -t 00


    PREDAILYBACKUP.BAT

    echo off
    rem
    rem Write start message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Execution of PreDailyBackup.bat started."
    rem
    rem Complete idle tasks.
    rem
    rem rundll32.exe advapi32.dll,ProcessIdleTasks
    rem
    rem Point to root of C: drive.
    rem
    cd /d c:\
    rem
    rem Force termination of the Second Copy process.
    rem
    taskkill /im seccopy.exe /f /t
    rem
    rem Run all Second Copy folder backups, closing Second Copy when finished.
    rem
    "c:\Program Files\SecCopy\seccopy.exe" "Folder Backups" /ExitWhenIdle
    rem
    rem Write end message to the event log.
    rem
    eventcreate /l application /t information /so XXXX /id 1 /d "Execution of PreDailyBackup.bat ended."


    POSTDAILYBACKUPMONDAY.BAT

    echo off
    rem
    rem Write start message to the event log.
    rem
    eventcreate /l application /t information /so AFPV /id 1 /d "Execution of PostDailyBackupMonday.bat started."
    rem
    rem Complete idle tasks.
    rem
    rem rundll32.exe advapi32.dll,ProcessIdleTasks
    rem
    rem Copy image and file backups to external and internal drives.
    rem
    "c:\Program Files\SecCopy\seccopy.exe" "Mass Backups" /ExitWhenIdle
    rem
    rem Write end message to the event log.
    rem
    eventcreate /l application /t information /so AFPV /id 1 /d "Execution of PostDailyBackupMonday.bat ended."
     
  2. The Gold Tooth

    The Gold Tooth Registered Member

    Joined:
    Feb 25, 2008
    Posts:
    27
    Drat! I thought I proofed the above posting well (or at least adequately), but ....

    1. When writing to the application event log I state that you should replace the literal "XXXX" with a character string of your own. This is correct, but I see that I accidentally left in at least one of the batch files the character string I use myself, "AFPV." Treat this as "XXXX" and replace as you see fit.

    2. You will see that the ProcessIdleTasks commands are commented out. I did this during testing and forgot to remove the "REM"s before publishing my post. Use ProcessIdleTasks or not as you see fit. I do.
     
  3. jaycee

    jaycee Registered Member

    Joined:
    Aug 24, 2006
    Posts:
    186
    Thank you for sharing your hard work with us :)

    I'll have those scripts on a side!
     
  4. shieber

    shieber Registered Member

    Joined:
    Oct 27, 2004
    Posts:
    3,710
    Looks like lots of hard work and darned complicated. Personally, I like to keep things simple when it comes to backups. Starting "posisiton" is to do full backups always and only. If a pressing need seems to indicate that doing all and only Fulls isn't practical (say, lack of disk space); I first consider how to address the need (get more space; save fewer backups). If directly addressing the issue is not possible or practical, then I'd consider bothering wiht incs/diffs and the complications they present.

    In most cases, I think the complexity itself is an argument against an approach.

    We've seen some reasonably simple batch files for automating backup -- and since the last coule of versions fo ATI they are generally unnecessary if you use the ATI or Windows Task Scheduler. Where batch files are a must is when one wants to start getting more variety in the backup scheme, for which your example is an excellent one.
     
  5. stcraig

    stcraig Registered Member

    Joined:
    Dec 22, 2007
    Posts:
    3
    Like you, Gold Tooth, I use a second backup program (Image for Windows) in addition to ATI. I have been looking for a simple way to "roll" the backups for IFW. Your PREWEEKLYBACKUP.BAT provided just what I was looking for.

    I, too, thank you for sharing.
     
  6. The Gold Tooth

    The Gold Tooth Registered Member

    Joined:
    Feb 25, 2008
    Posts:
    27
    If the subject of TI and batch files is of interest to you, please review my follow-up posting which presents batch files that can be used by the Windows Task Scheduler (rather than the unreliable TI scheduler) to automate the creation of rolling full and incremental backups.
     
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.