How to Backup and Restore Files with Rsnapshot on Ubuntu
Rsnapshot is a free backup tool for Ubuntu that keeps your files safe by making smart copies on your local computer or a remote server. It uses hard links (directory entries that point to the same file on disk) and a tool called rsync to save space by storing only the files you change.
You set up the whole system by editing the /etc/rsnapshot.conf file to pick your folders and schedules. Regular backups protect your important documents from hard drive crashes and accidental deletions.
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
To install rsnapshot on Ubuntu, open your terminal and run the package manager command sudo apt install rsnapshot. Because the backup tool is included in the default Ubuntu software repositories, you do not need to add any outside package sources. After the installation finishes, you can check that the software is ready to use by running rsnapshot –version to view your current version number.
After installation, running the command `rsnapshot –version` will display Rsnapshot’s binary location and version on Ubuntu. This command verifies that the software installed correctly and is ready for use, showing you have version 1.4.4 or later.
which rsnapshot
rsnapshot --version
Configure SSH authentication for remote system
To configure SSH authentication for remote system backups with rsnapshot on Ubuntu, you need to set up key-based logins so your computer can connect to remote servers without asking for a password. Run the ssh-keygen command to create your cryptographic credentials, and then copy the public key to your destination host. This step allows your automated backups to run smoothly over the network without stopping for manual password prompts.
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.
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.
Configure rsnapshot
To configure rsnapshot for your Ubuntu file backups, you need to edit the main settings file to set your source folders and destination directories. Always back up your original settings first by running sudo cp /etc/rsnapshot.conf /etc/rsnapshot.conf.orig, and then open the file using sudo nano /etc/rsnapshot.conf. This file dictates where your data comes from and where the backup archives go.
Before making changes, back up the original configuration file.
sudo cp /etc/rsnapshot.conf /etc/rsnapshot.conf.orig
Then, open the file and make your adjustments.
sudo nano /etc/rsnapshot.conf
Choose where to store your snapshots.
# All snapshots will be stored under this root directory.
#
snapshot_root /var/cache/rsnapshot/
# 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.
#########################################
# 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.
# 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 demonstrate how to back up a remote server and specify a local path.
###############################
### 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
To set up an automatic backup with Cron for rsnapshot on Ubuntu, create a scheduled task file by running sudo nano /etc/cron.d/rsnapshot in your terminal. This scheduling tool runs your backup routines automatically in the background based on the rules you defined in your main configuration file, which means you do not have to start your backups by hand every time.
sudo nano /etc/cron.d/rsnapshot
Set up the backup settings you defined in the `rsnapshot.conf` file.
# 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 completes the setup process.
Backing up and restoring files with Rsnapshot on Ubuntu provides an efficient method for safeguarding critical data. Review these core operational points:
- 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 file safety and system reliability.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!