scripts

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

commit 5a66b1b1dc5a67ce39bff08b2da87d85c12469ef
parent 47aa5aea6b7465b5de6f334491bf64b270b2b6ac
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sun,  3 Apr 2022 22:07:31 +0300

wrote zfs backup script, pretty cool

Diffstat:
MMakefile | 1+
Abackup | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Mse | 2+-
3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -2,6 +2,7 @@ SCRIPTS = ausplit \ autocomp \ + backup \ batnfy \ doccomp \ docprev \ diff --git a/backup b/backup @@ -0,0 +1,49 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} [-i] <from> <to>" 1>&2 + exit 1 +} + +drive_exists() +{ + local foo=$(zpool list | sed 1d | awk '{print $1}' | grep -x "${1}") + test -z "${foo}" && echo "${0##*/}: drive ${1} does not exist" && exit 1 +} + +f_incr=0 + +while getopts i arg; do +case "${arg}" in + i) f_incr=1 ;; + *) usage ;; +esac +done +shift $((OPTIND - 1)) + +test ${#} -ne 2 && usage + +from_drv="${1}" +to_drv="${2}" + +drive_exists "${from_drv}" +drive_exists "${to_drv}" + +new_snap="$(date +%Y%m%d)" +last_snap="$(zfs list -t snapshot -o name ${to_drv} | cut -f2 -d'@' | tail -1)" +nsnaps=$(zfs list -t snapshot -o name ${to_drv} | sed 1d | wc -l) + +# make sure we don't have a snapshot already +# also don't delete in case there's only one snap, otherwise we'll lose it all +if [ ! ${nsnaps} -le 1 ] && [ "${last_snap}" = "${new_snap}" ]; then + zfs destroy -r ${to_drv}@${new_snap} +fi +# create new snapshot in case we had made one already today +zfs destroy -r ${from_drv}@${new_snap} +zfs snapshot -r ${from_drv}@${new_snap} +if [ ${f_incr} -eq 1 ]; then + zfs send -RI ${from_drv}@${last_snap} ${from_drv}@${new_snap} | pv | zfs recv -Fu ${to_drv} +else + zfs send -R ${from_drv}@${new_snap} | pv | zfs recv -Fu ${to_drv} +fi diff --git a/se b/se @@ -1,3 +1,3 @@ #!/bin/sh -du -a /home/christos/src/scripts | awk '{print $2}' | fzf | xargs -r ${EDITOR} +find /home/christos/src/scripts | grep -v '\.git' | fzf | xargs -r ${EDITOR}