Skip to content

Instantly share code, notes, and snippets.

@hastern
Created January 27, 2017 16:26
Show Gist options
  • Save hastern/739b0894b957cb67d2abdd0431d759b9 to your computer and use it in GitHub Desktop.
Save hastern/739b0894b957cb67d2abdd0431d759b9 to your computer and use it in GitHub Desktop.
batch script to backup data using restic
@echo off
Setlocal EnableDelayedExpansion
IF [%RESTIC_REPOSITORY%] == [] GOTO missingrepo
IF [%RESTIC_PASSWORD%] == [] GOTO missingpass
IF NOT EXIST %RESTIC_REPOSITORY% GOTO invalidrepo
REM Expect restic to be in the system path
SET RESTIC_PATH=restic
REM One file / folder per line
SET RESTIC_BACKUP_FILE=%HOME%\restic_backup.txt
REM One pattern per line
SET RESTIC_EXCLUDE_FILE="%HOME%\.restic_exclude"
FOR /F %%F IN (%RESTIC_BACKUP_FILE%) DO CALL %RESTIC_PATH% --exclude-file=%RESTIC_BACKUP_FILE% backup %%F
REM Change deletion strategy if needed
%RESTIC_PATH% forget --keep-daily 7
GOTO eof
:missingrepo
ECHO Repository location missing in ENV
ECHO Set it by entering: SET RESTIC_REPOSITORY=[LOCATION]
GOTO eof
:missingpass
ECHO Repository password missing in ENV
ECHO Set it by entering: SET RESTIC_PASSWORD=[PASSWORD]
GOTO eof
:invalidrepo
ECHO No Repository found at %RESTIC_REPOSITORY%
ECHO Forgot to insert the USB Drive?
GOTO eof
:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment