Robocopy backup script with Bitlocker support

Due to security and comfort considerations I enhanced my previous backup script to include the Bitlocker unlock process.

  1. the script tries to unlock the USB Key if it’s still locked
  2. after the notification if the stick got unlocked or the password was wrong there is a countdown of 5 seconds, press Y to reenter the password. (there’s room for further improvement, more on that later)
  3. when the 5 seconds pass (or the N-Key got pressed), the backup process begins
  4. after the backup process I can chose between either leaving the stick mounted or not
  5. after 15 seconds the script choose the default option which is to leave the stick mounted
  6. after another 30 seconds, or after any key press, the script closes the command line
@ECHO OFF
:UNLOCKERROR
CLS
ECHO ### TRYING TO UNLOCK BITLOCKED USB KEY
ECHO ###
ECHO ###
manage-bde E: -unlock -pw
CHOICE /T 5 /D N /M "### REENTER PASSWORD?"
IF Errorlevel 2 Goto GOON
Goto UNLOCKERROR
:GOON
CLS
ECHO ### STARTING BACKUP
ECHO ###
ECHO ###
robocopy C:\Users\username\Documents\_MDAW\_Thesis\ E:\ /E /MT:8 /tee /log+:E:\_backup_log.txt
robocopy C:\Users\username\Desktop E:\ workingHours.xlsx /log+:E:\_backup_log.txt
robocopy C:\Users\username\Desktop E:\ fuelReport.xlsx /log+:E:\_backup_log.txt
robocopy C:\Users\username\Documents\Scripts E:\ backupThesis.bat /log+:E:\_backup_log.txt
ECHO ### BACKUP FINISHED
ECHO ###
ECHO ###
ECHO ### TO UNMOUNT USB KEY PRESS Y.
ECHO ### TO LEAVE IT MOUNTED PRESS N OR WAIT 15 SECONDS.
CHOICE /T 15 /D N /M "###"
IF Errorlevel 2 Goto NO
IF Errorlevel 1 Goto YES
Goto End

	:YES
	manage-bde E: -lock
	GOTO END

	:NO
	ECHO USB KEY NOT UNMOUNTED

:END
TIMEOUT /T 30

Next Steps:

  • find a way to trigger the first if clause dependent on whether the password was right or not
  • implement selection for drive letter with a default option

Published by

Matt

pure awesome

Leave a Reply