Merge branch 'master' of eternae.ink:ashpie/server-scripts

This commit is contained in:
Alice Gaudon 2021-10-04 11:36:18 +02:00
commit 1f0f73bd4c
2 changed files with 30 additions and 13 deletions

View File

@ -105,7 +105,7 @@ done <<< $(echo -e "$DISKS")
### Welcome message ###
LAST_LOGIN=$(last -w | grep $(whoami) | head -2 | tail -1)
LAST_LOGIN=$(last -w --time-format iso | grep $(whoami) | head -2 | tail -1)
echo -e
echo -e "Welcome to $(hostname), $(whoami)!
Last login: $(echo "$LAST_LOGIN" | awk '{for(i=4;i<=NF;i++) print $i}' | paste -sd ' ') from $(echo "$LAST_LOGIN" | awk '{print $3}')"

View File

@ -30,11 +30,28 @@ update_remote_state() {
echo "Fetching remote snapshots..."
remote_snapshots=$(ssh $REMOTE zfs list -H -t snapshot -o name -s creation)
r=$?
if [ $r -ne 0 ]; then
return $r
fi
echo "Fetching subdatasets..."
remote_subdatasets=$(ssh $REMOTE zfs list -H -o name -s creation -r "$REMOTE_ROOT_DATASET")
r=$?
if [ $r -ne 0 ]; then
return $r
fi
echo "Fetching resume tokens..."
resume_tokens=$(ssh $REMOTE zfs get -H -p receive_resume_token -o name,value -t filesystem)
r=$?
if [ $r -ne 0 ]; then
return $r
fi
return 0
}
@ -46,9 +63,9 @@ resume_transfer() {
RESUME_TOKEN=$(echo -e "$resume_tokens" | grep -P "^$remote_dataset\t.*\$" | cut -d$'\t' -f2)
if [ "$RESUME_TOKEN" != "" ] && [ "$RESUME_TOKEN" != "-" ]; then
echo "Resuming interrupted transfer..."
zfs send -v -t "$RESUME_TOKEN" | ssh $REMOTE zfs receive -Fu -s "$remote_dataset" || return 1
zfs send -v -t "$RESUME_TOKEN" | ssh $REMOTE zfs receive -Fu -s "$remote_dataset" || return 10
echo "Resumed transfer finished."
update_remote_state
update_remote_state || return 20
return 0
fi
@ -78,7 +95,7 @@ handle_dataset() {
echo
resume_transfer "$TARGET_REMOTE_DATASET" || return 1
resume_transfer "$TARGET_REMOTE_DATASET" || return 11
### Sync existing snapshots ###
@ -120,7 +137,7 @@ handle_dataset() {
if [ $RECURSIVE = true ] ; then
recu="-R"
fi
zfs send -v -p $recu $incr "$DATASET@$TO_SNAPSHOT" | ssh $REMOTE zfs receive -Fu -s "$TARGET_REMOTE_DATASET" || return 1
zfs send -v -p $recu $incr "$DATASET@$TO_SNAPSHOT" | ssh $REMOTE zfs receive -Fu -s "$TARGET_REMOTE_DATASET" || return 12
echo
echo "Done"
@ -140,7 +157,7 @@ init_subdataset() {
TARGET_REMOTE_DATASET="$REMOTE_ROOT_DATASET/"$(echo -e $PARENT_DATASET | sed -r "s/\//_/g")"/"${DATASET:$(echo -e "$PARENT_DATASET" | wc -c)}
resume_transfer "$TARGET_REMOTE_DATASET" || return 1
resume_transfer "$TARGET_REMOTE_DATASET" || return 13
if [ $(echo -e "$remote_subdatasets" | grep -e "^$TARGET_REMOTE_DATASET\$" | wc -l) -eq 0 ]; then
echo "Subdataset not found on $TARGET_REMOTE_DATASET, initializing..."
@ -149,11 +166,11 @@ init_subdataset() {
if test -z "$LOCAL_SNAPSHOT"; then
echo "No local snapshot"
return 1
return 14
fi
echo "[$DATASET@$LOCAL_SNAPSHOT -> $TARGET_REMOTE_DATASET]"
zfs send -v -p "$DATASET@$LOCAL_SNAPSHOT" | ssh $REMOTE zfs receive -Fu -s "$TARGET_REMOTE_DATASET" || return 1
zfs send -v -p "$DATASET@$LOCAL_SNAPSHOT" | ssh $REMOTE zfs receive -Fu -s "$TARGET_REMOTE_DATASET" || return 15
echo
echo "--- Done"
@ -162,7 +179,7 @@ init_subdataset() {
echo
echo "--- Subdataset $TARGET_REMOTE_DATASET is out of date compared to parent dataset. Syncing first..."
handle_dataset "$DATASET" false "" "$TARGET_REMOTE_DATASET" || return 1
handle_dataset "$DATASET" false "" "$TARGET_REMOTE_DATASET" || return 16
echo
echo "--- Done"
@ -173,7 +190,7 @@ init_subdataset() {
}
update_remote_state
update_remote_state || exit 21
HAD_ERROR=0
@ -216,7 +233,7 @@ for line in $(cat "$ZSC_CONFIG") ; do
for p in "${SUBDATASETS[@]}"; do
init_subdataset $p $dataset "$latest_synchronized_snapshot"
r=$?
if [ ! $r ]; then
if [ $r -ne 0 ]; then
echo "Error while initing subdataset $p, continuing"
if [ $HAD_ERROR ]; then
HAD_ERROR=$r
@ -227,12 +244,12 @@ for line in $(cat "$ZSC_CONFIG") ; do
echo "----------"
echo
update_remote_state
update_remote_state || exit 22
fi
handle_dataset $dataset $recursive $prefix
r=$?
if [ ! $r ]; then
if [ $r -ne 0 ]; then
echo "Error while initing subdataset $p, continuing"
if [ $HAD_ERROR ]; then
HAD_ERROR=$r