tinyapps.org / blog


Drive SnapShot batch file with auto-pruning #

Drive SnapShot is a truly remarkable tool. It is a noninvasive, standalone EXE that can image live or offline systems quickly and easily. Here is a simple batch file for daily backups and automatic pruning:
@echo off

REM This batch file calls Drive SnapShot to backup all partitions on HD1 to the
REM "backups" directory on the drive from which it was launched. As a result, there
REM is no need to worry about external drive letter assignments.

REM Filenames begin with the day of the week, allowing for easy auto-pruning of the
REM backup from last week.

REM Save this batch file (e.g., "backup.bat") along with the Drive SnapShot executable
REM ("snapshot.exe") to the root directory of your external backup storage device(s).
REM Be sure to create a folder called "backups" in the root directory as well - that's
REM where the backups will be stored.

REM Recommended: Set AutoPlay to open Explorer window when external backup devices
REM are plugged in so that you can simply double click "backup.bat" to start the backup.

REM Set "today" variable to 3 letter abbreviation for today

for /f %%x in ('date /t') do set today=%%x

REM Even though "date /t" output looks like "Sun 12/16/2012", the for command extracts
REM just the first word from each line of text it reads. The definition of "word" is text
REM delimited by one or more spaces or tabs.

REM Delete last week's backup

if '%today%=='Mon del .\backups\mo*.*
if '%today%=='Tue del .\backups\tu*.*
if '%today%=='Wed del .\backups\we*.*
if '%today%=='Thu del .\backups\th*.*
if '%today%=='Fri del .\backups\fr*.*
if '%today%=='Sat del .\backups\sa*.*
if '%today%=='Sun del .\backups\su*.*

REM Call Drive SnapShot to image all partitions on HD1

.\snapshot.exe HD1:* .\backups\$weekday-$date-$disk-$computername.sna -L0 --usevss

REM The -L0 option prevents Drive SnapShot from splitting partition backups into 650MB
REM chunks. Be sure backup storage device(s) filesystem(s) can handle large file sizes
REM (NTFS, exFAT, etc - *not* FAT32!).

REM Drive SnapShot homepage:
REM http://www.drivesnapshot.de/en/index.htm
REM Auto-pruning routine from AlanCulshaw:
REM http://www.wilderssecurity.com/showpost.php?p=722654&postcount=19
REM This blog post:
REM http://tinyapps.org/blog/windows/201308070700_drive_snapshot_batch_file.html

/windows | Aug 07, 2013


Subscribe or visit the archives