From 6f1ff73839963014088cd48d31dec338cd6b3ad5 Mon Sep 17 00:00:00 2001 From: David Marec Date: Fri, 14 Jul 2023 22:49:31 +0200 Subject: [PATCH] take a snapshot before upgrading --- portupgrade.sh | 11 ++++++++++- selfBackup.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 selfBackup.sh diff --git a/portupgrade.sh b/portupgrade.sh index b178cfd..1e29340 100755 --- a/portupgrade.sh +++ b/portupgrade.sh @@ -1,9 +1,15 @@ #!/bin/sh all_jails=`jls jid` + DO_CLEAN="" DO_DIST="" +do_snap() +{ + zfs snap -r zroot/JAILS/master@up || exit 0 +} + do_all_jails(){ echo '---------------------------------------' @@ -55,9 +61,12 @@ echo case "${yn}" in [Yy][eE][sS]|[yY]) - DO_DIST="clean -a" + DO_DIST="clean -a -y" ;; *) ;; esac + +zfs list -H -t snap -r zroot/JAILS/master@up || do_snap + do_all_jails diff --git a/selfBackup.sh b/selfBackup.sh new file mode 100755 index 0000000..18d5778 --- /dev/null +++ b/selfBackup.sh @@ -0,0 +1,28 @@ +#!/bin/sh +ZROOT_BASE="zroot" +SSH="/usr/bin/ssh" +ZFS="/sbin/zfs " +REMOTE="matarje" +REMOTE_USER="david" +REMOTE_KEY="~/.ssh/zfs" +REMOTE_POOL="breiz/BCK/master/popeye" +# ICLUDE="-o canmount=off" +XCLUDE="-x mountpoint -x canmount" + +# getting last snapshot id +# if one cannot trust the snap id one can use creation time + +${ZFS} list -H -t snap -r zroot/JAILS/master@up && zfs destroy -r zroot/JAILS/master@up + +for i in usr usr/home JAILS/master JAILS/master/php JAILS/master/git JAILS/master/d14 JAILS/master/epee JAILS/master/synapse JAILS/master/mariadb JAILS/master/next +do + +ZROOT="${ZROOT_BASE}/${i}" +ZLAST=`${ZFS} list -o name -Hp -t snap -d 1 ${ZROOT} | cut -d '@' -f 2 | sort | tail -1` +REMOTE_ZLAST=`${SSH} -i ${REMOTE_KEY} ${REMOTE_USER}@${REMOTE} ${ZFS} list -o name -Hp -t snap -d 1 ${REMOTE_POOL}/${i} | cut -d '@' -f 2 | sort | tail -1` + + +echo "sending incremental backup from " "${REMOTE_ZLAST} to ${ZLAST}" -- /${ZROOT} +# +${ZFS} send -L -e -c -i ${ZROOT}@${REMOTE_ZLAST} ${ZROOT}@${ZLAST} | ${SSH} -i ${REMOTE_KEY} ${REMOTE_USER}@${REMOTE} ${ZFS} recv -Fdu ${ICLUDE} ${XCLUDE} ${REMOTE_POOL} +done -- 2.47.0