-
-
Save G3z/35178e90b58fc9bd7de11b0629cfa694 to your computer and use it in GitHub Desktop.
Nanobox fetch latest backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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