Windows backup using bitlocker and powershell secrets

Definitely not for an environment that boasts TBs of data that should be backed up the most efficient way. This solution is best suitable for environments where backups sizes are not exceeding couple of TBs in size as the BitLocker encryption will slow down the entire process by encrypting each new file during the initial copying. Once the first sync is over, consecutive synching should be far faster as only new and modified files will be copied & encrypted to the destination volume.

Further, the performance of the entire process depends upon the hardware resources available also. We deployed this solution for one of our businesses that has approximately 500GB total size, consist of hundreds of thousands of small files. The first robocopy run on each external disk over USB 3.0 took approximately 10-12 hours and the consecutive runs completed within 20-22 minutes. We used Tandberg RDX Quickstor External solution for this purpose. This time could be brought down to couple of hours if both source and destination volumes are based on SSD.

The solution approach was like this. All RDX tapes for 6 days per week were formatted as NTFS volumes, enabled BitLocker on them immediately after formatting.

The same machine Powershell was configured to run remote signed scripts. Powershell sample as below.

PS C:\Users\rajesh> Get-ExecutionPolicy
RemoteSigned
PS C:\Users\rajesh> $secretPW = "MySecretPassword123@" | ConvertTo-SecureString -AsPlainText -Force
PS C:\Users\rajesh> $secretPW | Export-Clixml -Path C:\Scripts\default.xml
PS C:\Users\rajesh> $MySecret = Import-Clixml -Path C:\Scripts\default.xml
PS C:\Users\rajesh> echo $MySecret
System.Security.SecureString
PS C:\Users\rajesh> Unlock-Bitlocker F: -Password $MySecret

Interested about what happens when your password is converted to Secure String? Check the image below. That’s how a secure string looks & someone who has access to your computer/server could still be able to convert it to plain text and get your password. Hence, this is not a 100% fail safe solution, however it could be pretty effective against robots/malicious codes.

The above exercises were to confirm everything is in place and working properly before developing the script that will be used for regular backups. Name it anything and refer it inside the scheduled job.

#DailyBackup.ps1
#Author: Rajesh Thampi
#Date: 14.10.2024

#Read the BitLocker password from the xml file
$Secret = Import-Clixml -Path C:\Scripts\default.xml

#Unlock the volume that is BitLocer protected.
Unlock-Bitlocker F: -Password $Secret

#Setup source and destination paths.
$source='D:\Some_Folder'
$destination='F:'

#Start robocopy. Use /ZB switches to avoid recyclebin related issues.
Robocopy.exe $source $destination /E /DCOPY:DAT /XO /ZB

#After the copying, lock the drive immediately.
manage-bde -lock F: -ForceDismount

By the way, RDX hardware is not cheap. Hence you should consider alternative mediums. The advantage of a BitLocker protected volume is, even during a ransomware attack these volumes could be completely immune, unless the volume is open for backups during the attack. Well, you never know.

References

Windows | re-lock BitLocker unlocked drive

Updated on 31st July 2020

Download & install the below from git, which is easier and cleaner for less tech savvy users.

Updated on 12th October 2016

The below hack is applicable to Windows 10 also, however, after the RedStone update, the registry hack entry “might” get removed and if you still prefer to right click and lock the drive without restarting, you will have to import the registry once again.

Start registry editor (double click to merge is NOT anymore supported), from the “File menu” Select import and point to the lock-bde.reg or whatever name you have given to the registry file that was manually created.

End of update //12/October/2016

The major difference between Windows 8.x Professional and Windows 7 Professional? Well you have free Bitlocker encryption for your 8.x Windows box(professional onwards), while the same is limited to Ultimate and Enterprise editions for Windows 7

Enabling Bitlocker on a drive is pretty easy, right click and go on.

image

Obviously we will not recommend you to bitlock your root drive. If you do, you are on your own :)

Now we have a problem, to unlock you must enter a password or other bitlocker supported authentication methods, which is fine. The concern is the unlocked drive remains unlocked for any user logs into the same computer until a restart.

For me this is a clear concern. I have some stuff which is not appropriate for my 7 years old daughter, or for a friend who just wants to “check his emails” during a visit.

After loads of searches, I found some nice leads which helped me to re-lock a drive by right clicking the bitlocker enabled drive in the explorer window.

Below listed were the actual links, which helped me to achieve the objective on my Windows 8.1 boxes (Office laptop & Home PC)

spreadbytes solution had one problem, I am using the boxes without UAC, thus while the .vbs script fires, nothing happens and the drive remains unlocked

Technet thread had the exact requirement addressed & all I needed to do was, alter the scripts a bit here and there to achieve my target

Open notepad or notepad++ and copy the below text and save it as lock-bde.reg

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\Drive\shell\relock-bde]
"AppliesTo"="(System.Volume.BitLockerProtection:=1 OR System.Volume.BitLockerProtection:=3 OR System.Volume.BitLockerProtection:=5)"
@="Relock drive..."
"HasLUAShield"=""
"MultiSelectModel"="Single"
 
[HKEY_CLASSES_ROOT\Drive\shell\relock-bde\command]
@=hex(2):77,00,73,00,63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,20,\
00,6d,00,61,00,6e,00,61,00,67,00,65,00,2d,00,62,00,64,00,65,00,2d,00,6c,00,\
6f,00,63,00,6b,00,2e,00,76,00,62,00,73,00,20,00,25,00,31,00,00,00

The hex values mentioned over here creates an entry like following

image

Once the value created, you can change the text as you desire to suite your situation (for Example, my development machine was not reading the PATH information properly, hence I was forced to add C:\Windows\system32 in front of the command

Open notepad or notepad++ and copy the following text into it.  Then save as “manage-bde-lock.vbs”, and copy to c:\windows\system32

Args = ""
Last = Wscript.Arguments.Count - 1
For i = 0 To Last
Args = Args & " " & Wscript.Arguments.Item(i)
Next
Args = Replace(Args,"\","")
CreateObject("Shell.Application").ShellExecute "manage-bde.exe", "-lock -forcedismount " & Args, "", "runas", 1

That’s it. You should get “Relock Driver…” context menu by right clicking on the bitlocker enabled driver from now onwards

image

Hope this helps few out there.

for Windows7bugs

rajesh