]> xn--ix-yja.es Git - alex.git/commitdiff
Move dixie backup script to sys2, remove h2 backup
authoralex <alex@pdp7.net>
Sat, 21 Oct 2023 18:29:48 +0000 (20:29 +0200)
committeralex <alex@pdp7.net>
Sat, 21 Oct 2023 18:29:48 +0000 (20:29 +0200)
personal_infra/puppet/site/dixie.bcn.int.pdp7.net.pp

index 5453eb4c1e80f011d346fd54fcf86faa801be174..0d2c0c004a8c6e29eea7571ebbd2a0fd6381968c 100644 (file)
@@ -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',
+  }
 }