Created
March 30, 2019 21:38
-
-
Save dmilith/f4996002c1c7b78201d8c20d59159874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
studio-snapshot () { | |
dataset="$1" | |
. /Software/Sofin/share/loader | |
if [ -z "${dataset}" ]; then | |
error "No Studio dataset name specified!" | |
else | |
stamp="$(date +%F_%H:%M:%S 2>/dev/null)" && \ | |
zfs snapshot "Studio/${dataset}@${stamp}" && \ | |
permnote "Snapshot successfully created for: $(distn "Studio/${dataset}@${stamp}")" | |
ping -c1 losbandos >/dev/null 2>&1 | |
if [ "$?" = "0" ]; then | |
previous_snapshot_local="$(zfs list -t snap 2>/dev/null | grep "${dataset}@" 2>/dev/null | tail -n2 2>/dev/null | head -n1 2>/dev/null | awk '{print $1;}' 2>/dev/null)" | |
last_snapshot_remote="$(ssh losbandos "zfs list -t snap 2>/dev/null | grep '${dataset}@' 2>/dev/null | tail -n1 2>/dev/null | awk '{print \$1;}' 2>/dev/null")" | |
if [ -z "${previous_snapshot_local}" ]; then | |
error "No previous snapshot available for dataset: Studio/${dataset}!" | |
else | |
permnote "Previous snapshot: $(distn "${previous_snapshot_local}")" | |
fi | |
permnote "Remote backup host available. Sending last increment: $(distn "Studio/${dataset}@${stamp}")" | |
if [ -z "${last_snapshot_remote}" ]; then | |
zfs send -I ${previous_snapshot_local} "Studio/${dataset}@${stamp}" | \ | |
ssh losbandos "sudo zfs recv -F Studio/${dataset}" | |
else | |
zfs send -I ${last_snapshot_remote} "Studio/${dataset}@${stamp}" | \ | |
ssh losbandos "sudo zfs recv -F Studio/${dataset}" | |
fi | |
else | |
warn "No remote available! Skipping remote push." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment