====== Backup using RSYNC ======
Now we create a little script to backup via RSYNC
nano /srv/backup/backup.sh
You will need to create the appropriate backup locations for the script to use.
#!/bin/bash
# =====================================================================
# Script to Rsync backup
#
# V1.00 2024-03-20 Initial Release (Scotty)
# =====================================================================
source_file="backup"
date=$(date +"%Y-%m-%d")
new_filename="${source_file%.*}_${date}.log"
rsync -azAXPH --stats --delete --exclude='/swap.img' --exclude='/srv/*' --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/' / /srv/backup/cronbackup/backup_root > /var/log/backup/$new_filename
rsync -azAXPH --stats --delete /srv/data/ /srv/backup/cronbackup/backup_data/ >> /var/log/backup/$new_filename
rsync -azAXPH --stats --delete /srv/media/ /srv/backup/cronbackup/backup_media/ >> /var/log/backup/$new_filename
# Send a mail the backup has run
mail -s "Backup Completed" mark@scottworld.net < /var/log/backup/$new_filename
You can now add a cron job to run the script.
crontab -e
Add the following lines
00 03 * * 7 /srv/backup/backup.sh
00 03 * * 3 /srv/backup/backup.sh
This will run a backup on Sunday morning and Wednesday Morning at 03:00 am