Amazon RDS - Online only when needed?

amazon-rds, amazon-web-services

Solution

Here's a script that will stop/start/reboot an RDS instance

#!/bin/bash

# usage ./startStop.sh lhdevices start

INSTANCE="$1"
ACTION="$2"



# export vars to run RDS CLI
export JAVA_HOME=/usr;
export AWS_RDS_HOME=/home/mysql/RDSCli-1.15.001;
export PATH=$PATH:/home/mysql/RDSCli-1.15.001/bin;
export EC2_REGION=us-east-1;
export AWS_CREDENTIAL_FILE=/home/mysql/RDSCli-1.15.001/keysLightaria.txt;

if [ $# -ne 2 ]
then
echo "Usage: $0 {MySQL-Instance Name} {Action either start, stop or reboot}"
echo ""
exit 1
fi


shopt -s nocasematch

if [[ $ACTION == 'start' ]]
then
echo "This will $ACTION a MySQL Instance"  
rds-restore-db-instance-from-db-snapshot lhdevices 
--db-snapshot-identifier        dbStart --availability-zone us-east-1a     
--db-instance-class db.m1.small 

echo "Sleeping while instance is created"
sleep 10m
echo "waking..."

rds-modify-db-instance lhdevices --db-security-groups kfarrell

echo "Sleeping while instance is modified for security group name"
sleep 5m
echo "waking..."

elif [[ $ACTION == 'stop' ]]
then
echo "This will $ACTION a MySQL Instance" 

yes | rds-delete-db-snapshot dbStart

echo "Sleeping while deleting old snapshot "
sleep 10m

#rds-create-db-snapshot lhdevices --db-snapshot-identifier dbStart

# echo "Sleeping while creating new snapshot "
# sleep 10m
# echo "waking...."

#rds-delete-db-instance lhdevices --force --skip-final-snapshot 
rds-delete-db-instance lhdevices --force --final-db-snapshot-identifier dbStart

echo "Sleeping while instance is deleted"
sleep 10m
echo "waking...."

elif [[ $ACTION == 'reboot' ]]
then
echo "This will $ACTION a MySQL Instance" 
rds-reboot-db-instance lhdevices ;

echo "Sleeping while Instance is rebooted"
sleep 5m
echo "waking...."

else

echo "Did not recognize command: $ACTION"
echo "Usage: $0 {MySQL-Instance Name} {Action either start, stop or reboot}"

fi
shopt -u nocasematch

Problem

I had a question about Amazon RDS. I only need the database online for about 2 hours a day but I am dealing with quite a large database at around 1gb. I have two main questions: Can I automate bringing my RDS database online and offline via scripts to save money? When I put a RDS offline to stop the "work hours" counter running and billing me, when I bring it back online will it still have the same content (i.e will all my data stay there, or will it have to be a blank DB?). If so, is there any way around this rather than backing up to S3 and reimporting it every time?

Original source