Skip to content

Instantly share code, notes, and snippets.

@JacopoDaeli
Last active October 23, 2017 05:19
Show Gist options
  • Save JacopoDaeli/7faa94980d234e1b1451a3d54a7ba20a to your computer and use it in GitHub Desktop.
Save JacopoDaeli/7faa94980d234e1b1451a3d54a7ba20a to your computer and use it in GitHub Desktop.
Backup Redis to Goolge Cloud Storage
#!/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