2024-04-23, 01:42 AM
I had some hardware failure last summer and was able to restore from the backup made with this script. No corruption.
It reads in a text file that has a source directory to backup and a destination of where to place the backup. If you delete or change a file in the source directory it will delete it from the backup directory (the --delete option).
Excluding /var/lib/docker is important because it only contains temporary data and takes up a lot of space if you don't exclude it.
An example of the text file specifying what to backup. The colon separates the source (left) with the destination (right)
In /etc/cron.d I created a text file that contains the cronjob schedule. You can also put this in root's crontab.
This runs the backup script nightly at 3am. Every Monday at 1am it nulls the backup log file.
Code:
#!/bin/bash
BACKUP_LIST=/root/backup_list.txt
while read list ; do
source=$(echo $list | awk -F ':' '{print $1}')
dest=$(echo $list | awk -F ':' '{print $2}')
rsync -a -r -p --progress --exclude /var/lib/docker "$source" "$dest" --delete >> /root/backup.log
done < $BACKUP_LIST
It reads in a text file that has a source directory to backup and a destination of where to place the backup. If you delete or change a file in the source directory it will delete it from the backup directory (the --delete option).
Excluding /var/lib/docker is important because it only contains temporary data and takes up a lot of space if you don't exclude it.
An example of the text file specifying what to backup. The colon separates the source (left) with the destination (right)
Code:
/home:/media/extended/Backups/
/etc:/media/extended/Backups/
/var:/media/extended/Backups/
/media/storage:/media/extended/Backups/media/
/media/storage/Pictures:/media/extended/Backups/
/docker:/media/extended/Backups/
In /etc/cron.d I created a text file that contains the cronjob schedule. You can also put this in root's crontab.
Code:
0 3 * * * root /root/backup.sh
0 1 * * mon root cat /dev/null > /root/backup.log
This runs the backup script nightly at 3am. Every Monday at 1am it nulls the backup log file.