You want to manually save your application code. Perhaps you have an EC2 instance where you want to save your application code to an S3 bucket before the instance is terminated.
You can use the sample Bash code below to create a RightScript that will upload the contents from a specified directory to an S3 bucket. Simply add it to your Server/ServerTemplate and run it as an operational script to backup your application code.
Note: This script assumes that you have s3cmd installed. (See How do I install s3cmd?)
#/bin/bash # # Package content of application directory and upload it to s3 # Caution: Will overwrite any existing S3 files without warning! # export AWS_SECRET_ACCESS_KEY=$AWS_ACCESS_KEY export AWS_ACCESS_KEY_ID=$AWS_ACCESS_ID if [ -d "$APP_DIR" ]; then cd $APP_DIR tar czf $APPLICATION_NAME * s3cmd put $BUCKET:$APPLICATION_NAME $APPLICATION_NAME rm $APPLICATION_NAME logger -t RightScript "Uploaded $APPLICATION_NAME to S3 bucket $BUCKET" exit 0 else echo "Error entering directory $APP_DIR" echo "Aborting" exit 1
You will need to define values for the following inputs:
|APPLICATION_NAME||The name of your application (e.g. myapp)|
|APP_DIR||The directory where your application code is stored (e.g. /home/webapps/myproject/current)|
|AWS_ACCESS_ID||Your AWS Access ID|
|AWS_ACCESS_KEY||Your AWS Access Key|
The name of the S3 bucket where the backup of your application code will be saved. (e.g. myappbucket)
Note: When this script is executed, it will overwrite any existing file in the S3 bucket (if it has the same name).
© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.