Last active
October 23, 2017 05:19
-
-
Save JacopoDaeli/7faa94980d234e1b1451a3d54a7ba20a to your computer and use it in GitHub Desktop.
Backup Redis to Goolge Cloud Storage
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/bash | |
#### BEGIN CONFIGURATION #### | |
# set dates for backup rotation | |
NOWDATE=`date +%Y-%m-%d` | |
# set backup directory variables | |
SRCDIR='/tmp/gs_backups' | |
DESTDIR='redis' | |
BUCKET='backups' | |
#### END CONFIGURATION #### | |
# gcloud auth | |
gcloud auth activate-service-account --key-file=/path/to/gsbackups-key.json | |
# make the temp directory if it doesn't exist | |
mkdir -p $SRCDIR | |
# make a compressed copy of the redis dump | |
cp /var/lib/redis/dump.rdb $SRCDIR/$NOWDATE-redis-dump.rdb | |
gzip $SRCDIR/$NOWDATE-redis-dump.rdb | |
# send the file off to gs | |
/usr/bin/gsutil cp $SRCDIR/$NOWDATE-redis-dump.rdb.gz gs://$BUCKET/$DESTDIR/ | |
# remove all files in our source directory | |
rm -f $SRCDIR/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment