aboutsummaryrefslogtreecommitdiff
path: root/personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2023-10-21 20:29:48 +0200
committeralex <alex@pdp7.net>2023-10-21 20:29:48 +0200
commit353573748f0133759eff603d2bc0614a7db8f51a (patch)
treedb8d6e5cabedde0be9a506d5038fa8c45d957578 /personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp
parente03e19a3455ceeaac8d0bb74d9e1658ce7e1e8f2 (diff)
Move dixie backup script to sys2, remove h2 backup
Diffstat (limited to 'personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp')
-rw-r--r--personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp54
1 files changed, 54 insertions, 0 deletions
diff --git a/personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp b/personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp
index 5453eb4c..0d2c0c00 100644
--- a/personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp
+++ b/personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp
@@ -12,4 +12,58 @@ dhcp-option=121,10.0.0.0/8,192.168.76.2
class {'backups':
sanoid_config => "",
}
+
+ file {'/usr/local/sbin/zfs_receive_h2':
+ content => @(EOT)
+ #!/bin/bash
+
+ set -ue
+
+ run_backups_remote() {
+ host=$1
+ shift
+ sudo -u backups sh -c "export KRB5CCNAME=KEYRING:persistent:1284000004 && kinit -k -t /home/backups/.keytab backups && ssh $host $*"
+ }
+
+ get_last_remote_snapshot() {
+ host=$1
+ fs=$2
+ run_backups_remote $host /sbin/zfs list -H -t snapshot $fs | tail -1 | cut -f 1 | cut -d @ -f 2
+ }
+
+ get_last_local_snapshot() {
+ zfs list -H -t snapshot $1 | tail -1 | cut -f 1 | cut -d @ -f 2
+ }
+
+ replicate() {
+ host=$1
+ remote=$2
+ local=$3
+
+ last_local=$(get_last_local_snapshot $local)
+ last_remote=$(get_last_remote_snapshot $host $remote)
+
+ if test $last_local != $last_remote ; then
+ run_backups_remote $host /sbin/zfs send -w -i @$last_local $remote@$last_remote | zfs receive $local
+ fi
+ }
+
+ replicate case.ces.int.pdp7.net rpool/user/backed/cesar cesar_hdd_red_2/cesar
+ replicate case.ces.int.pdp7.net rpool/user/backed/filer cesar_hdd_red_2/filer
+
+ sudo -u backups /usr/sbin/syncoid --no-privilege-elevation --no-sync-snap backups@h1.pdp7.net:rpool/data/subvol-204-disk-1 rpool/user/backed/pg-h1-int-pg --quiet
+ sudo -u backups /usr/sbin/syncoid --no-privilege-elevation --no-sync-snap backups@h1.pdp7.net:rpool/data/subvol-208-disk-1 rpool/user/backed/nextcloud_new --quiet
+ sudo -u backups /usr/sbin/syncoid --no-privilege-elevation --no-sync-snap backups@h1.pdp7.net:rpool/data/subvol-210-disk-1 rpool/user/backed/bitwarden --quiet
+ sudo -u backups /usr/sbin/syncoid --no-privilege-elevation --no-sync-snap backups@h1.pdp7.net:rpool/data/subvol-211-disk-1 rpool/user/backed/gitolite --quiet'
+ | EOT
+ ,
+ owner => root,
+ group => root,
+ mode => '744',
+ }
+
+ file {'/etc/cron.hourly/zfs_receive_h2':
+ ensure => link,
+ target => '/usr/local/sbin/zfs_receive_h2',
+ }
}