News
Happy System Administrator Appreciation Day - to the true heroes of IT!
JH
Joe Harris
March 9 2025
Updated August 30 2025

How to Backup Files on Ubuntu 20.04 Using Rsync - Step-by-Step Guide

Backup Linux Ubuntu

Using another OS?

Select the desired version or distribution.

There are many ways to make a backup on Ubuntu. Recently, we looked at a powerful but complex tool – Bakula. Today we will learn how to make a backup using rsync.

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)/

Replace source-server-ip with the IP address of the first server, and ‘/destination/path/’ with the path for storing backups.

For regular backups, just add the task to the end of the /etc/crontab file.

Conclusion

Using Rsync for backups on Ubuntu 20.04 is an efficient and reliable solution for both personal and server environments. With minimal configuration, Rsync allows you to synchronize files between source and destination directories, maintain read-only permissions, and automate backups through cron jobs. By following the steps outlined in this guide, you can ensure your critical data is safely backed up, versioned by date, and ready for quick recovery in case of system failures or data loss.

FAQ

  • Q1: Is Rsync already installed on Ubuntu 20.04?
    Yes, Ubuntu 20.04 comes with Rsync pre-installed. You can verify by running sudo rsync --version. If it is not installed, you can add it using sudo apt install rsync.
  • Q2: Can Rsync perform automated backups?
    Absolutely. You can schedule recurring backups by adding Rsync commands to /etc/crontab or using cron jobs for automated execution.
  • Q3: How do I secure the Rsync password?
    Store your Rsync password in the /etc/rsyncd.passwd file and set strict permissions using chmod 0600 /etc/rsyncd.passwd to prevent unauthorized access.
  • Q4: Can I back up data over the network using Rsync?
    Yes. Rsync supports remote backups over SSH or the Rsync daemon, enabling secure transfer of files between servers.
  • Q5: What does the -a option do in Rsync?
    The -a (archive) option preserves file permissions, symbolic links, timestamps, and other metadata, ensuring an exact copy of the source files.
  • Q6: How can I organize backups by date?
    You can include $(date +%Y-%m-%d) in the destination path of the Rsync command to create daily folders automatically for organized backups.
  • Q7: Can I restrict write access to the source files during backup?
    Yes, by setting read only = yes in the /etc/rsyncd.conf file, you can ensure the backup process cannot modify the original files.
Vote:
5 out of 5
Аverage rating : 5
Rated by: 4
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.