enhancement: Improve the backup script
- Significantly decrease time it takes to save a backup - Remove host dependency on 'zip' binary - Preserve file attributes on backed-up files - Avoid copying files on the pi itself to /tmp Signed-off-by: Jeremy O'Brien <neutral@fastmail.com>
This commit is contained in:
parent
bd63f71a1d
commit
3efa96b292
scripts
@ -3,7 +3,7 @@
|
|||||||
# name of the ethernet gadget interface on the host
|
# name of the ethernet gadget interface on the host
|
||||||
UNIT_HOSTNAME=${1:-10.0.0.2}
|
UNIT_HOSTNAME=${1:-10.0.0.2}
|
||||||
# output backup zip file
|
# output backup zip file
|
||||||
OUTPUT=${2:-pwnagotchi-backup.zip}
|
OUTPUT=${2:-pwnagotchi-backup.tgz}
|
||||||
# username to use for ssh
|
# username to use for ssh
|
||||||
USERNAME=${3:-pi}
|
USERNAME=${3:-pi}
|
||||||
# what to backup
|
# what to backup
|
||||||
@ -19,38 +19,10 @@ FILES_TO_BACKUP=(
|
|||||||
/home/pi/.bashrc
|
/home/pi/.bashrc
|
||||||
)
|
)
|
||||||
|
|
||||||
if ! type "zip" >/dev/null 2>&1; then
|
|
||||||
echo "This script requires zip, please resolve and try again"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ping -c 1 "${UNIT_HOSTNAME}" >/dev/null || {
|
ping -c 1 "${UNIT_HOSTNAME}" >/dev/null || {
|
||||||
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."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "@ backing up $UNIT_HOSTNAME to $OUTPUT ..."
|
echo "@ backing up $UNIT_HOSTNAME to $OUTPUT ..."
|
||||||
|
ssh "${USERNAME}@${UNIT_HOSTNAME}" "sudo tar cv ${FILES_TO_BACKUP[@]}" | gzip -9 > "$OUTPUT"
|
||||||
ssh "${USERNAME}@${UNIT_HOSTNAME}" "sudo rm -rf /tmp/backup && sudo rm -rf /tmp/backup.zip" > /dev/null
|
|
||||||
|
|
||||||
for file in "${FILES_TO_BACKUP[@]}"; do
|
|
||||||
dir=$(dirname "$file")
|
|
||||||
|
|
||||||
echo "@ copying $file to /tmp/backup$dir"
|
|
||||||
|
|
||||||
ssh "${USERNAME}@${UNIT_HOSTNAME}" "mkdir -p /tmp/backup${dir}" > /dev/null
|
|
||||||
ssh "${USERNAME}@${UNIT_HOSTNAME}" "sudo cp -r ${file} /tmp/backup${dir}" > /dev/null
|
|
||||||
done
|
|
||||||
|
|
||||||
ssh "${USERNAME}@${UNIT_HOSTNAME}" "sudo chown ${USERNAME}:${USERNAME} -R /tmp/backup" > /dev/null
|
|
||||||
|
|
||||||
echo "@ pulling from $UNIT_HOSTNAME ..."
|
|
||||||
|
|
||||||
rm -rf /tmp/backup
|
|
||||||
scp -rC "${USERNAME}@${UNIT_HOSTNAME}":/tmp/backup /tmp/
|
|
||||||
|
|
||||||
echo "@ compressing ..."
|
|
||||||
|
|
||||||
zip -r -9 -q "$OUTPUT" /tmp/backup
|
|
||||||
rm -rf /tmp/backup
|
|
||||||
|
|
||||||
|
16
scripts/restore.sh
Executable file
16
scripts/restore.sh
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# name of the ethernet gadget interface on the host
|
||||||
|
UNIT_HOSTNAME=${1:-10.0.0.2}
|
||||||
|
# output backup zip file
|
||||||
|
BACKUP=${2:-pwnagotchi-backup.tgz}
|
||||||
|
# username to use for ssh
|
||||||
|
USERNAME=${3:-pi}
|
||||||
|
|
||||||
|
ping -c 1 "${UNIT_HOSTNAME}" >/dev/null || {
|
||||||
|
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 /"
|
Loading…
x
Reference in New Issue
Block a user