wordpress meta
title: 'Restic PowerShell Script'
date: '2020-03-10T13:15:50-05:00'
status: publish
permalink: /restic-powershell-script
author: admin
excerpt: ''
type: post
id: 1464
category:
- Backups
- restic
tag: []
post_format: []
title: 'Restic PowerShell Script'
date: '2020-03-10T13:15:50-05:00'
status: publish
permalink: /restic-powershell-script
author: admin
excerpt: ''
type: post
id: 1464
category:
- Backups
- restic
tag: []
post_format: []
Just for my reference my quick and dirty Windows backup script for restic. I left some of the rclone, jq lines in but commented out. Depending on how to handle logging it may be helpful. In one project I pushed the summary json output to a S3 bucket. In this version I ran a restic job to backup the log since the initial job won\'t contain the log still being generated of course.
For this way of logging ie keeping the logs in restic not rclone/jq/buckets potentially when reporting you will dump the log from the latest repo like so:
```bash
$ restic -r s3:s3.amazonaws.com/restic-windows-backup-poc.
Here is restic-backup.ps1. Note the hidden file for the restic variables and encryption key of course. And I am doing forget/prune here but that should be done weekly.
```powershell
Custom variables
. .\restic-keys.ps1 $DateStr = $(get-date -f yyyy-MM-dd-HHmm) $server = $env:COMPUTERNAME.ToLower() $logtop = jobs $restichome = C:\Software\restic-backup
if ( -not (Test-Path -Path $restichome\${logtop}\${server} -PathType Container) ) { New-Item -ItemType directory -Path $restichome\${logtop}\${server} }
$jsonfilefull = .\${logtop}\${server}\${DateStr}-restic-backup-full.json $jsonfilesummary = .\${logtop}\${server}\${DateStr}-restic-backup.json
.\restic.exe backup $restichome Y:\Docs\ --exclude $restichome\$logtop --tag prod --exclude 'omc**' --quiet --json | Out-File ${jsonfilefull} -encoding ascii
Get-Content ${jsonfilefull} | .\jq-win64.exe -r 'select(.message_type==\summary)' | Out-file ${jsonfilesummary} -encoding ascii
cat ${jsonfilefull} | Select-String -Pattern summary | Out-file ${jsonfilesummary} -encoding ascii -NoNewline del ${jsonfilefull}
.\rclone --config rclone.conf copy .\${logtop} s3_ash:restic-backup-logs
.\restic.exe backup $restichome\$logtop --tag logs --quiet
del ${jsonfilesummary}
.\restic forget -q --prune --keep-hourly 5 --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 5 ````