Skip to content

Instantly share code, notes, and snippets.

@cco
Last active May 19, 2025 07:17
Show Gist options
  • Select an option

  • Save cco/f5f6155abdd07387ebc04258e0233a6a to your computer and use it in GitHub Desktop.

Select an option

Save cco/f5f6155abdd07387ebc04258e0233a6a to your computer and use it in GitHub Desktop.
Powershell script for restic backups using latest winget package for restic. Use task scheduler to automate.
$env:RESTIC_REPOSITORY = ""
$env:RESTIC_PASSWORD = ""
$directories = @(
"C:\file\path\",
"\\server\path"
)
$excludePatterns = @(
"*.mkv", "*.mov",
"*.exe", "*.bin", "*.iso", "*.dll", "*.crdownload",
"*.jpg", "*.jpeg", "*.png", "*.gif",
"C:\file\path\"
)
$excludeArgs = $excludePatterns | ForEach-Object { "--exclude=$_" }
$backupArgs = @("backup") + $directories + $excludeArgs
Write-Host "Starting restic backup..." -ForegroundColor Cyan
& restic_0.18.0_windows_amd64.exe @backupArgs
Write-Host "Pruning old snapshots..." -ForegroundColor Yellow
& restic_0.18.0_windows_amd64.exe forget --keep-daily 7 --keep-weekly 4 --keep-monthly 1 --prune
Write-Host "Backup completed." -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment