Compare commits
6 Commits
927bb63535
...
61710aa4a4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61710aa4a4 | ||
|
|
95941c830f | ||
|
|
a5b2eb5f97 | ||
|
|
374654f8fd
|
||
|
|
7051cc9da8 | ||
|
|
51163ca3a3
|
@@ -25,6 +25,9 @@ knife[:automatic_attribute_whitelist] = %w[
|
||||
cloud_v2
|
||||
chef_packages
|
||||
]
|
||||
|
||||
knife[:default_attribute_whitelist] = []
|
||||
knife[:normal_attribute_whitelist] = ['knife_zero','kosmos-ejabberd']
|
||||
knife[:normal_attribute_whitelist] = ['knife_zero', 'kosmos_kvm', 'kosmos-ejabberd']
|
||||
knife[:override_attribute_whitelist] = []
|
||||
|
||||
knife[:allowed_normal_attributes] = ['knife_zero', 'kosmos_kvm', 'kosmos-ejabberd']
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
"normal": {
|
||||
"knife_zero": {
|
||||
"host": "10.1.1.167"
|
||||
},
|
||||
"kosmos_kvm": {
|
||||
"backup": {
|
||||
"schedule": "0/3:45"
|
||||
}
|
||||
}
|
||||
},
|
||||
"automatic": {
|
||||
@@ -10,7 +15,7 @@
|
||||
"os": "linux",
|
||||
"os_version": "5.4.0-54-generic",
|
||||
"hostname": "draco",
|
||||
"ipaddress": "148.251.237.73",
|
||||
"ipaddress": "148.251.237.111",
|
||||
"roles": [
|
||||
|
||||
],
|
||||
@@ -50,12 +55,12 @@
|
||||
"cloud": null,
|
||||
"chef_packages": {
|
||||
"ohai": {
|
||||
"version": "15.9.1",
|
||||
"ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.9.1/lib/ohai"
|
||||
"version": "15.12.0",
|
||||
"ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai"
|
||||
},
|
||||
"chef": {
|
||||
"version": "15.11.8",
|
||||
"chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.11.8/lib"
|
||||
"version": "15.17.4",
|
||||
"chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.17.4/lib"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
"normal": {
|
||||
"knife_zero": {
|
||||
"host": "10.1.1.147"
|
||||
},
|
||||
"kosmos_kvm": {
|
||||
"backup": {
|
||||
"schedule": "0/3:00"
|
||||
}
|
||||
}
|
||||
},
|
||||
"automatic": {
|
||||
@@ -70,8 +75,8 @@
|
||||
"ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai"
|
||||
},
|
||||
"chef": {
|
||||
"version": "15.14.0",
|
||||
"chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib"
|
||||
"version": "15.17.4",
|
||||
"chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.17.4/lib"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -18,8 +18,7 @@ virsh snapshot-create-as --domain $1 \
|
||||
--disk-only \
|
||||
--diskspec vda,snapshot=external
|
||||
|
||||
borg create -v --stats \
|
||||
$REPOSITORY::$1_$(date +%F_%H-%M) \
|
||||
borg create -v $REPOSITORY::$1_$(date +%F_%H-%M) \
|
||||
/var/lib/libvirt/images/$1.qcow2 \
|
||||
/root/backups/vm_meta/$1.xml
|
||||
|
||||
|
||||
@@ -12,16 +12,24 @@ file "/root/.ssh/borg_rsa" do
|
||||
mode '0600'
|
||||
end
|
||||
|
||||
bash "Add borg environment variables for bash" do
|
||||
file "/root/.borg_credentials.env" do
|
||||
content <<-EOF
|
||||
BORG_RSH='ssh -i /root/.ssh/borg_rsa'
|
||||
BORG_PASSPHRASE=#{borg_credentials["passphrase"]}
|
||||
BORG_REPO='#{borg_credentials["repository"]}'
|
||||
EOF
|
||||
end
|
||||
|
||||
bash "Load borg credentials in console sessions" do
|
||||
code <<-EOF
|
||||
cat >>/root/.bashrc <<EOL
|
||||
|
||||
# GENERATED BY CHEF
|
||||
export BORG_RSH='ssh -i /root/.ssh/borg_rsa'
|
||||
export BORG_PASSPHRASE=#{borg_credentials["passphrase"]}
|
||||
export BORG_REPO='#{borg_credentials["repository"]}'
|
||||
set -o allexport
|
||||
source ~/.borg_credentials.env
|
||||
set +o allexport
|
||||
EOF
|
||||
not_if "grep -q BORG /root/.bashrc"
|
||||
not_if "grep -q borg_credentials /root/.bashrc"
|
||||
end
|
||||
|
||||
directory "/root/backups" do
|
||||
@@ -46,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
|
||||
|
||||
Reference in New Issue
Block a user