Created
March 19, 2024 20:29
-
-
Save Gelob/500ce48d9989c60ae6c31824003f7cca to your computer and use it in GitHub Desktop.
libvirt-backup script slightly modified for Slack notifications. Modified from an original script created by @cpcwood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Slightly modified from https://cpcwood.com/code-snippets/22-backup-libvirt-domains-using-virtnbdbackup | |
virtnbdbackup_path=/bin/virtnbdbackup | |
backup_base_dir=/mnt/backups | |
remove_backups_older_than_months=3 | |
domains_to_backup=( | |
"domain-a" | |
"domain-b" | |
) | |
for domain in "${domains_to_backup[@]}"; do | |
echo "[$(date +"%T")] Backing up $domain" | |
backup_dir="$backup_base_dir/$domain/$(date +"%Y-%m")" | |
echo "[$(date +"%T")] Creating backup directory $backup_dir" | |
mkdir -p "$backup_dir" | |
echo "[$(date +"%T")] Creating backup of $domain" | |
if "$virtnbdbackup_path" -l auto -d "$domain" -o "$backup_dir" ; then | |
echo "[$(date +"%T")] Backup of $domain completed successfully" | |
else | |
echo "[$(date +"%T")] Backup of $domain failed" | |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Backup of '$domain' failed"}' <slack webhook here> | |
fi | |
echo "[$(date +"%T")] Removing backups older than $remove_backups_older_than_months months" | |
old_backup_dir="${backup_base_dir:?}/${domain:?}/$(date --date="$remove_backups_older_than_months months ago" +%Y-%m)" | |
echo "[$(date +"%T")] Removing $old_backup_dir is it exists" | |
if [[ -d "$old_backup_dir" ]]; then | |
rm -rf "$old_backup_dir" | |
fi | |
done | |
echo "[$(date +"%T")] Backups completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment