Skip to content

Instantly share code, notes, and snippets.

@luckyjajj
luckyjajj / elasticache_backup.sh
Last active January 14, 2019 22:28
Hacky AWS ElastiCache Hourly Backup Shell Script
#!/bin/bash
## Requires AWS CLI Tools
aws elasticache create-snapshot --cache-cluster-id redis-replica-1 --snapshot-name cg-backup-hourly-"$(date +"%Y-%m-%d-%H%M")"
if [ $(aws elasticache describe-snapshots --cache-cluster-id redis-replica-1 |grep SnapshotName | wc -l) = "8" ]; then
old_snapshot="$(aws elasticache describe-snapshots --cache-cluster-id redis-replica-1 |grep SnapshotName | head -1 | cut -d \" -f 4)"
aws elasticache delete-snapshot --snapshot-name $old_snapshot
fi