How to Back Up Ubuntu 20.04 with Rsync (Step-by-Step)
There are many ways to create a backup on Ubuntu, each with its own advantages. In a previous tutorial, we explored Bacula — a powerful yet complex tool suited for enterprise-level backup management. However, not every situation requires such complexity.
Creating regular backups is a critical part of any system maintenance strategy. Whether you're a casual user, a developer, or a system administrator, unexpected data loss can occur due to hardware failure, accidental deletion, malware, or even system upgrades gone wrong. Backups ensure that you can recover quickly without losing valuable files, configurations, or work.
In this tutorial, we'll focus on rsync — a simple yet highly effective command-line tool for creating backups. It's fast, efficient, and offers a wide range of options to suit different backup needs. You’ll learn how to use rsync to back up your data on Ubuntu 20.04, step by step.
Step 1 – Installing rsync
Ubuntu 20.04 already contains the rsync package installed. To check this and find out the version, use the command:
sudo rsync --version
If the package is not installed for some reason, use the command:
sudo apt install rsync
To launch rsync as a service in Ubuntu 20.04, create the /etc/rsyncd.conf file and copy /lib/systemd/system/rsync.service to /etc/systemd/system/rsync.service.
sudo nano /etc/rsyncd.conf # save and close it
sudo cp /lib/systemd/system/rsync.service /etc/systemd/system/rsync.service
Now restart the service.
sudo systemctl restart rsync
Step 2 – Configuring the data source server
First, add these lines to the rsync configuration file /etc/rsyncd.conf. Change the 'path' parameter to the path to the source files to back up. For ‘uid’ and ‘gid’, use the existing username and group with read permissions in the backup source folders.
sudo nano /etc/rsyncd.conf
# Global configuration of the rsync service
pid file = /var/run/rsyncd.pid
# Username and group for working with backups
uid = backup-user
gid = backup-user
# Don't allow to modify the source files
read only = yes
# Data source information
[data]
path = /path/to/backup
list = yes
auth users = backup-user
secrets file = /etc/rsyncd.passwd
The data in the ‘auth users’ parameter and the /etc/rsyncd.passwd file is used for authorization between rsync on different computers. Add a line there, like this:
sudo nano /etc/rsyncd.passwd
backup-user:test-pass
Change the permissions for the rsyncd.passwd file.
sudo chmod 0600 /etc/rsyncd.passwd
Restart the service to apply the changes.
sudo systemctl restart rsync
Step 3 – Running the backup
Create the /etc/rsyncd.passwd file on the receiving server where the backups will be stored. Enter the same password as on the source computer, but without the user name, set 600 permissions for it.
sudo nano /etc/rsyncd.passwd
test-pass # Save and close file
sudo chmod 0600 /etc/rsyncd.passwd
To perform a backup run the command:
rsync -a --password-file=/etc/rsyncd.passwd backup-user@source-server-ip::data /destination/path/$(date +%Y-%m-%d)/
For regular backups, just add the task to the end of the /etc/crontab file.
Conclusion
Rsync offers a flexible, reliable, and lightweight solution for backing up data on Ubuntu 20.04. Whether you're protecting personal files or managing server environments, rsync gives you control over what to back up, where to store it, and how often it runs — all with simple command-line tools. Unlike more complex systems like Bacula, rsync can be set up quickly and customized to fit both simple and advanced needs.
By following the steps in this tutorial, you've learned how to install and configure rsync, set up secure authentication between systems, and automate regular backups. Taking the time to implement a solid backup strategy now can save you hours — or even days — of recovery efforts later.
Don’t wait for data loss to remind you of the importance of backups. Set up rsync today and give yourself peace of mind knowing your critical files are safe.


