elfsightSkip to content
Creating Automated Backups with cron and rsync in

Creating Automated Backups with cron and rsync in Linux

Creating automated backups with cron and rsync in Linux. By combining the rsync command with the cron system, you can easily automate backups of essential files in Linux.

This method is flexible, efficient and suitable for any server or workstation that requires data protection.

Periodic implementation of these backups is a good practice that contributes to the security and stability of your system.

Creating automated backups

Maintaining a backup copy of essential files is vital for any system.

In Linux, combining the rsync command with the cron scheduler allows backup automation in an efficient and secure way.

This article presents the necessary steps to configure an automated backup system using these two tools.

What is rsync?

rsync is a fast and versatile tool for synchronizing and transferring files between directories or computers.

The main advantage is that rsync transfers only the changes, thus saving time and bandwidth.

Installing rsync

On most Linux distributions, rsync is pre-installed. If it’s not available, you can install it with the following commands:

sudo apt install rsync       # Ubuntu/Debian
sudo yum install rsync       # CentOS/RHEL

Basic rsync command

rsync -avh /source/ /destination/

Explanation:

  • -a – archive mode (preserves permissions, timestamps, symbolic links)
  • -v – verbose (shows progress)
  • -h – human-readable (easy-to-read display)

What is cron?

cron is a Linux daemon that executes commands at regular intervals, based on a file called crontab.

It is used for automating recurring tasks such as backups, updates or reporting.

Editing the crontab file

To create a scheduled task, use the command:

crontab -e

This will open the cron editor for the current user.

Example of automated backup with rsync and cron

Let’s assume you want to backup the /home/user/documents directory to /mnt/backup/documents every day at 2:00 AM.

Step 1: Testing the rsync command

rsync -avh /home/user/documents/ /mnt/backup/documents/

Step 2: Adding to crontab

0 2 * * * rsync -avh /home/user/documents/ /mnt/backup/documents/ >> /var/log/backup.log 2>&1

Cron explanation:

  • 0 2 * * * – at 2:00 AM every day
  • >> – redirects output to the log file
  • 2>&1 – also redirects errors to the same file

Recommendations for secure backups

Example of backup to remote server via SSH

rsync -avh -e ssh /home/user/documents/ user@192.168.1.100:/mnt/backup/documents/

Make sure that SSH authentication works (SSH keys without password, if running automatically from cron).

Monitoring backups

It is recommended to send a completion or error report via email or implement an automated logging and alerting solution.

You can analyze the /var/log/backup.log file to verify if the backup was performed correctly.

Special SEO Services – We offer specialized SEO optimization and search engine marketing services. Contact us now!

Previous post
Next article

Comments (0)

Leave a Reply

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

Back To Top
ROEN