Skip to content

Instantly share code, notes, and snippets.

@Twinuma
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save Twinuma/c8f25aa4fcd26fc5af19 to your computer and use it in GitHub Desktop.

Select an option

Save Twinuma/c8f25aa4fcd26fc5af19 to your computer and use it in GitHub Desktop.

Revisions

  1. Twinuma revised this gist Sep 5, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rds-snapshot_prod.sh
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ BACKUP_DATE=`date '+%Y%m%d'`
    rds-create-db-snapshot -i YOUR DBNAME -s backup-$BACKUP_DATE

    COUNT=0
    # 世代をここで設定
    MAX=3

    for i in `rds-describe-db-snapshots | cut -f3 -d ' ' | sort -r`
  2. Twinuma created this gist Sep 5, 2014.
    2 changes: 2 additions & 0 deletions credential.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    AWSAccessKeyId=your AccessKey
    AWSSecretKey=your SecretKey
    23 changes: 23 additions & 0 deletions rds-snapshot_prod.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/sh -l

    export JAVA_HOME=/usr/lib/jvm/jre
    export AWS_BIN=/opt/aws/bin
    export PATH=$PATH:$EC2_HOME/bin:$AWS_BIN
    export EC2_REGION=ap-northeast-1
    export AWS_CREDENTIAL_FILE=/opt/aws/rds/credential.txt

    BACKUP_DATE=`date '+%Y%m%d'`
    rds-create-db-snapshot -i YOUR DBNAME -s backup-$BACKUP_DATE

    COUNT=0
    MAX=3

    for i in `rds-describe-db-snapshots | cut -f3 -d ' ' | sort -r`
    do
    if [ $COUNT -ge $MAX ]
    then
    echo "DELETE:$i"
    rds-delete-db-snapshot $i -f
    fi
    COUNT=`expr $COUNT + 1`
    done