Skip to content

Instantly share code, notes, and snippets.

@G3z
Forked from cullan/nanobox_latest_backup.sh
Last active November 20, 2019 09:05
Show Gist options
  • Save G3z/35178e90b58fc9bd7de11b0629cfa694 to your computer and use it in GitHub Desktop.
Save G3z/35178e90b58fc9bd7de11b0629cfa694 to your computer and use it in GitHub Desktop.
Nanobox fetch latest backup
#!/bin/bash
# grab the latest backup from the warehouse data hoarder
# this file goes in the root of the nanobox project.
# it assumes you followed the backup guide:
# https://content.nanobox.io/data-safety-with-nanobox-backup-and-recovery/
search=${1:-backup}
port=7410
address="https://localhost:$port/blobs"
token=$(nanobox evar ls | awk '/DATA_HOARDER_TOKEN/ {print $3}')
if [ -z "$token" ]
then
echo "Missing variable DATA_HOARDER_TOKEN"
echo "go to https://dashboard.nanobox.io and copy the value of WAREHOUSE_DATA_HOARDER_TOKEN"
echo "like so:"
echo "nanobox evar add DATA_HOARDER_TOKEN=****"
exit
fi
dst=./nanobox/backups # location to save backup
# open a tunnel to the data hoarder
nanobox tunnel warehouse.data.hoarder -p $port: &> /dev/null &
# keep the pid so we can stop the tunnel later
tunnel_pid=$!
echo "Waiting for the tunnel to come up..."
while ! nc -z localhost $port
do
sleep 0.5
done
backup=$(curl -k -s -H "X-AUTH-TOKEN: $token" $address |
json_pp |
grep $search | # or another word in the filename to match on
sed 's/.*: "\(.*\)".*/\1/' |
sort |
tail -n 1)
echo "Grabbing $backup"
mkdir -p $dst
curl -s -k -H "X-AUTH-TOKEN: $token" $address/$backup > $dst/$backup
echo "Done"
# stop the tunnel
kill $tunnel_pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment