scripts

Random scripts
git clone git://git.margiolis.net/scripts.git
Log | Files | Refs | README | LICENSE

commit 96bb945ae6cf1597aa3ba65e9a47309cdd748ea1
parent a91ced62313a01f48f1ec169310c1731afec672c
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sun,  3 Apr 2022 23:19:31 +0300

make it work with datasets as well

Diffstat:
Mbackup | 12+++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/backup b/backup @@ -2,7 +2,7 @@ usage() { - echo "usage: ${0##*/} [-ir] <src> <dst>" 1>&2 + echo "usage: ${0##*/} [-ir] src[/set] dst[/set]" 1>&2 exit 1 } @@ -14,7 +14,7 @@ err() pool_exists() { - local foo=$(zpool list -o name | sed 1d | grep -x "${1}") + local foo=$(zfs list -o name | sed 1d | grep -x "${1}") test -z "${foo}" && err "pool ${1} does not exist" } @@ -24,6 +24,8 @@ last_snap() zfs list -t snapshot -o name "${1}" | cut -f2 -d'@' | tail -1 } +# Make appropriate checks before creating new snapshot. +# If the snapshot already exists, either renew it or exit. delete_existing_snap() { local pool=${1} @@ -60,14 +62,10 @@ src_last_snap=$(last_snap "${src_pool}") dst_last_snap=$(last_snap "${dst_pool}") nsnaps=$(zfs list -t snapshot -o name ${dst_pool} | sed 1d | wc -l) -# Make appropriate checks before creating new snapshot. -# If the snapshot already exists, either renew it or exit. delete_existing_snap "${src_pool}" "${src_last_snap}" zfs snapshot -r ${src_pool}@${new_snap} -# Overwrite dst snapshot if it already exists when the -r option is passed, -# otherwise, exit. Also make sure there are more than 1 snapshots before we -# delete anything. +# Make sure dst has more than 1 snapshots before we delete anything. test ${nsnaps} -le 1 || delete_existing_snap "${dst_pool}" "${dst_last_snap}" if [ ${f_incr} -eq 1 ]; then