Linux·28 questions

How to set up automated data backup in Linux using rsync and systemd timers?

Answer

Creating reliable backups is critically important for any Linux server or workstation, and the rsync utility is the gold standard for efficiently copying and synchronizing files locally or over a network. Thanks to its delta-transfer algorithm, rsync transfers only the modified parts of files, which significantly saves bandwidth and execution time for backup tasks.

To automatically run backup scripts instead of the traditional cron scheduler, it is increasingly recommended to use systemd timers, which offer more flexible logging, dependency management, and precise event scheduling. Creating such a timer consists of two steps: writing a service file describing the command to be executed and a timer file with the execution schedule.

The service file is created in the system directory or user systemd folder and contains a service section specifying the path to the executable rsync script. The timer file has the same name but with the .timer extension, and defines the exact start time, such as daily execution or running at a specific interval after system boot.

After creating the files, you need to reload the systemd daemon, enable the timer to start on boot, and start it using the service management command. You can check the timer status and verify its correct operation using the log viewing utility, which will show the entire execution history and any script errors.

Was this answer helpful?

More questions in this topic

Related questions from other topics