Set up systemd service and timer for backups

This commit is contained in:
Râu Cao 2022-10-21 10:50:04 +02:00
parent 95941c830f
commit 61710aa4a4
4 changed files with 49 additions and 0 deletions

View File

@ -3,6 +3,11 @@
"normal": {
"knife_zero": {
"host": "10.1.1.167"
},
"kosmos_kvm": {
"backup": {
"schedule": "0/3:45"
}
}
},
"automatic": {

View File

@ -3,6 +3,11 @@
"normal": {
"knife_zero": {
"host": "10.1.1.147"
},
"kosmos_kvm": {
"backup": {
"schedule": "0/3:00"
}
}
},
"automatic": {

View File

@ -5,3 +5,6 @@ node.default["kosmos_kvm"]["host"]["qemu_base_image"] = {
"checksum" => "6db74917f85146569cb6ae89e1d163ac6d1e488a7f32bc74761ec6d1869c714f",
"path" => "/var/lib/libvirt/images/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm-#{ubuntu_server_cloud_image_release}.qcow2"
}
# A systemd.timer OnCalendar config value
node.default["kosmos_kvm"]["backup"]["schedule"] = "daily"

View File

@ -54,3 +54,39 @@ template "/root/backups/backup_all_vms.sh" do
mode '0750'
variables vm_domains: vm_domains
end
systemd_unit "backup-libvirt-guests.service" do
content({
Unit: {
Description: "Back up libvirt guest images and metadata",
Wants: "network.target"
},
Service: {
Type: "oneshot",
EnvironmentFile: "/root/.borg_credentials.env",
ExecStart: "/root/backups/backup_all_vms.sh",
SyslogIdentifier: "backup-libvirt-guests",
Restart: "no"
}
})
verify false
triggers_reload true
action [:create]
end
systemd_unit "backup-libvirt-guests.timer" do
content({
Unit: {
Description: "Back up libvirt guest images and metadata",
},
Timer: {
OnCalendar: node["kosmos_kvm"]["backup"]["schedule"]
},
Install: {
WantedBy: "timers.target"
}
})
verify false
triggers_reload true
action [:create, :enable, :start]
end