Skip to content

Commit

Permalink
fix: don't use $USERNAME as default username for backup/restore scrip…
Browse files Browse the repository at this point in the history
…ts, as this is usually defined on linux hosts as the current logged in user

Signed-off-by: Jeremy O'Brien <neutral@fastmail.com>
  • Loading branch information
neutralinsomniac committed Nov 15, 2019
1 parent 87e4661 commit 8c51936
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ while getopts "ho:n:u:" arg; do
OUTPUT=$OPTARG
;;
u)
USERNAME=$OPTARG
UNIT_USERNAME=$OPTARG
;;
*)
usage
Expand All @@ -30,7 +30,7 @@ UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2}
# output backup tgz file
OUTPUT=${OUTPUT:-${UNIT_HOSTNAME}-backup-$(date +%s).tgz}
# username to use for ssh
USERNAME=${USERNAME:-pi}
UNIT_USERNAME=${UNIT_USERNAME:-pi}
# what to backup
FILES_TO_BACKUP="/root/brain.nn \
/root/brain.json \
Expand All @@ -54,4 +54,4 @@ ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
}

echo "@ backing up $UNIT_HOSTNAME to $OUTPUT ..."
ssh "${USERNAME}@${UNIT_HOSTNAME}" "sudo find ${FILES_TO_BACKUP} -print0 | xargs -0 sudo tar cv" | gzip -9 > "$OUTPUT"
ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo find ${FILES_TO_BACKUP} -print0 | xargs -0 sudo tar cv" | gzip -9 > "$OUTPUT"
6 changes: 3 additions & 3 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ while getopts "hb:n:u:" arg; do
UNIT_HOSTNAME=$OPTARG
;;
u)
USERNAME=$OPTARG
UNIT_USERNAME=$OPTARG
;;
*)
exit 1
Expand All @@ -42,12 +42,12 @@ if [ -z $BACKUP ]; then
fi
fi
# username to use for ssh
USERNAME=${USERNAME:-pi}
UNIT_USERNAME=${UNIT_USERNAME:-pi}

ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
exit 1
}

echo "@ restoring $BACKUP to $UNIT_HOSTNAME ..."
cat ${BACKUP} | ssh "${USERNAME}@${UNIT_HOSTNAME}" "sudo tar xzv -C /"
cat ${BACKUP} | ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo tar xzv -C /"

0 comments on commit 8c51936

Please sign in to comment.