pwnagotchi/scripts/backup.sh

46 lines
1.1 KiB
Bash
Raw Normal View History

2019-10-03 15:55:03 +02:00
#!/usr/bin/env bash
# name of the ethernet gadget interface on the host
UNIT_HOSTNAME=${1:-10.0.0.2}
# output backup zip file
OUTPUT=${2:-pwnagotchi-backup.zip}
# what to backup
FILES_TO_BACKUP=(
/root/brain.nn
/root/brain.json
/root/.api-report.json
2019-10-03 15:55:03 +02:00
/root/handshakes
/root/peers
2019-10-08 19:29:22 +02:00
/etc/pwnagotchi/
2019-10-03 15:55:03 +02:00
/var/log/pwnagotchi.log
)
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 "@ backing up $UNIT_HOSTNAME to $OUTPUT ..."
ssh pi@$UNIT_HOSTNAME "sudo rm -rf /tmp/backup && sudo rm -rf /tmp/backup.zip" > /dev/null
2019-10-03 15:55:03 +02:00
for file in "${FILES_TO_BACKUP[@]}"; do
dir=$(dirname $file)
echo "@ copying $file to /tmp/backup$dir"
ssh pi@$UNIT_HOSTNAME "mkdir -p /tmp/backup$dir" > /dev/null
ssh pi@$UNIT_HOSTNAME "sudo cp -r $file /tmp/backup$dir" > /dev/null
2019-10-03 15:55:03 +02:00
done
echo "@ pulling from $UNIT_HOSTNAME ..."
rm -rf /tmp/backup
scp -rC pi@$UNIT_HOSTNAME:/tmp/backup /tmp/
echo "@ compressing ..."
zip -r -9 -q $OUTPUT /tmp/backup
rm -rf /tmp/backup