Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Restic cheatsheet

Restic backup application - commands cheatsheet

Installation & config

  1. add Retic repo
  2. yum install restic

add a Restic credential file to root

vim /root/.restic

export RESTIC_REPOSITORY=s3:<name of host>
export AWS_ACCESS_KEY_ID=<id>
export RESTIC_PASSWORD="<pw>"

initialize S3 Repo

source /etc/restic/cred
restic init

created restic repository 73974eeba3 at s3:

Please note that knowledge of your password is required to access
the repository. Losing your password means that your data is
irrecoverably lost.

Backing up directories

backup a single directory

restic backup /home/user

create a file that contains paths to backup (include and exclude), run restic

restic backup --files-from=restic_include.conf --exclude-file=restic_exclude.conf

open repository
repository 73974eeb opened successfully, password is correct

Files:        4136 new,     0 changed,     0 unmodified
Dirs:            3 new,     0 changed,     0 unmodified
Added to the repo: 261.182 MiB

processed 4136 files, 285.394 MiB in 0:18
snapshot a40aec1c saved

Check file difference

use diff to compare different snapshots show snapshots

restic snapshots

repository 73974eeb opened successfully, password is correct
ID        Time                 Host        Tags        Paths
a40aec1c  2019-02-27 16:08:54  awstestbox              /home  /root

16d01d35  2019-02-27 16:13:19  awstestbox              /home  /root
2 snapshots

compare diff between 2 snapshots

restic diff a40aec1c 16d01d35

repository 73974eeb opened successfully, password is correct
comparing snapshot a40aec1c to 16d01d35:

+    /root/test.txt
M    /var/log/messages
M    /var/spool/mail/root

Files:           1 new,     0 removed,     2 changed

Find a file in a snapshot

restic find /etc/hosts

List files in latest snaphot

restic ls -l latest

Cat file in a snapshot

restic dump latest /etc/hosts (or insert snapshot ID instead of latest)

Restoring from a snapshot

example, restore a user's /home directory from latest snapshot

restic restore latest --target / --include /home/<user>

to restore to a specific dir (temporary dir)

restic restore latest --target /tmpdir --include /home/<user>

to restore all paths,

restic restore latest (or snapshot ID) --target /


configure restic to run daily and email status

0 0 * * * sh /etc/restic/

# Runs Restic backup on a schedule via cron, emails with status


### keep last # of days of snapshots

log() { 
    echo -e "$(date "+%m%d%Y_%H%M%S"): ${1}" | tee -a $LOG

notify() {
    echo -e "${1}" | mail -r "${FROM}" -s "Errors running Restic Backup on host: $(hostname)" "$1" 

cd $RDIR

echo -e "\n" | tee -a $LOG

if [ ! -f cred ]
	log "${RDIR}/cred file not present, exiting..\n\n"
	exit 1

source ${RDIR}/cred

log "starting backup.."

msg=$(restic backup --files-from=include --exclude-file=exclude >> $LOG 2>&1)

if [ $? -eq 1 ]
    notify "[restic backup]\n${msg}" $EMAIL_ALL
    log "${msg}\n-----------------------------------------"
    exit 1

msg=$(restic check >> $LOG 2>&1)

# Check for Errors
if [ $? -eq 1 ]
    notify "[restic check]\n${msg}" $EMAIL_ALL
    log "${msg}\n--------------------------------------"
    exit 1

log "removing old snapshots.."

msg=$(restic forget --keep-daily ${KEEPDAYS} --prune)

if [ $? -eq 1 ]
    notify "[restic forget]\n${msg}" $EMAIL
    log "${msg}"
    exit 1

log "end of run\n-----------------------------------------\n\n"

# notify OK
echo -e "Snapshot complete, snapshots older than $KEEPDAYS days deleted." | mail -r "${FROM}" -s "Restic Backup OK on: $(hostname)" ${EMAIL}

include and exclude examples:





Removing old snapshots

remove a snapshot by ID

restic forget SNAPSHOT_ID
restic prune

keep only last 5 snapshots, remove all others

restic forget --keep-daily

Mount S3 as a file server

install fusermount

yum install fuse
restic mount /mnt/restic

restic will mount the S3 bucket. Quit the process to unmount.

all files are located under

Copy link

pzeinlinger commented Jan 1, 2020

Thanks for your excellent work! :-) There is a small error in the notify function:
notify() {
echo -e "${1}" | mail -r "${FROM}" -s "Errors running Restic Backup on host: $(hostname)" "$1" <- should be $2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment