Backup Script

By Xah Lee. Date: . Last updated: .

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

# 2021-03-30 2021-09-28 2021-10-06

echo "Start backup"
Get-Date

$dateNow = Get-Date -Format "yyyy-MM-dd"
$backupDriveLetter="f:"
$destDirName = "xahbackup_$dateNow"
$destDirPath = (join-path $backupDriveLetter $destDirName )
$xahWebGitDestDir = "xahweb_${dateNow}.git.zip"
$gitCommand = "git --git-dir='c:/Users/xah/web/.git/' archive -o '$backupDriveLetter/$xahWebGitDestDir' HEAD"

echo "Start backup xah website git"
Get-Date

Invoke-Expression $gitCommand

echo "Start backup c drive"
Get-Date

mkdir $destDirPath

$cdriveDirs = "xdoc", "git", "Desktop", "Documents", "Downloads"
$cdriveDirs.foreach({
Compress-Archive "c:/Users/xah/$_/" (join-path $destDirPath "$_.zip")
})

echo "Start backup d drive"
Get-Date

Compress-Archive "d:/Documents_2021-01-09" (join-path $destDirPath "Documents_2021-01-09.zip")
Compress-Archive "d:/Pictures_2021-01-09" (join-path $destDirPath "Pictures_2021-01-09.zip")

cp "d:/Videos_2021-01-09" $destDirPath -Recurse

echo "Backup done."
Get-Date

PowerShell

How-to

Advanced

Script Examples