Skip to content

Instantly share code, notes, and snippets.

@cullan
Last active November 20, 2019 08:59
Show Gist options
  • Save cullan/7d321fa677f134cad9e12702c4d4bb81 to your computer and use it in GitHub Desktop.
Save cullan/7d321fa677f134cad9e12702c4d4bb81 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/
port=7410
address="https://localhost:$port/blobs"
token=$(nanobox evar ls | awk '/DATA_HOARDER_TOKEN/ {print $3}')
dst=./storage/backup/ # 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 backup | # or another word in the filename to match on
sed 's/.*: "\(.*\)".*/\1/' |
sort |
tail -n 1)
echo "Grabbing $backup"
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