Restic
Is a Backup Software that can run on Windows, Linux, MacOS
Links¶
Reference¶
- Exclude
resticfrom antivirus - Configuration are held using environment variables using Batch, PowerShell or bash
- Update binaries using
restic self-update
Initialize a repo¶
restic initto create the remote repository- Specify the repo with
- Passwords can be provided via:
- CLI, when the user execute
restic - The variable
RESTIC_PASSWORDor option - A file, defined in
--password-file fileor variableRESTIC_PASSWORD_FILE - An external software, called via
--password-command commandor variableRESTIC_PASSWORD_COMMAND
- CLI, when the user execute
Create a backup¶
restic backup ~/dirAto backupdirAto the reporestic backup /dirA /dirBto backup multiple directories or files
restic backup /fileA.zipto backupfileAto the repo- If
fileAwas part ofdirA, it get saved at no extra cost 🤯
- If
- Use
stdinas backup input for CLI dump - Exclusions & inclusions filters
--exclude-if-present .backupignorewill ignore the content of any directory with file.backupignoreinside - only the directory name and this file will be saved
View snapshots¶
restic snapshotsto view all snapshots in the repo - docrestic statsto view information: size of all snapshots (not on disk), ...restic diff snapshotID1 snapshotID2to check difference between 2 snapshots-
- Add
--tag XYZto add identify information on creation or edition
- Add
Manage data¶
Verification¶
restic checkto verify structural consistency & integrity - Should be used regularly!restic check --read-datato verify backup data integrity- This command does it in full, but subset are possible - see doc
Removing snapshots¶
restic forget snapshotID|policyto remove one snapshot- Policy are defined here
- Policy are chainable like
restic forget --keep-daily 7 --keep-weekly 5 --keep-monthly 6 --keep-yearly 1for 100 years - Default policy is grouped per host name and path, can be changed with
--group-by 'tagsfor instance
restic pruneto definitely remove data that are unlinked to any snapshot- It is advised to run a
restic checkafter
- It is advised to run a
- And
restic recoverto restore removed snapshot that are notpruneed
Manage locks¶
restic unlockto remove locks from the repo that are ≥ 30 min or created by local hostrestic unlock --remove-allto force remove lock
Restore data¶
restic ls <snapshot_id>to list all files in the snapshotgrepcan be used to find a file - see Linux
restic restore <snapshot_ID> --target /path/to/restoreto restore a snapshot to directoryrestic restore <snapshot id> --include=/path/to/files/we/want/to/restore --target=/path/where/to/restorefor a certain directory to a certain target directory
restic mount ~/tempmount/to mount the whole backup repo
Passwords¶
Multiple passwords (or called key) can be defined in one repo:
- restic key list
- restic key add
- restic key remove <key_id>
- restic key passwd to change current key
CLI Flags¶
| Command | Note |
|---|---|
--use-fs-snapshot |
on Windows to use VSS and avoid file lock, bu there's some default exclusions (see doc) |
--verbose |
to see what is happening |
--verbose=2 |
to see more of what is happening: files and folder |
--dry-run |
to try a command but not write anything to the repo |
Scripting¶
- Scheduling must be done by host OS, cannot done by Restic
- Make sure that there's no already running instances!
Windows¶
Process:
- Task scheduler will run the task
- General
- Run whether user is logged on or not and Do not store password
- Run with highest privilege
- Trigger: every day
- Conditions: none
- Settings:
-
- A script will be called to
- check wheter the connection is metered or not - see gist.github.com - Powershell check if on metered network · GitHub
- if true, it will send a ping to monitoring tool
- do a restic backup according to pre-defined command
- as admin in order to use VSS
- send the result to monitoring tool
- do a restic forget according to policy
- send the result to monitoring tool
- do a restic check
- send the result to monitoring tool
- A lot of inspiration coming from this set of script
Linux¶
- Use the same PowerShell script than on Windows above
- Execute it, not as
rootbut as dedicatedresticuser - see restic doc- Don't forget to set proper files & folder permissions and ownership
chown -R root:restic /opt/restic/resticchmod 750 /opt/restic/resticsetcap cap_dac_read_search=+ep /opt/restic/restic
- Don't forget to set proper files & folder permissions and ownership
- Then schedule it with
crontab- see Cron
Related¶
- Restic browser to browse and restore backup repositories
- Restic-windows-backup, a collection of PowerShell scripts to automate backup
Ressources¶
- Official documentation
- Medium articles