Created
January 26, 2011 16:48
-
-
Save phred/796984 to your computer and use it in GitHub Desktop.
Quick n' dirty shell script to back up a Cloudant database to a new, uniquely-named Cloudant DB.
This file contains hidden or 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/sh | |
CLOUDANT_USER="myusername" | |
CLOUDANT_PASS="mypassword" | |
CLOUDANT_DB="mydb" | |
DATE=`date +"%Y-%m-%d\$%H.%M"` | |
BACKUP_NAME="${CLOUDANT_DB}_backup_${DATE}" | |
echo "Creating database named ${BACKUP_NAME}" | |
# First, create the database | |
curl -X PUT "http://${CLOUDANT_USER}:${CLOUDANT_PASS}@${CLOUDANT_USER}.cloudant.com/${BACKUP_NAME}" -g | |
echo "Starting replication..." | |
# Next, tell the replicator to copy the source database to the new backup database | |
curl -X POST "http://${CLOUDANT_USER}:${CLOUDANT_PASS}@${CLOUDANT_USER}.cloudant.com/_replicate" -d '{"source":"http://'${CLOUDANT_USER}':'${CLOUDANT_PASS}'@${CLOUDANT_USER}.cloudant.com/'${CLOUDANT_DB}'","target":"http://'${CLOUDANT_USER}':'${CLOUDANT_PASS}'@'${CLOUDANT_USER}'.cloudant.com/'${BACKUP_NAME}'"}' -H "Content-type: application/json" -g | |
echo "All done." |
Thanks! Just made a quick edit to fix an issue I ran into today.
Hmm, I wonder what this is used for... ;)
Here's a gem to do this easily with ruby: cloudant-backup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one, cheers!