Simple Backups with rsync
04 May 2024Introduction
Rsync is a powerful tool often utilized for its proficiency in file synchronization and transfer. Widely adopted in various computing environments, rsync excels in efficiently mirroring data across multiple platforms and minimizing data transfer by sending only changes in files. This utility is not only pivotal for maintaining backups but also ensures that the copies are consistent and up-to-date.
Today’s article is designed to guide you through the steps of setting up a basic yet effective backup system using rsync. By the end of this guide, you’ll have the knowledge to implement a reliable backup solution that can be customized to fit your specific needs.
Daily
The daily backup captures all of the changes for the day, giving you a backup with the fastest cadence.
Using whoami
and hostname
we can generalise this script so that you can reuse it between all of your machines.
The rsync-homedir-excludes.txt
file allows you to define files that you’re not interested in backing up.
The switches that we’re sending into rsync
are quite significant:
-a
putsrsync
into archive mode, preserving file structures, and links-A
preserves the ACLs so all of our permissions are preserved-X
any extra attributes that are stored by your file system will be preserved--delete
will delete files in the destination that are no longer present in the source, making the backup a true mirror
Weekly
The weekly backup is very similar to the daily backup. It’ll target different folders, and will have a different execution cadence.
There isn’t much difference here. Just writing to the /weekly
folder.
Monthly
The longest cadence that we have is a monthly process which will archive the current state into an archive, and date the file for later use potentially.
Using tar
this script builds a full archive, and then sends that off to the backup server.
Scheduling
Finally, we need to setup these scripts to execute automatically for us. For this, we’ll use cron
.
Here’s an example crontab scheduling these scripts: