Backup Script

By Xah Lee. Date: .

Here's a simple backup script i use to backup my stuff to a external drive.

# 2021-03-30

# create git archive to backup drive
# and backup other dirs to backup drive

date

$dateNow = Get-Date -Format "yyyy-MM-dd"
$destDir = "xahbackup_" + $dateNow
$xahWebGitDestDir = "xahweb_"+ $dateNow + ".git.zip"
$driveLetter="f:/"
$gitCommand = "git --git-dir='c:/Users/xah/web/.git/' archive -o '$driveLetter$xahWebGitDestDir' HEAD"

Invoke-Expression $gitCommand

mkdir $destDir

Copy-Item -Recurse -Path "c:/Users/xah/xdoc/" -Destination $destDir
Copy-Item -Recurse -Path "c:/Users/xah/git/" -Destination $destDir

Copy-Item -Recurse -Path "c:/Users/xah/Desktop/" -Destination $destDir
Copy-Item -Recurse -Path "c:/Users/xah/Documents/" -Destination $destDir

Copy-Item -Recurse -Path "d:/Documents_2021-01-09" -Destination $destDir
Copy-Item -Recurse -Path "d:/Pictures_2021-01-09" -Destination $destDir
Copy-Item -Recurse -Path "d:/Videos_2021-01-09" -Destination $destDir

date

PowerShell

How-to

Advanced

Script Examples