Backup with Powershell

This is a copy of my backup script system_image_backup.ps1 that I use for machines that don’t have a GUI to configure backups. I made a github repo for this so you can just use the command:

git clone https://github.com/steppy345/powershell_backup.git

Then, you can edit the files in Powershell ISE

system_image_backup.ps1

################################################
#
#  Create a System Image Backup
#  Backup to internal drive
#
#  Author: <Your_Name>
#  Contact: <Your_Email>
#
#################################################

$backup_source = 'C:,D:'
$backup_destination = 'G:'
$logfile = 'C:\Log\BackupLog-' + $(Get-Date -Format MM-dd-yyyy-HH-mm-ss) + '.txt'

#Create New Backup Log File
New-Item -Path $logfile -ItemType File

#Backup starting on logfile
Write-Output "Backup Starting `n`n" | Out-File $logfile -Append

#Begin Backup
wbAdmin start backup -backupTarget:$backup_destination -include:$backup_source -allCritical | Out-File $logfile -Append

Write-Output "Backup Success" | Out-File $logfile -Append

Write-Output "Spawning External Backup Process" | Out-File $logfile -Append
& "$PSScriptRoot\copy_backup_ext.ps1"

Here is the copy of my copy_backup_ext.ps1 script.

copy_backup_ext.ps1

################################################
#
#  Create backup to external drive
#
#
#  Author: <Your_Name>
#  Contact: <Your_Email>
#
#################################################
Write-Output "Backup to external storage starting...`n"

robocopy G:\ E:\ /MIR /MT /V /ZB

Then I create a scheduled task and have it run during the night.

Note: Make sure that the user running the script is the “owner” on the drive or partition that the backup is being copied to. I had to reformat a couple of external drives i.e. Tuesday and Friday for example such that the necessary permissions to write to the drive were there.