Blog

Windows Backup Scripting
If you use (or planning to use) MS Windows' built-in backup utility, you may find this blog interesting/helping. The backup utility is mainly a GUI based tool where you do not write any automating scripting. Though it works just fine in many situations, but it can cause frustration and in-efficiencies under some situations. That is where knowing the command line equivalent and a little bit of BAT (or batch) file scripting comes handy.

Say you have a perfectly configured backup with all the settings that go with it. All you want to do is change the backup type from type Normal (a complete backup) to an Incremental type. Or you want to save the backup into a different target file named using date suffix. I found using command line interface the backup utility and custom created .BAT files make it real easy after the intial time investment.

Here are some helping hints to get you started fast:

  1. You would need some help with the command line parameters. Either open up the help from the GUI and search the index for batch files.  Or enter ntbackup /?   from the command prompt and will take you straight into the most relevant help page.
  2. You would need to create your backup selection file using the GUI tool. Create your backup selection just like you would normally do. Save it to somewhere you can easily find it. The defaul location may be hard to find. You would refer to this file from your bacth command.
  3. Now you will create a l....ong command (yes, because of a large number of parameters and file paths for selection set and the backup target). I find it helpful to edit the command in a .bat file then right frm the command prompt.
  4. Assuming that you created a .bat file, you can call your .bat file from the Windows "Scheduled Tasks". It is entirely possible to put the long command into the scheduled task, though it is easier to admin the .bat file. It is also possible to extract your command line from a previously scheduled task using GUI. After all the GUI is just an interactive way to create the underlying command.
  5. Finally review and feel free to reuse the following batch files that I am currently using.

Comments/contact? Click here.

Full Backup to Dated Target File:

 @echo off
REM ------------------
REM Normal / Full backup
REM -------------------

REM ------------------
REM Day of the week
set dow=%date:~0,3%

REM Day of the year YYYYMMDD =============
set DOY=%date:~10,4%%date:~4,2%%date:~7,2%


REM Time of the day HH:MM ================
SET tod=%time:~0,5%


REM Backup location ======================
set BACKUP_DIR=G:\Backups

REM Backup set selection file ============
set BACKUP_SET=F:\Bacup_scripts\Standard_v01.bks

@echo
C:\WINDOWS\system32\ntbackup.exe backup "@%BACKUP_SET%" /d "Set created %date% at %time%" /n "%BACKUP_SET% created %date% at %time%" /v:yes /r:no /rs:no /hc:off /m normal /j "Home_Normal" /l:s /f "%BACKUP_DIR%\Home_%DOY%.bkf"

rem pause

Incremental Backup to Week Day Named Target:

@ECHO OFF
REM ------------------
REM Incremental backup
REM -------------------

REM ------------------
REM Day of the week
SET dow=%date:~0,3%

REM ------------------
REM Day of the year YYYYMMDD
SET DOY=%date:~10,4%%date:~4,2%%date:~7,2%

REM ------------------
REM Time of the day HH:MM
SET tod=%time:~0,5%

REM ------------------
REM Backup location
set BACKUP_DIR=G:\Backups

REM ------------------
REM Backup set selection file
set BACKUP_SET=F:\Bacup_scripts\Standard_v01.bks

@ECHO
C:\WINDOWS\system32\ntbackup.exe backup "@%BACKUP_SET%" /d "Set created %date% at %time%" /n "%BACKUP_SET% created %date% at %time%" /v:no /r:no /rs:no /hc:off /m incremental /j "Home_Incremental" /l:s /f "%BACKUP_DIR%\HomeI_%DOW%.bkf"

Comments/contact? Click here.