Follow
Ubuntu Linux

How to Backup and Restore Files with Rsnapshot on Ubuntu

Richard
Written by
Richard
Dec 23, 2024 Updated Mar 20, 2026 5 min read
How to Backup and Restore Files with Rsnapshot on Ubuntu
How to Backup and Restore Files with Rsnapshot on Ubuntu

You backup and restore files on Ubuntu using the Rsnapshot utility.

Rsnapshot is a powerful filesystem snapshot utility that leverages rsync and hard links for efficient, incremental backups. It saves disk space by only storing changed files, allowing you to create local or remote backups easily.

You configure Rsnapshot using the `/etc/rsnapshot.conf` file. This central configuration lets you specify exactly what you want to back up, when, and where, making automated backups a breeze.

Regularly backing up your important files protects you from data loss due to accidental deletion or hardware failures. Rsnapshot simplifies this process, ensuring you can restore your data quickly when needed.

⚡ Quick Answer

Install rsnapshot using ‘sudo apt install rsnapshot’. Configure backups by editing /etc/rsnapshot.conf, specifying snapshot locations, retention intervals, and directories to back up. Schedule backups using cron jobs in /etc/cron.d/rsnapshot.

Install rsnapshot

Rsnapshot is included in the default Ubuntu repository, so installation is quite manageable. To install it, run the command below.

🐧Bash / Shell
sudo apt update
sudo apt install rsnapshot

After installation, you can check Rsnapshot’s binary location and version on Ubuntu by running this command:

💻Code
which rsnapshot
rsnapshot --version

Configure SSH authentication for remote system

If you’re backing up to or from a remote system, make sure SSH authentication is set up for the target systems.

You can use the ssh-keygen -t ed25519 command below to generate your SSH keypair. Then, use ssh-copy-id to copy the public key to the remote server.

💻Code
ssh-keygen -t ed25519
ssh-copy-id username@remote_server_name

Replace the username and remote_server_name with your actual username and system names.

For more on setting up SSH authentication, check out the post below.

How to set up SSH key based authentication login on Ubuntu

Configure rsnapshot

Once you’ve set up the remote system, you’ll configure Rsnapshot settings. This lets you select files to back up, set the interval, and more.

Before you make changes, back up the original configuration file.

🐧Bash / Shell
sudo cp /etc/rsnapshot.conf /etc/rsnapshot.conf.orig

Then, open the file and make your adjustments.

🐧Bash / Shell
sudo nano /etc/rsnapshot.conf

Choose where to store your snapshots.

💻Code
# All snapshots will be stored under this root directory.
#
snapshot_root /var/cache/rsnapshot/

Make sure these lines aren’t commented out; they enable remote backups.

💻Code
# rsync must be enabled for anything to work. This is the only command that
# must be enabled.
#
cmd_rsync /usr/bin/rsync

# Uncomment this to enable remote ssh backups over rsync.
#
cmd_ssh /usr/bin/ssh

You can also change how often backups occur.

💻Code
#########################################
# BACKUP LEVELS / INTERVALS #
# Must be unique and in ascending order #
# e.g. alpha, beta, gamma, etc. #
#########################################

retain daily 6
retain weekly 7
retain monthly 4

#retain delta 3

SSH normally uses port 22, but you can specify a custom port here.

💻Code
# ssh has no args passed by default, but you can specify some here.
#
ssh_args -p 22

The backup section is where you’ll tell Rsnapshot what to back up and where. The highlighted lines show how to back up a remote server and specify a local path.

Remember to replace username and remote_server_name with your actual system details.

💻Code
###############################
### BACKUP POINTS / SCRIPTS ###
###############################

# LOCALHOST
backup /home/ localhost/
backup /etc/ localhost/
backup /usr/local/ localhost/

backup username@remote_server_name:/etc/ local_server_name
backup username@remote_server_name:/www/data/ local_server_name

#backup /var/log/rsnapshot localhost/
#backup /etc/passwd localhost/
#backup /home/foo/My Documents/ localhost/
#backup /foo/bar/ localhost/ one_fs=1,rsync_short_args=-urltvpog
#backup_script /usr/local/bin/backup_pgsql.sh localhost/postgres/
# You must set linux_lvm_* parameters below before using lvm snapshots
#backup lvm://vg0/xen-home/ lvm-vg0/xen-home/

Once you’re done, save your changes and exit.

Automatic backup with Cron

After saving your configuration changes, open the Rsnapshot cron file to set up automatic backups.

🐧Bash / Shell
sudo nano /etc/cron.d/rsnapshot

Set up the backup settings you defined in the `rsnapshot.conf` file.

💻Code
# This is a sample cron file for rsnapshot.
# The values used correspond to the examples in /etc/rsnapshot.conf.
# There you can also set the backup points and many other things.
#
# To activate this cron file you have to uncomment the lines below.
# Feel free to adapt it to your needs.

0 0 * * * root /usr/bin/rsnapshot daily
0 0 * * 0 root /usr/bin/rsnapshot weekly
0 0 1 * * root /usr/bin/rsnapshot monthly

Save the file and exit.

For help setting up a cron task, check out the post below.

How to run cron jobs on Ubuntu

To restore your data, copy files from the snapshots location you defined in the Rsnapshot file.

That should do it!

Conclusion:

Backing up and restoring files with Rsnapshot on Ubuntu is an efficient and effective way to safeguard your data. Here are the key takeaways:

  • Automated Backups: Rsnapshot allows for easy scheduling of automated backups, ensuring your data is regularly protected without manual intervention.
  • Incremental Backups: By utilizing hard links, rsnapshot can perform incremental backups, saving both time and storage space.
  • Remote Backups: The tool can back up files to and from remote systems, enhancing flexibility and security for critical data.
  • Simple Configuration: With its straightforward configuration file, users can easily manage backup settings, including frequency and directories to back up.
  • Ease of Restoration: Restoring data from snapshots is a simple process, making recovery quick and efficient in case of data loss.

Incorporating Rsnapshot into your data management routine significantly enhances data safety and reliability.

Does timeshift work with Ubuntu?

A failed kernel update or broken package transaction is much easier to undo when you already have system snapshots. You can install Timeshift on Ubuntu from the default repositories, then roll system files back with RSYNC or BTRFS snapshots without hunting for a separate download.

What is rsnapshot?

Rsnapshot is an rsync-based filesystem snapshot utility. It can take incremental backups of local and remote filesystems for any number of machines. Rsnapshot makes extensive use of hard links, so disk space is only used when absolutely necessary.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

Secure SSH Access on Ubuntu with Google Authenticator
Ubuntu Linux Secure SSH Access on Ubuntu with Google Authenticator
How to install Homebrew on Ubuntu 24.04
Ubuntu Linux How to install Homebrew on Ubuntu 24.04
How to Allow Remote Access to MariaDB in Ubuntu Linux
Ubuntu Linux How to Allow Remote Access to MariaDB in Ubuntu Linux
How to Install WordPress on Google Cloud Server
CMS How to Install WordPress on Google Cloud Server

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *