fix: don't use $USERNAME as default username for backup/restore scripts, as this is usually defined on linux hosts as the current logged in user

Signed-off-by: Jeremy O'Brien <neutral@fastmail.com>
This commit is contained in:
Jeremy O'Brien 2019-11-15 07:55:22 -05:00
parent 87e46610f9
commit 8c51936c13
2 changed files with 6 additions and 6 deletions

View File

@ -17,7 +17,7 @@ while getopts "ho:n:u:" arg; do
OUTPUT=$OPTARG OUTPUT=$OPTARG
;; ;;
u) u)
USERNAME=$OPTARG UNIT_USERNAME=$OPTARG
;; ;;
*) *)
usage usage
@ -30,7 +30,7 @@ UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2}
# output backup tgz file # output backup tgz file
OUTPUT=${OUTPUT:-${UNIT_HOSTNAME}-backup-$(date +%s).tgz} OUTPUT=${OUTPUT:-${UNIT_HOSTNAME}-backup-$(date +%s).tgz}
# username to use for ssh # username to use for ssh
USERNAME=${USERNAME:-pi} UNIT_USERNAME=${UNIT_USERNAME:-pi}
# what to backup # what to backup
FILES_TO_BACKUP="/root/brain.nn \ FILES_TO_BACKUP="/root/brain.nn \
/root/brain.json \ /root/brain.json \
@ -54,4 +54,4 @@ ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
} }
echo "@ backing up $UNIT_HOSTNAME to $OUTPUT ..." 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"

View File

@ -17,7 +17,7 @@ while getopts "hb:n:u:" arg; do
UNIT_HOSTNAME=$OPTARG UNIT_HOSTNAME=$OPTARG
;; ;;
u) u)
USERNAME=$OPTARG UNIT_USERNAME=$OPTARG
;; ;;
*) *)
exit 1 exit 1
@ -42,7 +42,7 @@ if [ -z $BACKUP ]; then
fi fi
fi fi
# username to use for ssh # username to use for ssh
USERNAME=${USERNAME:-pi} UNIT_USERNAME=${UNIT_USERNAME:-pi}
ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || { 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." echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
@ -50,4 +50,4 @@ ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
} }
echo "@ restoring $BACKUP to $UNIT_HOSTNAME ..." 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 /"