Merge pull request 'Prune VM backups after every run' (#447) from feature/439-prune_backups into master

Reviewed-on: #447
This commit is contained in:
Greg 2022-11-05 20:42:31 +00:00
commit 5a94050555
4 changed files with 21 additions and 2 deletions

View File

@ -6,7 +6,7 @@
},
"kosmos_kvm": {
"backup": {
"schedule": "0/3:45"
"schedule": "0/3:55"
}
}
},
@ -15,7 +15,7 @@
"os": "linux",
"os_version": "5.4.0-54-generic",
"hostname": "draco",
"ipaddress": "148.251.237.111",
"ipaddress": "148.251.237.73",
"roles": [
],

View File

@ -0,0 +1,11 @@
#!/bin/bash
# GENERATED BY CHEF
# DO NOT EDIT
set -e
echo "Pruning backups of VM: $1"
borg prune --prefix $1 \
--keep-hourly 4 --keep-daily 4 --keep-weekly 1 \
--keep-monthly 1 --keep-yearly 1 \
--stats $BORG_REPO

View File

@ -45,6 +45,11 @@ cookbook_file "/root/backups/backup_vm.sh" do
mode "0750"
end
cookbook_file "/root/backups/prune_vm_backups.sh" do
source "prune_vm_backups.sh"
mode "0750"
end
# Search all guests and filter by presence on current host
vm_domains = search(:node, "role:kvm_guest").map{|n| n["hostname"] } \
& `virsh list --name`.strip.chomp.split("\n")

View File

@ -8,4 +8,7 @@ echo "Backing up all VMs with kvm_guest chef role..."
for domain in <%= @vm_domains.join(" ") %>
do
/root/backups/backup_vm.sh $domain
/root/backups/prune_vm_backups.sh $domain
# TODO Enable this when upgrading borg to 1.2
# borg compact $BORG_REPO
done