Learn how to – How To Securely Backup Linux system using Restic.
Are you in search for a fast, secure and easy to use backup program for Linux, macOS, and Windows?. Performing backup is a critical process for all System Administrators. Data is the most important aspect of business and we can’t trust our computers to keep data safe and available at all times. This is why we need an online and offline backup so we are able to restore in an event of system crash or unplanned disasters. All backed up data needs to be secure against any sort of attacks.
What is Restic?
Restic is a fast, secure and efficient backup program for Linux, macOS, Windows and BSD systems such as FreeBSD and OpenBSD. It uses cryptography to guarantee
Step 1: Install Restic Backup program
Use the commands below to install Restic on your system.
Install Restic on Debian/Ubuntu:
sudo apt update
sudo apt install restic
Install Restic on Fedora:
sudo dnf -y install restic
Install Restic on FreeBSD:
sudo pkg install restic
Install Restic on RHEL & CentOS
sudo yum -y install yum-plugin-copr
sudo yum copr enable copart/restic
sudo yum -y install restic
Install Restic on Arch Linux
sudo pacman -S restic
Install Restic on Windows
restic can be installed using Scoop
scoop install restic
You can check installed version of Restic using:
$ restic version
restic 0.12.1 compiled with go1.17 on linux/amd64
Update can be done with the restic self-update
command.
$ restic self-update
writing restic to /usr/bin/restic
find latest release of restic at GitHub
restic is up to date
Configure Restic autocompletion.
$ sudo restic generate --bash-completion /etc/bash_completion.d/restic
writing bash completion file to /etc/bash_completion.d/restic
$ source /etc/bash_completion.d/restic
For Zsh – Install Zsh on Linux and Configure
$ mkdir ~/.zsh
$ restic generate --zsh-completion ~/.zsh/restic.zsh
writing zsh completion file to /home/jmutai/.zsh/restic.zsh
$ echo "source ~/.zsh/restic.zsh" | tee -a ~/.zshrc
$ source ~/.zshrc
Step 2: Create Restic Backup repository
Backups are saved in a repository
. Restic has native support for the following backends.
- Local directory
- sftp server (via SSH)
- HTTP REST server (protocol rest-server)
- AWS S3 (either from Amazon or using the Minio server)
- OpenStack Swift
- BackBlaze B2
- Microsoft Azure Blob Storage
- Google Cloud Storage
In this guide, we will use AWS S3 service to store our backups. But you can also configure other backends by following the guides on above links.
Configure AWS S3 backend
Install and configure AWS CLI using our guide on how to install and use AWS CLI. Once this is done, create s3 bucket for saving files.
$ aws s3 mb s3://databackups.local
make_bucket: databackups.local
Replace databackups
.local
with the name of the bucket to create. S3 bucket can also be created from the AWS console.
Export AWS credentials if you don’t have them in ~/.aws/credentials
.
export AWS_ACCESS_KEY_ID=<MY_ACCESS_KEY>
export AWS_SECRET_ACCESS_KEY=<MY_SECRET_ACCESS_KEY>
Initialize a repository that uses your Amazon S3 as a backend.
$ restic --repo s3:s3.amazonaws.com/databackups.local init
enter password for new repository: <SetPassword>
enter password again: <ConfirmPassword>
created restic repository c564d0cd66 at s3:s3.amazonaws.com/databackups.local
Please note that knowledge of your password is required to access
the repository. Losing your password means that your data is
irrecoverably lost.
Step 3: Backing up Data with Restic
Now that we have the repository initialized, let’s start to backup our data. The contents of a directory at a specific point in time is called a “snapshot” in restic.
$ restic --repo s3:s3.amazonaws.com/databackups.local backup sitemap.xml
open repository
enter password for repository:
repository c564d0cd opened successfully, password is correct
created new cache in /home/jmutai/.cache/restic
Files: 1 new, 0 changed, 0 unmodified
Dirs: 0 new, 0 changed, 0 unmodified
Added to the repo: 13.719 KiB
processed 1 files, 13.340 KiB in 0:02
snapshot ca04a741 saved
This will sitemap.xml
s3:s3.amazonaws.com/databackups.local
ca04a741
To upload a directory with multiple files, just replace sitemap.xml
with the name of directory.
List files in a repository
Use restic list
to list objects in the repository.
$ restic --repo s3:s3.amazonaws.com/databackups.local list index
enter password for repository:
repository c564d0cd opened successfully, password is correct
6589e05e67933146677712caecd88719be2e852da017c8ae965edee05a35466e
6cd779cb7adf737d3f77856ba49b864d887a60e663cee7c7763013e2b37baab6
$ restic --repo s3:s3.amazonaws.com/databackups.local list snapshots
enter password for repository:
repository c564d0cd opened successfully, password is correct
005c3d29e4771bd82b522dd3756fe4250bbe698dbdfc60731d7d11488a29427d
ca04a741482b8a38ebd4b4a0015476031a302089e690a6217f2c355d1fe57ca9
List files in snapshot using ls option. Pass the first 8
characters of Snapshot ID
$ restic -r s3:s3.amazonaws.com/databackups.local ls ca04a741
enter password for repository:
repository c564d0cd opened successfully, password is correct
snapshot ca04a741 of [/home/jmutai/sitemap.xml] filtered by [] at 2019-03-07 09:20:14.108746307 +0300 EAT):
/sitemap.xml
You can also backup files from a list, and exclude files from a list.
find /path | grep 'PATTERN1' > /tmp/files_to_backup
find /path | grep 'PATTERN2' > /tmp/excludes.txt
restic -r /srv/restic-repo backup ~/work --exclude="*.c" --exclude-file=excludes.txt
restic -r /restic-repo backup --files-from /tmp/files_to_backup
--exclude-file=/tmp/excludes.txt /otherfiles
For more usage examples, read Restic Documentation. Other guides available are:
- How to Backup and Restore Ubuntu, Debian & Linux Mint using Timeshift
- How to Backup files to Scaleway Object Storage using AWS-CLI
- How to Install Nakivo VMware Backup & Replication tool on Linux
- Ten Best Terminal Emulators for Linux
Leave a Reply
You must be logged in to post a comment.