Skip to content

Instantly share code, notes, and snippets.

@danielbene
Last active May 7, 2023 15:33
Show Gist options
  • Select an option

  • Save danielbene/2a890f76ead64a80cfad5b801949cb94 to your computer and use it in GitHub Desktop.

Select an option

Save danielbene/2a890f76ead64a80cfad5b801949cb94 to your computer and use it in GitHub Desktop.

Revisions

  1. danielbene revised this gist May 7, 2023. 1 changed file with 15 additions and 22 deletions.
    37 changes: 15 additions & 22 deletions run_backup.bat
    Original file line number Diff line number Diff line change
    @@ -26,32 +26,25 @@ set SEP=---------------------------------------------------------------

    : --------------------------------------------------

    echo %SEP%
    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% backup %SYNC_FOLDER% --dry-run -v
    echo %SEP%

    SET /P AREYOUSURE=Execute backup (Y/[N])?
    IF /I "%AREYOUSURE%" NEQ "Y" GOTO END

    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% backup %SYNC_FOLDER%
    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 Backup done.
    :END
    echo %SEP%
    echo Exit.
    endlocal
    pause
    EXIT

    :RUNNER
    echo %SEP%
    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% forget %CLEANUP_RULE% --prune --dry-run -v
    %~2 --dry-run -v
    echo %SEP%

    SET /P AREYOUSURE=Execute cleanup (Y/[N])?
    IF /I "%AREYOUSURE%" NEQ "Y" GOTO ENDD

    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% forget %CLEANUP_RULE% --prune
    SET /P PROMPT=Execute %~1 (Y/[N])?
    IF /I "%PROMPT%" NEQ "Y" GOTO END

    echo Cleanup done.
    :ENDD

    echo %SEP%
    echo Exit.
    endlocal
    %~2

    pause
    echo %~1 done
    :END
    EXIT /B 0
  2. danielbene revised this gist May 7, 2023. No changes.
  3. danielbene revised this gist May 7, 2023. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion run_backup.bat
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,11 @@ setlocal

    : --------------------------------------------------

    : the bucket has to be created and the repository initialized before running the script
    : 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
  4. danielbene revised this gist May 7, 2023. No changes.
  5. danielbene created this gist May 7, 2023.
    53 changes: 53 additions & 0 deletions run_backup.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    @echo off
    setlocal

    : --------------------------------------------------

    : the bucket has to be created and the repository initialized 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=---------------------------------------------------------------

    : --------------------------------------------------

    echo %SEP%
    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% backup %SYNC_FOLDER% --dry-run -v
    echo %SEP%

    SET /P AREYOUSURE=Execute backup (Y/[N])?
    IF /I "%AREYOUSURE%" NEQ "Y" GOTO END

    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% backup %SYNC_FOLDER%

    echo Backup done.
    :END

    echo %SEP%
    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% forget %CLEANUP_RULE% --prune --dry-run -v
    echo %SEP%

    SET /P AREYOUSURE=Execute cleanup (Y/[N])?
    IF /I "%AREYOUSURE%" NEQ "Y" GOTO ENDD

    %RESTIC% -r rclone:%REMOTE_NAME%:%BUCKET% -o rclone.program=%RCLONE% --password-file %PWD% forget %CLEANUP_RULE% --prune

    echo Cleanup done.
    :ENDD

    echo %SEP%
    echo Exit.
    endlocal

    pause