Skip to content

Instantly share code, notes, and snippets.

@stil stil/backup.ps1
Created Mar 2, 2014

What would you like to do?
Differential backup with 7zip and Powershell
$dirToBackup = "C:\Users\John" # path to directory we back up (no following backslash)
$outputDir = "E:\bak" # path directory we store our backups (no following backslash)
$params = '-t7z', '-r', '-ms=off', '-mx1'
$fullBackup = $outputDir + "\full.7z"
if (Test-Path ($fullBackup)) { # Let's check whether full backup exists
Write-Host "Full backup already exists"
$args = ,'u' + $params
$args += '-u-', "-up0q3r2x2y2z0w2!`"$($outputDir)\diff-$(Get-Date -format "yyyyMMdd-HHmmss").7z`""
$args += $fullBackup, $dirToBackup
} else {
$args = , ('a') + $params + $fullBackup + $dirToBackup
& 7z $args

This comment has been minimized.

Copy link

mkomputes commented Dec 17, 2017

Thanks for the inspiration!

Note: Having $args in an array is essential to having the !difffile passed to 7z with quotes around it. Otherwise the parser will strip them off and 7z will throw an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.