Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables users to create encrypted, incremental backups of files and directories, ensuring that data is safely stored and can be restored in case of data loss, corruption, or accidental deletion. Restic supports a wide range of backend storage options, including local directories, remote servers via SFTP, and various cloud services such as Amazon S3 and Backblaze B2. With features like deduplication, snapshot management, and pruning, Restic minimizes storage usage while maintaining data integrity. Its ease of use and strong focus on security make it an excellent choice for both individual and enterprise-level backup solutions.
Backing up your server is essential to ensure data safety and recoverability in case of hardware failure, data corruption, or accidental deletions. Restic is an efficient, fast, secure backup program supporting various backend storage options. This guide will walk you through setting up and using Restic to back up your Ubuntu 24.04 server.
Before we begin, ensure you have the following:
sudo privileges.Restic is included in the default Ubuntu repositories. I will show you how to install restic from the Ubuntu repository (method 1) and how to get the latest binary by downloading it manually (method 2).
Update your package index:
sudo apt update Install Restic:
sudo apt install restic Download the latest Restic binary from the official GitHub releases page:
wget https://github.com/restic/restic/releases/download/v0.17.0/restic_0.17.0_linux_amd64.bz2 Decompress the file:
bzip2 -d restic_0.17.0_linux_amd64.bz2 Make the binary executable:
chmod +x restic_0.17.0_linux_amd64 Move the binary to /usr/local/bin for global usage:
sudo mv restic_0.17.0_linux_amd64 /usr/local/bin/restic Verify the installation:
restic version Restic requires a repository (a location where backups are stored). This repository can be local (a directory on the server) or remote (on another server or cloud storage).
Choose or create a directory where the backups will be stored. For example, use /backup/restic:
sudo mkdir -p /backup/restic Initialize the repository:
sudo restic init --repo /backup/restic You’ll be prompted to enter a password to secure the repository. Make sure to remember this password, as you’ll need it for all operations with this repository.
To back up to a remote server via SFTP:
Initialize the repository on the remote server:
restic -r sftp:user@hostname:/path/to/repo init Replace user, hostname, and /path/to/repo with appropriate values.
Enter the password when prompted.
Restic supports various cloud providers (e.g., Amazon S3, Backblaze B2, Google Cloud Storage). The configuration varies slightly depending on the provider. Refer to the Restic documentation for detailed instructions on setting up cloud storage as a repository.
Now that your repository is set up, you can create your first backup.
To back up a directory (e.g., /home/user/data):
sudo restic -r /backup/restic backup /home/user/data If you’re using a remote repository, use:
sudo restic -r sftp:user@hostname:/path/to/repo backup /home/user/data You can exclude specific files or directories from the backup using the --exclude option:
sudo restic -r /backup/restic backup /home/user/data --exclude /home/user/data/temp For multiple exclusions, use an exclude file:
sudo nano /home/user/exclude.txt /home/user/data/temp
/home/user/data/cache sudo restic -r /backup/restic backup /home/user/data --exclude-file /home/user/exclude.txt You can automate backups using cron jobs. Open the crontab editor:
sudo crontab -e Add a cron job to run daily at 2 AM:
0 2 * * * /usr/local/bin/restic -r /backup/restic backup /home/user/data >> /var/log/restic_backup.log 2>&1 Save and exit the editor.
This cron job will run the backup command daily at 2 AM and log output to /var/log/restic_backup.log.
It's crucial to verify your backups to ensure data integrity regularly.
sudo restic -r /backup/restic check For remote repositories:
sudo restic -r sftp:user@hostname:/path/to/repo check Restic makes it straightforward when you need to restore data.
To restore a directory to its original location:
sudo restic -r /backup/restic restore latest --target / To restore to a different location, specify the target directory:
sudo restic -r /backup/restic restore latest --target /restore/location You can browse available snapshots before restoring:
sudo restic -r /backup/restic snapshots To restore a specific snapshot:
sudo restic -r /backup/restic restore [snapshot_id] --target /restore/location Replace [snapshot_id] with the ID of the snapshot you want to restore.
Over time, your backup repository may grow in size. Restic provides options to prune old data and maintain the repository.
To remove old snapshots and optimize storage usage:
sudo restic -r /backup/restic forget --keep-last 5 --prune This command keeps the last 5 snapshots and removes others, followed by pruning unused data.
You can automate pruning with a cron job:
sudo crontab -e 0 3 * * 7 /usr/local/bin/restic -r /backup/restic forget --keep-last 5 --prune >> /var/log/restic_prune.log 2>&1 Restic is a powerful and flexible tool for backing up your Ubuntu 24.04 server. By following this guide, you can ensure that your data is safely backed up and can be restored easily in case of an emergency. Remember to regularly verify and prune your backups to maintain data integrity and optimize storage usage. With Restic's secure encryption and efficient data management, your backup strategy will be both robust and reliable.
Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…
ISPConfig is an open-source control panel that allows users to manage multiple servers from a…
As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…
Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…
phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…
In the IT world, it is important to keep a copy of your data as…