How to Use Restic Backup Software on Ubuntu 24.04
Restic is a fast, secure, and versatile backup software. Designed with simplicity and security in mind, Restic encrypts data by default, making it ideal for safeguarding files on a local or remote server. This guide will show you how to install, configure, and use Restic to create, verify, and restore backups on Ubuntu 24.04. The Restic installation on Ubuntu 24.04 will be consist of several steps below :
1. Install Restic on Ubuntu 24.04
2. Initialize a Backup Repository
3. Confirm the repository was initialized successfully by listing snapshots
4. Verify the Backup
5. Restoring from a Backup
6. Schedule Automatic Backups with Cron (Optional)
7. Additional Restic Commands
Prerequisites
To follow along with this guide, you will need:
- A machine running Ubuntu 24.04 with sudo privileges.
- Internet access to download and install Restic.
- An external or network storage location for backups (optional but recommended).
Step 1: Install Restic on Ubuntu 24.04
Start by updating your package list to ensure you’re installing the latest version:
$ sudo apt update
Install Restic using the package manager:
$ sudo apt install restic -y
Once installed, verify the installation by checking the version:
$ restic version
You should see the installed Restic version displayed, indicating a successful installation.
Step 2: Initialize a Backup Repository
Restic organizes backups in repositories. A repository can be a directory on your machine, an external drive, or a remote location.
1. Create a repository directory on your local system or mounted storage (e.g., /mnt/backup):
$ mkdir -p /mnt/backup
2. Initialize the repository in this directory:
$ restic init -r /mnt/backup
During initialization, you will be prompted to create a password for your repository. Note: Keep this password secure, as you’ll need it for future access.
3. Confirm the repository was initialized successfully by listing snapshots:
$ restic -r /mnt/backup snapshots
Since this is a new repository, there will be no snapshots listed.
Step 3: Perform Your First Backup
Let’s now perform a backup of the /home
directory.
1. Run the following command to back up /home:
$ restic -r /mnt/backup backup /home
Restic will process the directory and provide details about files being backed up. This may take some time, depending on the size of the directory.
2. To back up additional directories, simply specify them after the backup command:
$ restic -r /mnt/backup backup /etc /var
Step 4: Verify the Backup
To ensure the integrity of your backup, use Restic’s check
command:
$ restic -r /mnt/backup check
This command will validate the files in your backup repository and ensure there are no issues with the stored data.
Step 5: Restoring from a Backup
To restore files from your backup repository, follow these steps:
1. List all snapshots to find the one you want to restore:
$ restic -r /mnt/backup snapshots
2. Use the snapshot ID to restore a specific backup. Here’s an example of restoring a snapshot to a new location (/tmp/restore):
$ restic -r /mnt/backup restore <snapshot-id> --target /tmp/restore
Replace <snapshot-id> with the actual ID of the snapshot you wish to restore.
3. Confirm the files have been restored to the target directory:
$ ls /tmp/restore
Step 6: Schedule Automatic Backups with Cron (Optional)
To ensure regular backups, you can schedule Restic using cron jobs.
1. Open the cron editor:
$ crontab -e
2. Add the following line to schedule a daily backup of /home at midnight:
0 0 * * * restic -r /mnt/backup backup /home --quiet
3. Save and exit the editor. Restic will now back up the /home directory daily at midnight.
Step 7: Additional Restic Commands
To support the use of Restic more comfortable, the application also can be used by any option to as shown below :
1. Forget Old Snapshots: To remove older backups and manage storage space, use the forget command:
$ restic -r /mnt/backup forget --keep-daily 7 --keep-weekly 4 --prune
This command keeps the last 7 daily and 4 weekly snapshots, deleting others and freeing up space.
2. List Files in a Snapshot: To see files in a specific snapshot:
$ restic -r /mnt/backup ls <snapshot-id>
Conclusion
You have successfully installed and configured Restic on Ubuntu 24.04, created backups, and learned to restore and manage snapshots. With Restic’s encryption and flexibility, you can securely back up your data on local and remote storage, ensuring your data is protected. The Restic official website can be found on https://restic.net/.