The restic is a fast, secure, and efficient backup tool via command line designed to back up files and directories. It supports multiple storage backends, including local storage, SFTP, Amazon S3, and other cloud services. The restic is known for its simplicity, encryption by default, and data deduplication features. This tutorial shows how to install restic on Ubuntu 24.04.
Prepare environment
To extract bz2 archive, ensure the bzip2 tool is installed:
sudo apt update
sudo apt install -y bzip2
Install restic
Obtain the most recent restic version from its GitHub repository:
RESTIC_VERSION=$(curl -s "https://api.github.com/repos/restic/restic/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
Download restic archive:
sudo wget -qO /usr/local/bin/restic.bz2 https://github.com/restic/restic/releases/latest/download/restic_${RESTIC_VERSION}_linux_amd64.bz2
Use the following command to extract the binary file from the archive:
sudo bzip2 -d /usr/local/bin/restic.bz2
Set execute permission:
sudo chmod a+x /usr/local/bin/restic
We can verify restic version as follows:
restic version
Testing restic
After installing restic, begin by creating a repository for your backups:
restic init --repo /tmp/backup
Output example:
enter password for new repository:
enter password again:
created restic repository 3414a7b441 at /tmp/backup
Please note that knowledge of your password is required to access
the repository. Losing your password means that your data is
irrecoverably lost.
Create directory and file for testing:
mkdir ~/myproject
touch ~/myproject/test.txt
To back up the specified directory, run this command:
restic --repo /tmp/backup backup ~/myproject
Output example:
enter password for repository:
repository 3414a7b4 opened (version 2, compression level auto)
created new cache in /home/adminer/.cache/restic
no parent snapshot found, will read all files
Files: 1 new, 0 changed, 0 unmodified
Dirs: 1 new, 0 changed, 0 unmodified
Added to the repository: 658 B (548 B stored)
processed 1 files, 0 B in 0:00
snapshot 31abb0ba saved
Remove directory to test recovery:
rm -rf myproject
View all snapshots saved in the repository:
restic --repo /tmp/backup snapshots
Output example:
enter password for repository:
repository 3414a7b4 opened (version 2, compression level auto)
ID Time Host Tags Paths
------------------------------------------------------------------------------
31abb0ba 2024-07-06 04:09:01 ubuntu /home/adminer/myproject
------------------------------------------------------------------------------
1 snapshots
Use this command to restore the backup from the snapshot:
restic --repo /tmp/backup restore 31abb0ba --target ~/
Output example:
enter password for repository:
repository 3414a7b4 opened (version 2, compression level auto)
restoring <Snapshot 31abb0ba of [/home/adminer/myproject] at 2024-07-06 04:09:01.890585611 +0000 UTC by adminer@ubuntu> to /home/adminer/
Summary: Restored 2 files/dirs (0 B) in 0:00
Uninstall restic
If restic is no longer needed, remove related file:
sudo rm -rf /usr/local/bin/restic
Remove cache:
rm -rf ~/.cache/restic
Leave a Comment
Cancel reply