Skip to content

Instantly share code, notes, and snippets.

@danielbene
Last active May 7, 2023 15:33
Show Gist options
  • Save danielbene/2a890f76ead64a80cfad5b801949cb94 to your computer and use it in GitHub Desktop.
Save danielbene/2a890f76ead64a80cfad5b801949cb94 to your computer and use it in GitHub Desktop.
Windows backup script with restic and rclone to a Backblaze B2.
@echo off
setlocal
: --------------------------------------------------
: Avoiding the built in B2 backend according to the docs, and I could not make pruning work with the S3 api (lifecycle delete rule did absolutely nothing).
: It's a bit clunky, but wokrs for me. Check this for more info: https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#backblaze-b2.
: You have to create the bucket and initialize the repository before running the script.
: --------------------------------------------------
set RESTIC="c:\Programs\restic\restic.exe"
: restic parameter paths should use forward slash
set RCLONE="c:/Programs/restic/rclone.exe"
: password file contains a single line with the repository password
set PWD="c:/Programs/restic/pwd"
set REMOTE_NAME="awesome-sync"
set BUCKET="awesome-sync-folder"
set SYNC_FOLDER="c:/path/to/sync"
set CLEANUP_RULE=--keep-daily 5 --keep-monthly 6 --keep-yearly 5
set SEP=---------------------------------------------------------------
: --------------------------------------------------
CALL :RUNNER "backup", "%RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% backup %SYNC_FOLDER%"
CALL :RUNNER "cleanup", "%RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% forget %CLEANUP_RULE% --prune"
echo %SEP%
echo Exit.
endlocal
pause
EXIT
:RUNNER
echo %SEP%
%~2 --dry-run -v
echo %SEP%
SET /P PROMPT=Execute %~1 (Y/[N])?
IF /I "%PROMPT%" NEQ "Y" GOTO END
%~2
echo %~1 done
:END
EXIT /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment