Problem:
I run a site called Videoly. It is a simple video emailing service. The site is hosted on Amazon EC2 instance and we wanted a simple backup solution for our user generated content. The criteria for the backup solutions were simple - cheap, simple, reliable. It should include incremental changes to user generated data, database changes, and important configuration files. Also, the process should generate reports and deliver them through emails.
How to backup MySQL database and files from Amazon EC2 instance ?
Solution:
Amazon EC2 service is neatly coupled with simple storage service also called as Amazon S3. We decided to use the S3 service to store our backups. The service is reliable and most importantly all transfers between S3 and EC2 instances are free.
Here is our current solution -
- Use JungleDisk to map s3 to our EC2 instance
- Backup our content and MySQL database using a utility called Backup Manager
- Use Cron job to perform regular backups and send emails
Here we go ... concise list of steps you need to perform in order to implement such solution -
1. Jungle Disk
Reference to a helpful post here
Install jungledisk, and FUSE. Check out your distribution instructions. During your installation remember the location where you store your settings file. In my case, I stored it in /root/.jungledisk/jungledisk-settings.xml
Edit jungledisk-settings.xml.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configEncryptionKey>PROTECTED:dgfdfgd34342fsd9f8fs90sfs</configEncryptionKey>
<GlobalConfig>
<proxyServer>
<enabled>0</enabled>
<proxyServer></proxyServer>
<userName></userName>
<password></password>
</proxyServer>
<listenPort>2667</listenPort>
<cacheDirectory>/root/.jungledisk/cache/</cacheDirectory>
<logDuration>30</logDuration>
<largeWindows>0</largeWindows>
<useSSL>1</useSSL>
<loginAccount>
<userName>kunal@videoly.com</userName>
<password>ENCRYPTED:sdfsdfN398sdfKNUsdf09343098sdfSHUIsdf</password>
<domain></domain>
</loginAccount>
<enableUpdateCheck>1</enableUpdateCheck>
<passwordPrompt>0</passwordPrompt>
<computerName></computerName>
<uploadLimit>
<enableLimit>0</enableLimit>
<rateLimit>200</rateLimit>
<limitTimeRange>0</limitTimeRange>
<startTime>0</startTime>
<endTime>0</endTime>
</uploadLimit>
<downloadLimit>
<enableLimit>0</enableLimit>
<rateLimit>200</rateLimit>
<limitTimeRange>0</limitTimeRange>
<startTime>0</startTime>
<endTime>0</endTime>
</downloadLimit>
<buckets>
<value>
<BucketConfig>
<bucketName>videoly-backup</bucketName>
<accessKey>1SDFAF2dfSKDFJ4R2</accessKey>
<secretKey>ENCRYPTED:SSFOQ3sdf:LIOIDSFhNDNlYjFiZjk5ZDlhYjsdufIOOsdff3A6Qi9Rwt3AZ//GOXCeZQyIsi8XtpOr8jYyYY411MqQ=</secretKey>
<cacheCheckInterval>120</cacheCheckInterval>
<maxCacheSize>1000</maxCacheSize>
<retryCount>3</retryCount>
<asyncOperations>1</asyncOperations>
<encryptionKey></encryptionKey>
<decryptionKeys></decryptionKeys>
<useFastCopy>1</useFastCopy>
<uploadResume>1</uploadResume>
<deltaUpdates>1</deltaUpdates>
<plusFallback>0</plusFallback>
<archiveFlag>1</archiveFlag>
<archiveConfig>
<archiveUpdated>1</archiveUpdated>
<archiveDeleted>1</archiveDeleted>
<maxArchiveSize>100</maxArchiveSize>
<maxArchiveCount>0</maxArchiveCount>
<enableExcludeTypes>0</enableExcludeTypes>
<enableExcludeFolders>0</enableExcludeFolders>
<archiveExcludeTypes></archiveExcludeTypes>
<archiveExcludeFolders></archiveExcludeFolders>
</archiveConfig>
<archiveCleanupConfig>
<minArchiveCount>0</minArchiveCount>
<archiveDuration>60</archiveDuration>
</archiveCleanupConfig>
<networkDrive>
<mapDrive></mapDrive>
<mountVolume></mountVolume>
<mountPath>/mnt/jungledisk</mountPath>
</networkDrive>
<loginTicket>VCsdfZWjL+1aWWCeQKwdXXDaE8g1YkDo+1aWWCeQKwdXQ/uzrVJXH1zFPJIq+1aWWCeQKwdX/4EsP1615Nh5DCO1yKVw2uWYZCw2SCzmzoNnVhMOvr</loginTicket>
<licenseData>Y+1aWWCeQKwdXMzgzODVjNWI2ZWI0MjFiNDE3ZjkxMWQ0ZFtr++1aWWCeQKwdX|qaJyURvY6hk86lGhpDHTtKBStO9YH9Z9qaUI7WMgg8ly3wo9zrSLvEaVfmKFPX3IvZvUuoNBsSRTeW23eCO/+1aWWCeQKwdX/LbxjJ00/Y=|fnYsPyUVCZWjLXDaIulYAjzf6BdQJYvP2kA0tvg2Kfx98YxKdRE8g1YkDoQ/uzrVJXH1zFPJIq+1aWWCeQKwdX/4EsP1615Nh5DCO1yKVw2uWYZCw2SCzmzoNnVhMOvr</licenseData>
<archivePath>/~VersionArchive</archivePath>
<backupJobs></backupJobs>
</BucketConfig>
</value>
</buckets>
</GlobalConfig>
</configuration>
Mount JungleDisk
/sbin/modprobe fuse
/usr/local/jungledisk/jungledisk /mnt/jungledisk -o config=~/.jungledisk/jungledisk-settings.xml
2. Backup Manager
Reference to a great article by Tim Linden here
wget http://www.backup-manager.org/download/backup-manager-0.7.7.tar.gz
gzip -d backup-manager-0.7.7.tar.gz
tar -xvf backup-manager-0.7.7.tar
cd backup-manager-0.7.7
make install
cp /usr/share/backup-manager/backup-manager.conf.tpl /etc/backup-manager.conf
Backup Manager 0.7.7 includes a feature which uploads the backup files to S3 location. However, when I read though the documentation and forums, I found this post. The author of the utility does not speak highly about the feature, so I stayed away from it. I just used the utility to backup my files. Here is my configuration file -
Edit /etc/backup-manager.conf. I left everything else to default
export BM_REPOSITORY_ROOT="/mnt/jungledisk/"
#otherwise you will get chmod errors
export BM_REPOSITORY_SECURE="false"
export BM_ARCHIVE_METHOD="mysql tarball-incremental"
# dar slices backups, helps to keep objects below 5 GB - requirement of S3
export BM_TARBALL_FILETYPE="dar"
#Content folders
BM_TARBALL_TARGETS[0]="/usr/local/content1"
BM_TARBALL_TARGETS[1]="/usr/local/content2"
BM_TARBALL_TARGETS[2]="/usr/local/content3"
# S3 allows file size to be max 5 GB so I set them to be 4.5 GB to be on safe side
export BM_TARBALL_SLICESIZE="4500M"
#here is an example of incremental backup setting
# once a week fullbackup on the day 1
export BM_TARBALLINC_MASTERDATETYPE="weekly"
export BM_TARBALLINC_MASTERDATEVALUE="1"
export BM_MYSQL_DATABASES="__ALL__"
export BM_MYSQL_ADMINLOGIN="root"
export BM_MYSQL_ADMINPASS="notgoingtotellyou"
#turned off upload feature
export BM_UPLOAD_METHOD="none"
3. Add a Cron Job
1: crontab -e
2: enter “45 1 * * * /usr/sbin/backup-manager –v“
3: crontab -l
These are minimum steps to get you started. Lot of minor tweaks might be necessary to get it to work for you.




Recent Comments