Amazon RDS - Online only when needed?

不想你离开。 提交于 2019-12-03 02:12:50

问题


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:

  1. Can I automate bringing my RDS database online and offline via scripts to save money?

  2. 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?


回答1:


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



回答2:


If you wish to do this programatically,

  1. Snapshot the RDS instance using rds-create-db-snapshot http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-CopyDBSnapshot.html

  2. Delete the running instance using rds-delete-db-instance http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-DeleteDBInstance.html

  3. Restore the database from the snapshot using rds-restore-db-instance-from-db-snapshot http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-RestoreDBInstanceFromDBSnapshot.html

You may also do all of this from the AWS Web Console as well, if you wish to do this manually.




回答3:


You can start EC2* instances using shell scripts, so I guess that you can as well for RDS. (see http://docs.aws.amazon.com/AmazonRDS....html)

But unlike EC2*, you cannot "stop" an RDS instance without "destroying" it. You need to create a DB snapshot when terminating your database. You will use this DB snapshot when re-starting the database.

*EC2 : Elastic Computing, renting a virtual server or a server.




回答4:


Amazon recently updated their CLI to include a way to start and stop RDS instances. stop-db-instance and start-db-instance detail the steps needed to perform these operations.



来源:https://stackoverflow.com/questions/14923774/amazon-rds-online-only-when-needed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!