How to Use Rsync for Backup Creation on CentOS 8
In this tutorial, we will use Rsync to create a backup on CentOS 8. Backups will be sent to the second server and stored there. So we need 2 working and configured CentOS 8 servers. So we need 2 working and configured CentOS 8 servers. We will cover the installation of Rsync, setup of SSH keys for secure communication, and how to automate the backup process using cron jobs for regular data synchronization.
Installing Rsync packages
Let's check if the necessary Rsync packages are installed and install them if not.
dnf install rsync rsync-daemonStart the Rsync daemon and enable its automatic starting.
systemctl enable --now rsyncdCheck if auto start is enabled and working.
systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-12-19 13:18:16 UTC; 6s ago
...Check if the Rsync service is listening on the network port.
netstat -tulpn | grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 55746/rsync
tcp6 0 0 :::873 :::* LISTEN 55746/rsyncConfiguring the backup source server
Open the configuration file:
nano /etc/rsyncd.confInsert following lines in it:
# Rsync daemon global config
pid file = /var/run/rsyncd.pid
# User name and group for reading source files
uid = rsync-user
gid = rsync-user
# Do not allow to modify the source files
read only = yes
# Data Source Configuration
[data]
path = /home/user
list = yes
auth users = rsync-user
secrets file = /etc/secret.passwdCreate a file with credentials for authorization on this machine.
nano /etc/secret.passwdEnter username and password in it.
rsync-user:rsync-passChange the file permissions to read-only by the root user.
chmod 0600 /etc/secret.passwdRestart the Rsync daemon.
systemctl restart rsyncdYou also need to create the user that was specified in the configuration and file with credentials.
useradd rsync-userСonfiguring the receiving Rsync backup server
Create a file for the password.
nano /etc/secret.passwdEnter the password for the Rsync user on the source server.
rsync-passChange its permissions here as well.
chmod 0600 /etc/secret.passwdRunning a backup
Create a folder for backup.
mkdir /opt/backupThe following command will start the backup. Replace source-server-ip with the source server's IP address.
rsync -a --password-file=/etc/secret.passwd rsync-user@source-server-ip::data /opt/backup/$(date +%Y-%m-%d)/
700
300
700
300
700
300