backup/rsync_backups/rsync_backup

39 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

2024-08-25 18:56:46 +00:00
#!/bin/bash
2024-08-28 00:29:14 +00:00
if [ $# -ne 2 ]; then
echo "Usage: $0 <file lists> <backup_location>"
2024-08-25 18:56:46 +00:00
exit 1
fi
2024-08-28 00:29:14 +00:00
echo "backing up the following folders: ${1}/backup.txt"
2024-08-25 18:56:46 +00:00
echo -e "\e[32m-------------------------------------------"
2024-08-28 00:29:14 +00:00
cat "${1}/backup.txt"
2024-08-25 18:56:46 +00:00
2024-08-28 00:29:14 +00:00
echo -e "\e[0mexclude the following folders: ${1}/exclude.txt"
2024-08-25 18:56:46 +00:00
echo -e "\e[32m-------------------------------------------"
2024-08-28 00:29:14 +00:00
cat "${1}/exclude.txt"
2024-08-25 18:56:46 +00:00
2024-08-28 00:29:14 +00:00
mkdir -p $2
2024-08-25 18:56:46 +00:00
echo ""
echo -e "\e[0mStarting Backup"
2024-08-28 00:29:14 +00:00
rsync -rptgpXh --delete-excluded --delete-before --progress --stats --exclude-from="${1}/exclude.txt" --files-from="${1}/backup.txt" / $2 > /tmp/backup_data_tmp 2>&1
2024-08-25 18:56:46 +00:00
if [ $? -eq 0 ]; then
2024-08-28 00:29:14 +00:00
curl -H "Title: Backup: $(hostname)" -d "The backup on $(hostname) finished successfully. $(tail -n 17 /tmp/backup_data_tmp)" https://ntfy.locker98.com/camera_h9CQ0
2024-08-25 18:56:46 +00:00
else
2024-08-28 00:29:14 +00:00
curl -H "Title: Backup: $(hostname)" -H "Priority: urgent" -H "Tags: warning" -d "The backup on $(hostname) failed. $(tail -n 17 /tmp/backup_data_tmp)" https://ntfy.locker98.com/camera_h9CQ0
2024-08-25 18:56:46 +00:00
fi
2024-08-28 00:29:14 +00:00
#rm /tmp/backup_data_tmp
2024-08-25 18:56:46 +00:00
echo ""
echo -e "\e[0mBackup Done"