AWS Example of Backing Up A Database And Image File

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


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

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

#use aws-cli to upload to DreamObjects
aws --endpoint-url s3 sync /home/ s3://bucketname/
echo "Backups are in AWS bucket."

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

Before running this script you should:
#Set up the AWS bucket for your backups.
#Create a directory called 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 ‘’‘’’’ 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.