{"id":1464,"date":"2020-03-10T13:15:50","date_gmt":"2020-03-10T18:15:50","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1464"},"modified":"2020-04-12T11:56:02","modified_gmt":"2020-04-12T16:56:02","slug":"restic-powershell-script","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/restic-powershell-script\/","title":{"rendered":"Restic PowerShell Script"},"content":{"rendered":"

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.<\/p>\n

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:<\/p>\n

$ restic -r s3:s3.amazonaws.com\/restic-windows-backup-poc.<domain>.com dump latest \/C\/Software\/restic-backup\/jobs\/desktop-l0qamrb\/2020-03-10-1302-restic-backup.json | jq\n {\n   message_type: summary,\n   files_new: 0,\n   files_changed: 1,\n   files_unmodified: 12,\n   dirs_new: 0,\n   dirs_changed: 2,\n   dirs_unmodified: 3,\n   data_blobs: 1,\n   tree_blobs: 3,\n   data_added: 2839,\n   total_files_processed: 13,\n   total_bytes_processed: 30386991,\n   total_duration: 1.0223828,\n   snapshot_id: e9531e66\n }<\/code><\/pre>\n

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.<\/p>\n

##################################################################\n#Custom variables\n. .\\restic-keys.ps1\n$DateStr = $(get-date -f yyyy-MM-dd-HHmm)\n$server = $env:COMPUTERNAME.ToLower()\n$logtop = jobs\n$restichome = C:\\Software\\restic-backup\n###################################################################\n\nif ( -not (Test-Path -Path $restichome\\${logtop}\\${server} -PathType Container) ) \n{ \n   New-Item -ItemType directory -Path $restichome\\${logtop}\\${server} \n}\n\n$jsonfilefull = .\\${logtop}\\${server}\\${DateStr}-restic-backup-full.json\n$jsonfilesummary = .\\${logtop}\\${server}\\${DateStr}-restic-backup.json\n\n.\\restic.exe backup $restichome Y:\\Docs\\ --exclude $restichome\\$logtop --tag prod --exclude 'omc\\**' --quiet --json | Out-File ${jsonfilefull} -encoding ascii\n\n#Get-Content ${jsonfilefull} | .\\jq-win64.exe -r 'select(.message_type==\\summary\\)' | Out-file ${jsonfilesummary} -encoding ascii\ncat ${jsonfilefull} | Select-String -Pattern summary | Out-file ${jsonfilesummary} -encoding ascii -NoNewline\ndel ${jsonfilefull}\n\n#.\\rclone --config rclone.conf copy .\\${logtop} s3_ash:restic-backup-logs\n.\\restic.exe backup $restichome\\$logtop --tag logs --quiet\n\ndel ${jsonfilesummary}\n\n.\\restic forget -q --prune --keep-hourly 5 --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 5<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Just for my reference my quick and dirty Windows backup script for restic. I left some of the rclone, jq<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,99],"tags":[],"class_list":["post-1464","post","type-post","status-publish","format-standard","hentry","category-backups","category-restic"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1464"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1464\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}