Created
July 5, 2014 08:52
-
-
Save shnjp/886eda28061c37047cd5 to your computer and use it in GitHub Desktop.
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 | |
S3_BUCKET=$1 | |
S3_OBJECT=$2 | |
S3CFG=S3-CONFIG-FILE | |
S3CMD="s3cmd -c $S3CFG" | |
TIMESTAMP=$((`date +%s` + 600)) | |
can_string="GET\n\n\n${TIMESTAMP}\n/${S3_BUCKET}/${S3_OBJECT}" | |
# generate the signature | |
SIGNATURE=$($S3CMD sign "$(echo -e "$can_string")" | sed -n 's/^Signature: //p') | |
# extract access key from .s3cfg | |
S3_ACCESS_KEY=$(sed -n 's/^access_key = //p' $S3CFG) | |
echo "https://${S3_BUCKET}.s3.amazonaws.com/${S3_OBJECT}?AWSAccessKeyId=${S3_ACCESS_KEY}&Expires=${TIMESTAMP}&Signature=${SIGNATURE}" |
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 | |
REDIS_DUMP_RDB='/usr/local/var/db/redis/dump.rdb' | |
REDIS_PROTOCOL_FILE='redis-cache-data.raw.gz' | |
S3_BACKUP_BUCKET='s3://S3-BUCKET-NAME/' | |
# dump redis data to .RDB file | |
basetimestamp=`redis-cli lastsave` | |
redis-cli bgsave | |
while [ 1 ] | |
do | |
curtimestamp=`redis-cli lastsave` | |
if [ $basetimestamp != $curtimestamp ] | |
then | |
break | |
fi | |
sleep 1 | |
done | |
# make redis loader command | |
echo 'Convert cache data to redis protocol commands...' | |
rdb --command protocol --key KEY-PATTERN $REDIS_DUMP_RDB gzip --stdout > $REDIS_PROTOCOL_FILE | |
# upload | |
echo 'Upload to S3' | |
s3cmd -c S3-CONFIG-FILE put $REDIS_PROTOCOL_FILE $S3_BACKUP_BUCKET | |
# remove file | |
rm $REDIS_PROTOCOL_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment