- Restic offers encrypted, deduplicated, and cross-platform backups, ideal for Linux and other systems.
- It allows you to save backups on local disks and servers. SSH and S3-type clouds, with flexible retention policies.
- Its use per line of commands It facilitates automation with scripts and cron, both on servers and on devices. Android.
- It includes tools to verify integrity and restore data granularly from snapshots.
If you use Linux daily, sooner or later you'll need a backup system that's reliable, fast, and easy to restore . Restic has earned that reputation: it's simple to use, encrypts everything it saves, and works equally well on a home laptop or a cloud server.
In the following lines, you'll see how to set up a backup system with Restic on Linux that allows you to create encrypted, automatic, and verified backups , whether on a local disk, another server via SSH, or compatible cloud services (S3, Backblaze B2, Azure, etc.). The idea is that, once everything is configured, you only need to remember to occasionally check that you can restore your data.
What is Resti and why is it worthwhile in Linux?
Restic is an open-source backup program that focuses on being fast, secure, and efficient . It's written in Go and distributed as a single binary, so you don't need to deploy servers or set up complicated architectures: you run it wherever you store your data or backups, and you're good to go.
One of its greatest strengths is its cross-platform compatibility . You can use Restic on Linux, BSD, macOS, Windows , and even on architectures like ARM (for example, on a Raspberry Pi). This means that you can use the same tool to unify backups across all your systems.
Restic is based on two key concepts: repositories and snapshots . The repository is where the information is stored (locally, remotely, or in the cloud), and snapshots represent the state of the data at a specific point in time. Each time you run a backup , Restic creates a new snapshot containing only the changes since the previous one.
To protect the information, Restic encrypts all repository data with AES-256 and Poly1305-AES authentication . No files are stored in plain text: even if someone were to gain access to the repository, without the password they would not be able to read anything at all.
Another strength is deduplication. When you run a backup again, Restic detects existing blocks and only uploads or saves what has actually changed. The result: less backup time and significantly less space used, even if you run full backups frequently.
Practical advantages of Restic for your backups
Beyond the technical aspects, Restic's ease of use is a real plus in daily operations. Being a command-line tool, it's perfect for automating backups on servers without a graphical interface or integrating with scripts, cron jobs, systemd timers, and more.
You can store backups almost anywhere: a local directory, a USB drive , an SSH/SFTP server, or cloud services like Amazon S3, MinIO, Backblaze B2, Wasabi, Google Cloud Storage, OpenStack Swift, or Azure Blob Storage. You can even use rclone to add even more backends.
Another very useful advantage is that you can browse through the contents of a snapshot without fully restoring it.Through commands such as restic mount or file listings, it's easy to locate a specific file and recover it without having to restore the entire backup.
The restoration process is quite straightforward: with a single command you can recover a directory, a file, or an entire backup to the path of your choice. And if you wish, you can mount the repository in read-only mode to explore the data as if it were just another file system.
Finally, Restic includes commands to verify the integrity of copies, clean up old data, and apply retention policies (by number of copies, by age, by tags, etc.), which is essential when the repository starts to grow.
Installing Restic on Linux (and keeping it updated)
The easiest way to install Restic on most Linux distributions is to use your system's package manager . On Debian, Ubuntu, and derivatives, you can use:
sudo apt install restic
In other distributions, the usual commands would be similar to these, which serve as a quick reference to see how it is handled in different GNU/Linux environments :
sudo dnf install resticon Fedora, RHEL, CentOS, Rocky or AlmaLinuxsudo pacman -S resticon Arch Linuxsudo zypper install resticin openSUSEsudo apk add resticin Alpinesudo emerge -a sys-apps/resticin Gentoo
You can also install Resti from source code or use containers. For example, in Docker, simply download the official image with a `docker pull` :
docker pull restic/restic
If you prefer to compile it, you first need to have Go installed, then clone the repository and run the build script . This even allows you to generate binaries for other platforms (Windows, FreeBSD, Linux ARM, etc.).
git clone https://github.com/restic/restic
cd restic
go run build.go
Compiling for other systems is as simple as specifying the target system in the command, which is very practical when you have heterogeneous environments and want to use the same backup engine across all of them.
If you installed Restic from your distribution's repositories, you might not have the latest stable version. The program itself offers a command to automatically update the binary from GitHub, keeping everything up-to-date without disrupting your workflow:
sudo restic self-update
This command downloads the latest version, verifies the GPG signature, and replaces the old binary, so in a matter of seconds you have Restic updated to the latest version on your system.
Create and protect the backup repository
Before performing the first backup, you need to create the repository where the data will be stored. In a typical scenario, you might have a VPS server or remote machine acting as the backup server.
For example, on the server that will store the backups, you can create a dedicated directory, something as simple as:
mkdir /home/ubuntu/rpi4_bk
Once you have the path, initialize the repository with the init command and the -r option to indicate where the data will be stored:
restic -r /home/ubuntu/rpi4_bk init
The program will ask you for a password for the repository. It is vital that this password be strong and that you keep it safe , because without it the repository's contents are unrecoverable. Every operation that involves reading or modifying data (making backups, restoring, listing snapshots, checking integrity, etc.) will require this password or a password file.
If you use remote storage instead of a local directory , the procedure is similar, but the repository path points, for example, to an SFTP backend or an S3 URL. The important thing to understand is that the repository is the encrypted container where all your backup snapshots will reside.
Setting up a dedicated user and permissions in Linux
On Linux machines where you want to back up the entire system, a recurring problem arises: with a normal user, you can't read files owned by root or restricted areas. The most direct solution would be to run Restic as root, but you can opt for a more nuanced approach.
A very interesting pattern involves creating a user without administrative privileges, for example called restic , and adjusting the permissions so that this user can read all the necessary data without being root:
sudo useradd -m restic
sudo passwd restic
Next, the ownership and permissions of the Resti binary are changed so that only root and the restic user can execute it, reinforcing the tool's security on the system:
sudo chown root:restic /usr/bin/restic
sudo chmod 750 /usr/bin/restic
The key step is to apply a special capability to the binary with setcapso that it can read the entire system regardless of file permissions. The capability is used cap_dac_read_search=+epwhich allows Resti to traverse directories and read them as if it were root, but without needing to run as root:
sudo setcap cap_dac_read_search=+ep /usr/bin/restic
With this configuration, when you run backups using the restic user you can back up absolutely all system files , respecting a more secure separation of privileges than always running as root.
Remote access to the backup server via SSH
If your backups are going to a remote server via SFTP/SSH, the user running Restic on the client (e.g., the restic user on a Raspberry Pi ) should be able to connect without entering a password each time.
For that, a folder is created. .ssh in your home directory and within it a subdirectory where you will store the private key used to authenticate with the backup server. This entire process can be done with simple commands: create directories, generate or copy the key, and adjust permissions so that only the restic user can read it.
The private key is stored in a file, for example ubuntu_server, to which permissions 0400 and ownership of the user restic are assigned. This ensures that the key is protected and only accessible to the user who needs it:
chown restic:restic ubuntu_server
chmod 0400 ubuntu_server
To simplify the use of the key, the file is configured ~/.ssh/config from the restic user indicating a host alias (for example vps2), the server IP or name, the SSH port, the remote username, and the path to the private key. This way, when Restic uses the SFTP backend with sftp:vps2:/pathIt will automatically use that configuration.
Once this is done, the client machine's restic user can connect to the backup server without a password, allowing automatic backups to function without human intervention.
Define what is included and what is excluded in the copies
To have fine control over what's included in the backup, it's common to use two text files: one with what you want to include and another with what you want to exclude. Resty supports this through the `--files-from` and `--exclude-file` options.
For example, in the home directory of the user restic you can create a folder ~/restic and inside a file files_to_backup.txt where directories are listed as /home/pi and other important routes:
/home/pi
/media/nextcloud/twitter
/media/nextcloud/podcast
/media/nextcloud/services/jellyfin/
In parallel, a files_to_exclude.txt This section details paths that you don't want to back up (e.g., a very large video directory) or patterns such as all files with a certain extension. Thanks to this, you can fine-tune the size and relevance of your copies:
/home/pi/videos
*.txt
By combining both files, you ensure that the copy includes everything you're interested in (like the complete home directory and some folders from a service like Nextcloud or Jellyfin) and excludes what doesn't contribute much or can be easily regenerated.
Perform a manual backup with Restic
Once you have a repository, a dedicated user, an SSH connection, and include/exclude lists, you're ready to run your first manual backup. This is great for verifying that everything is working correctly before automating anything.
A typical command, if the repository is on an accessible SFTP server like vps2 and the destination route is /home/ubuntu/rpi4_bk/It would be something like:
sudo -u restic restic -r sftp:vps2:/home/ubuntu/rpi4_bk/ backup \
--tag raspberry --tag docker \
-v --exclude-file=/home/restic/restic/files_to_exclude.txt \
--files-from=/home/restic/restic/files_to_backup.txt
You use `sudo -u restic` to run the command as the restic user, specify the SFTP backend, add tags to the copy (for example, to distinguish backups from different machines or services), and specify the files to include and exclude.
During execution, you'll see Resti scan the directories, calculate the size, upload the new blocks, and finally create a snapshot with its unique identifier. Once finished, the repository on the backup server will contain a complete snapshot of your data's state at that moment.
Check that the copy is correct
There's no point in making backups if you can't restore them, so learning how to verify what's been saved is essential. Restic offers several commands for this, both from the backup server and the client.
To list the snapshots stored in a local repository, you can use something like:
restic -r /home/ubuntu/rpi4_bk/ snapshots
The list shows the ID of each snapshot, the date, the host that created it, the tags, and the included paths. With this information, you know which versions of your data are available and when they were generated.
If instead of accessing the local repository you want to do so from the client that created the copies via SFTP, the command is almost identical but changing the repository path to the remote URL:
sudo restic -r sftp:vps2:/home/ubuntu/rpi4_bk/ snapshots
To verify the integrity of the repository, the `check` command is used , which iterates through indexes, packages, and data trees and checks that everything is consistent. It's a very powerful way to ensure there's no corruption or problems in your backups.
restic -r /home/ubuntu/rpi4_bk/ check
It's advisable to run this check periodically, especially if you use external drives, network storage, or services where outages may occur, as it gives you peace of mind about the actual health of your backups.
Delete snapshots and retention policies
Over time , the number of saved snapshots can grow considerably, and it's advisable to have an organized way to delete old copies to free up space and keep the repository under control.
The most basic form consists of delete specific snapshots using its ID. First we list the copies with the snapshots command and then we can delete a specific one with forget:
restic -r /home/ubuntu/rpi4_bk/ forget 3161b4f6
This command removes the snapshot from the index, but shared data may remain on disk if it's part of other snapshots. To permanently clean up what's no longer needed, run prune on the repository:
restic -r /home/ubuntu/rpi4_bk/ prune
If you want to do it all at once from the client to an SFTP backend, you can combine both steps into a single command, asking Resti to forget a specific snapshot and then clean up the associated data.
Even more interesting is using the built-in retention policies. For example, if you want to keep only the last six copies per host, you can use:
restic forget -r /home/ubuntu/rpi4_bk/ --group-by host --keep-last 6 --prune
With this, Restic will keep the six most recent snapshots for each machine and delete the oldest ones, automatically adjusting the repository space. There are also options to retain backups by age (days, weeks, months) or by tags, giving you a lot of flexibility in designing your backup policy.
Automate backups with scripts and cron
Once you've verified that the manual backup works correctly, the next logical step is to automate the process. The usual approach is to use a small script that does all the work and schedule it with cron or an equivalent service.
The first detail to resolve is the repository passwordTo avoid typing it each time it runs, a file is usually created, for example pass en /home/restic/restic, which contains the key. It is given strict permissions so that only the restic user (and root) can read it:
echo "mi_password" > /home/restic/restic/pass
chmod 0400 /home/restic/restic/pass
You can also have an output file, like raspberry.txtwhere all the information generated by the script is redirected. This way you can easily check if the process went well or if any errors have occurred.
The automation script can be called run_backup.sh and contain several sections: write the backup date, run the copy command, apply the retention policy and, optionally, perform an integrity check at the end.
#!/bin/bash
echo -e "Backup $HOSTNAME realizado el $(date +'%d/%m/%Y a las %R')" > /home/restic/restic/raspberry.txt 2>&1
sudo -u restic restic -r sftp:vps2:/home/ubuntu/rpi4_bk/ backup \
--password-file="/home/restic/restic/pass" \
--tag raspberry --tag docker \
-v --exclude-file=/home/restic/restic/files_to_exclude.txt \
--files-from=/home/restic/restic/files_to_backup.txt >> /home/restic/restic/raspberry.txt 2>&1
sudo -u restic restic -r sftp:vps2:/home/ubuntu/rpi4_bk/ forget \
--password-file="/home/restic/restic/pass" \
--group-by host --keep-last 6 --prune >> /home/restic/restic/raspberry.txt 2>&1
sudo -u restic restic -r sftp:vps2:/home/ubuntu/rpi4_bk/ check \
--password-file="/home/restic/restic/pass" >> /home/restic/restic/raspberry.txt 2>&1
Once you've created the script, don't forget to give it execute permissions. From that point on, any authorized user (for example, your regular user using sudo) will be able to start the automatic backup simply by calling the script.
Schedule execution with cron on Linux and Android
To make copies automatically, the usual practice is to add a entry in crontab of the user you want to trigger the process. For example, if you want the user pi Run the script every Saturday at 1:05 AM; simply edit your crontab:
crontab -e
And add a line like this:
5 1 * * 6 bash /home/restic/restic/run_backup.sh
Cron will automatically run the script at the specified time without requiring any intervention. This way, you'll have regular and consistent backups without having to do it manually each time.
In Android environments, a similar approach can be achieved using Termux and the termux-services package, which provides cron support via cronie . The workflow would involve installing Termux, adding termux-services, enabling the services, and configuring a cron job that calls a Restic-based backup script, just as you would on a desktop Linux system, but with some adjustments to the paths and variables.
Restyc on Android and S3-type storage with MinIO
Restic isn't limited to the world of PCs or servers. You can also use it to protect your data on Android devices , which are essentially computers that handle personal and work information.
One option is to use a dedicated project called Restic Android, which uses termux/proot to run the Restic Linux binary within Android. This app allows you to manage S3, B2, or REST repositories, configure backup folders, schedule backups, and define cleanup policies, although the project is still in early development and may contain bugs.
Another, more flexible approach is to use Restic directly within Termux. This allows you to maintain your backup configuration in your dotfiles, sharing scripts between your desktop computer and the Android device with minor variations. This is very convenient if you already work with templates (for example, Jinja files) and tools like jinrender to generate scripts with the corresponding variables for each device.
In both cases, remote storage can be based on S3-compatible services. This is where MinIO comes in, an object server that replicates the S3 API and that you can self-host on your own server or even your PC . This way, you get all the advantages of the S3 model without paying for an external service or depending on third parties.
Obviously, this involves installing, configuring, and maintaining MinIO, but in many cases the cost is offset by the flexibility and complete control over your data. Combined with Restic, you have a system of encrypted and deduplicated backups in an object-based backend that you fully control , for both Linux and Android.
Basic operations: snapshots, restoration, and cleanup
In daily use of Restic, in addition to making and scheduling backups, there are three operations that should be very clear: listing snapshots, restoring data, and deleting old backups.
To see what copies you have stored, the snapshots command already mentioned shows you the complete inventory.
If at any point you want to compare two snapshots to see what changed between them, you can use restic diff Passing the IDs that interest you, which greatly helps in understanding the evolution of your data.
The restoration is done with the command restore, indicating the snapshot ID (or the keyword latest (if you want the most recent one) and the destination path. Restic doesn't restore to the original location by default, so you must specify a target directory where the content will be displayed:
restic restore latest -r /path/to/backup-repository --target /tmp/restore
If you only want to retrieve a specific directory, you can use additional options such as --include o --path to limit which part of the snapshot is restored, saving time and space when searching a small set of files.
Regarding cleaning, apart from the commands forget y pruneRestic allows you to define more elaborate rules such as "keep the last N copies, keep those from the last X days, weeks, or months, or don't delete those with certain tags." This gives you enough tools to design. fairly sophisticated retention strategies without complicating your life.
With Restic, you can set up a fast, secure, and easy-to-manage backup system on Linux (and other systems, including Android): install the binary, create an encrypted repository , define what to back up and what not to back up, automate with a script and cron, apply retention policies, and periodically verify data integrity. All of this leverages local backends, SSH, or cloud services like S3, with deduplication, strong encryption, and a simple restore workflow that lets you sleep soundly knowing your important data is well protected.
Table of Contents
- 1 What is Resti and why is it worthwhile in Linux?
- 2 Practical advantages of Restic for your backups
- 3 Installing Restic on Linux (and keeping it updated)
- 4 Create and protect the backup repository
- 5 Setting up a dedicated user and permissions in Linux
- 6 Remote access to the backup server via SSH
- 7 Define what is included and what is excluded in the copies
- 8 Perform a manual backup with Restic
- 9 Check that the copy is correct
- 10 Delete snapshots and retention policies
- 11 Automate backups with scripts and cron
- 12 Schedule execution with cron on Linux and Android
- 13 Restyc on Android and S3-type storage with MinIO
- 14 Basic operations: snapshots, restoration, and cleanup