AWS Example of Backing Up A Database And Image File

The following shell script can be executed from the command line or via Cron.

#!/bin/sh

cd /home/temp.directory
/usr/bin/mysqldump -u dbrootuser -pdbrootpw --host mysql.my.host.name --single-transaction databasename > databasename.txt
nowdate=$(date +"%Y-%m-%d")
mv databasename.txt $nowdate.databasename.txt
echo
echo "databasename database backup completed."
echo

tar -zcf website.image.tgz ~/website/images/ 
mv website.image.tgz $nowdate.website.image.tgz
echo
echo "website image directory backup completed."
echo

#use aws-cli to upload to DreamObjects
aws --endpoint-url https://objects-us-east-1.dream.io s3 sync /home/temp.directory s3://bucketname/
echo
echo "Backups are in AWS bucket."
echo

#delete backups from web server
rm -f /home/temp.directory/* 

Before running this script you should:
#Set up the AWS bucket for your backups.
#Create a directory called temp.directory in your user root.
#Perform the following substatutions in the above script:
##Replace ‘’‘dbrootuser’’’ with the database root user ID.
##Replace ‘’‘dbrootpw’’’ with the database root user password.
##Replace ‘’‘mysql.my.host.name’’’ with a host URL for your database server.
##Replace ‘’‘databasename’’’ with the name of your database.
##Replace ‘’‘website’’’ with the absolute location of your website’s main directory.

This post was flagged by the community and is temporarily hidden.