Restic – backup to the cloud

Few months ago we decided to change our backup workflow. I found an ultimate tool for backing up our web servers to Digital Ocean Spaces (object storage, cheaper then Amazon S3).

Restic – backups done right!

Main features:

  • easy
  • encrypted
  • fast
  • wide range of backends

You can backup your files to local, via SFTP, Amazon S3, Digital Ocean Spaces, MS Azure Blob storage, Google Cloud Storage, Backblaze B2 (very cheap 😉 ) or they own REST server. In April 2018 they added support to rclone, so the number of supported service has increased rapidly (e.g. DropBox, OneDrive, Google Drive, OwnCloud and many more).

Example of simple files/DB backup script:

#! /bin/bash

MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
ARCHIVE=/usr/bin/pigz
RESTIC=/usr/local/bin/restic
BACKUP_DIR=/www/htdocs


export AWS_ACCESS_KEY_ID="<KEY>"
export AWS_SECRET_ACCESS_KEY="<SECRET>"
export RESTIC_PASSWORD="<PASS>"

#$RESTIC init

#Backup MySQL

export RESTIC_REPOSITORY="s3:ams3.digitaloceanspaces.com/lynt-test-db"

databases=`$MYSQL -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
for db in $databases; do
$MYSQLDUMP --opt --single-transaction --skip-lock-tables --databases $db | $ARCHIVE | $RESTIC backup --tag $db --stdin --stdin-filename $db.sql.gz
done

#Cleanup
$RESTIC forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3
#$RESTIC prune

#Backup files

export RESTIC_REPOSITORY="s3:ams3.digitaloceanspaces.com/lynt-test-web"

$RESTIC backup --exclude-file /etc/restic-exclude.conf $BACKUP_DIR

#Cleanup
$RESTIC forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3
#$RESTIC prune

Our restic-exclude.conf (glob format):

**/temp/**
**/tmp/**
**/.git/**
**/log/**
**/logs/**
**/cache/**
**/sessions/**

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s