Finally I got around to actually set up a Backup routine for my Hard drive to my little Raspberry Pi “NAS”.
I decided against any fancy Software and went straight to robocopy to mirror all my files. This has the added benefit of being able to browse the files normally, but it lacks any form of compression or security by itself. For me that is enough for now though, so I went with it.
The script is fairly simple. It basically first copies a few selected User related files from my C: drive to the appropiate folder on my HDD and then Mirrors the whole tree from D:\ downwards over to my Samba share on my RasPi.
I needed to include some exceptions though.
I replaced some personal Information in my script for security reasons, but here’s the whole script:
Write-Output "Starting Backup at $(get-date -f yyyy-MM-dd--hh:mm:ss)..." >> \\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)WindowsBackupScript.log
Write-Output "Exporting Programlist" >> \\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)WindowsBackupScript.log
$tempCSV = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, UninstallString | where DisplayName -NotLike *Microsoft*
$tempCSV += Get-ItemProperty HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, UninstallString | where DisplayName -NotLike *Microsoft*
$tempCSV | Export-Csv D:\UserBackups\ProgramExport.csv
Write-Output "Copying User Stuff to Mainspace..." >> \\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)WindowsBackupScript.log
robocopy 'C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\customLinks' D:\UserBackups /MIR /Tee /Z
Write-Output "Backing up Mainspace..." >> \\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)WindowsBackupScript.log
cd D:\
robocopy D: \\192.168.[...]\[Sharename]\Backups\[PC-Name]\Mainspace /MIR /LOG+:"\\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)robocopyD_log.log" /Z /XD D:\Steam "D:\other games" D:\HyperV D:\`$RECYCLE.BIN D:\Recovery "D:\System Volume Information" D:\config.msi -np -ndl -tee
Write-Output "Finished Backup Job at $(get-date -f yyyy-MM-dd--hh:mm:ss)" >> \\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)WindowsBackupScript.log
Read-Host -Prompt "Finished all Backups. Press Enter to open the Logfile(s)."
& 'C:\Program Files\Notepad++\notepad++.exe' "\\192.168.[...]\[Sharename]\Backups\Logs\$(get-date -f yyyyMMdd)robocopyD_log.log"
So, what does my script do?
I wanted to have a log of when the script does what, so I included “comment” lines which output what the script does to the log file.
In a case of me having to reinstall Windows from scratch I decided to have some sort of list of installed programs. Backing up the installers or executables felt like a weak way to do this though, so I let powershell grab the installed programs from the registry directly and let it compile into a csv file.
$tempCSV = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, UninstallString | where DisplayName -NotLike *Microsoft*
I decided that I’d filter out everything with “Microsoft” in the name so I wouldn’t have all the restributables and stuff cluttering the list. This way a few actual programs get filtered out, but most of them are obvious enough for me to not be important in that list.
Anyway, this should help me remember the various programs I installed, just in case.
robocopy 'C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\customLinks' D:\UserBackups /MIR /Tee /Z
This little line copies the custom links I created so I can just type in the script names to run them.