TrueCrypt backup batch file
August 24th, 2007
The description of how to use this script is here. And sorry about the long lines…
echo off REM ----------------------------------------------------------------------- REM --Make sure the file, password, folder, and drive letter aren't empty-- if "%~f1"=="" goto USAGE if "%~f2"=="" goto USAGE if "%~f3"=="" goto USAGE if "%~f4"=="" goto USAGE REM --The 5th arg should be /T /A /R or /X-- if not "%~5"=="/T" if not "%~5"=="/A" if not "%~5"=="/R" if not "%~5"=="/X" if not "%~5"=="" goto USAGE if "%~5"=="/T" if "%~f6"=="" goto USAGE REM --The 7th arg should be /A /R or /X-- if not "%~7"=="/A" if not "%~7"=="/R" if not "%~7"=="/X" if not "%~7"=="" goto USAGE if "%~7"=="/A" if "%~8"=="" goto USAGE REM --The 9th arg should be /R or /X-- if not "%~9"=="/R" if not "%~9"=="/X" if not "%~9"=="" goto USAGE REM --Make sure the drive letter specified doesn't already exist-- if EXIST %4: echo Drive %4: already exists! if EXIST %4: goto END REM --Make sure the archive folder exists-- if "%~7"=="/A" if NOT EXIST "%~8" echo Archive folder does not exist if "%~7"=="/A" if NOT EXIST "%~8" goto END REM --Make sure the template file isn't the same file-- if not "%~5"=="/T" if "%~f6"=="%~f1" echo TrueCrypt template and TrueCrypt volume are the same file! if not "%~5"=="/T" if "%~f6"=="%~f1" goto END REM --Make sure the template file exists-- if "%~5"=="/T" if NOT EXIST "%~f6" echo TrueCrypt template volume file does not exist! if "%~5"=="/T" if NOT EXIST "%~f6" goto END REM --WHERE TO BEGIN?--- if "%~5"=="/T" goto TEMPLATE goto MOUNT REM ----------------------------------------------------------------------- :TEMPLATE echo Copying TrueCrypt Volume template... copy "%~f6" "%~f1" if NOT EXIST "%~f1" echo Failed to copy TrueCrypt template volume file! if NOT EXIST "%~f1" echo (Is the new TrueCrypt volume's path valid?) if NOT EXIST "%~f1" echo (Are you running Vista and have UAC on?) if NOT EXIST "%~f1" echo (Is the folder of the new TrueCrypt volume read-only?) if NOT EXIST "%~f1" goto END echo TrueCrypt Volume created! REM ----------------------------------------------------------------------- :MOUNT echo Mounting TrueCrypt Volume... "C:Program Files (x86)TrueCryptTrueCrypt.exe" /v "%~f1" /l%4 /p %2 /s /q if NOT EXIST %4: echo Failed to mount TrueCrypt volume! if NOT EXIST %4: goto END echo TrueCrypt Volume mounted! if "%5"=="/R" goto ROBOCOPY if "%5"=="/X" goto XCOPY if "%7"=="/R" goto ROBOCOPY if "%7"=="/X" goto XCOPY if "%9"=="/R" goto ROBOCOPY if "%9"=="/X" goto XCOPY REM ----------------------------------------------------------------------- :ROBOCOPY robocopy "%~f3" %4: /E echo Files copied into TrueCrypt Volume! goto DISMOUNT REM ----------------------------------------------------------------------- :XCOPY xcopy "%~f3" %4: /E echo Files copied into TrueCrypt Volume! goto DISMOUNT REM ----------------------------------------------------------------------- :DISMOUNT echo Dismounting TrueCrypt Volume... "C:Program Files (x86)TrueCryptTrueCrypt.exe" /q /d%4 /s if EXIST %4: echo Failed to dismount TrueCrypt volume! if EXIST %4: goto END echo TrueCrypt Volume dismounted! if "%~5"=="/A" goto ARCHIVE if "%~7"=="/A" goto ARCHIVE goto END REM ----------------------------------------------------------------------- :ARCHIVE if "%~5"=="/A" move "%~f1" "%~f6" if "%~7"=="/A" move "%~f1" "%~f8" echo TrueCrypt Volume archived! goto END REM ----------------------------------------------------------------------- :USAGE echo Creates a TrueCrypt volume of the specified folder echo. echo TCBACKUP trueCryptVolume password folderToBackup driveLetter [/T templateVolume] [/A archiveFolder] [/R ^| /X] echo. echo trueCryptVolume The name of the TrueCrypt volume file to backup to echo password The password of the TrueCrypt volume file echo folderToBackup The folder to store in the TrueCrypt volume file echo driveLetter The drive letter to mount the TrueCrypt volume at echo /T Uses a template TrueCrypt volume file to create the TrueCrypt volume file echo templateVolume The path to the template TrueCrypt volume file echo /A Moves the finished TrueCrypt volume to an archive folder echo archiveFolder The archive folder to move the TrueCrypt volume file to echo /R Uses robocopy to do the copying (default) echo /X Uses xcopy to do the copying echo. REM ----------------------------------------------------------------------- :END echo on





[…] TrueCrypt backup batch file […]
August 24, 2007 @ 4:47 am
Excellent script. I’ve been seeking something simple and elegant like this, and it already uses TrueCrypt + RoboCopy which were two of my requirements! I’ll give this a shot. Thanks for sharing.
September 17, 2009 @ 7:49 am