EC2 Consistent Snapshot

The purpose of this document is to explain how to install and use ec2-consistent-snapshot (see here for the readme).

Install CPAN

yum -y install expat-devel.x86_64 tmp_dir="/root/tmp/ec2-consistent-snapshot" && dst_dir="/opt/aws/ec2-consistent-snapshot/" mkdir -p "${tmp_dir}" && mkdir -p "${dst_dir}" && cd "${tmp_dir}" wget https://raw.github.com/alestic/ec2-consistent-snapshot/master/ec2-consistent-snapshot mv ec2-consistent-snapshot ec2-consistent-snapshot.pl && chmod u+x *.pl export PERL_MM_USE_DEFAULT=1 cpan install File::Slurp.pm install Net::Amazon::EC2.pm install DateTime::Locale.pm install DateTime::TimeZone.pm mv ec2-consistent-snapshot.pl "${dst_dir}"/ cat /proc/partitions fdisk /dev/xvdf fdisk /dev/xvdg fdisk /dev/xvdh fdisk /dev/xvdi mdadm --verbose --create /dev/md0 --level=raid10 --raid-devices=8 /dev/xvdf1 /dev/xvdg1 /dev/xvdh1 /dev/xvdi1 watch cat /proc/mdstat mdadm --detail --scan >> /etc/mdadm.conf mdadm --stop /dev/md0 mkfs.xfs /dev/md0 mdadm --assemble --scan mount -o noatime /dev/md0 /var/mysql yum -y install libaio libaio-devel mysql

Install MySQL server here

CREATE DATABASE `testdb` CHARACTER SET utf8 COLLATE utf8_bin; USE `testdb`; CREATE TABLE `test` ( `id` INT(10) NOT NULL AUTO_INCREMENT, `desc` VARCHAR(255) NULL, `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) COLLATE='utf8_general_ci' ENGINE=innodb; CREATE TABLE `test` ( `id` int(10) NOT NULL AUTO_INCREMENT, `data` varchar(255) DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8

#!/bin/bash while [ 1 ] do mysql -uroot -p'<password>' -h 127.0.0.1 -e "USE testdb; INSERT INTO testdb.test SET data='0123456789';" echo "inserted one row..." sleep 1 done

#!/bin/bash echo "Starting snapshot..." iso_date=$( date --rfc-3339=seconds --utc) /opt/aws/ec2-consistent-snapshot/ec2-consistent-snapshot.pl \ --debug \ --description "${iso_date} JGS snapshot test" \ --aws-credentials-file /root/.awssecret \ --region "us-east-1" \ --freeze-filesystem /var/mysql/ \ --mysql-host 127.0.0.1 \ --mysql-username root \ --mysql-password '<password>' \ --mysql-master-status-file /var/mysql/master_status.txt \ --lock-timeout 5 \ --lock-tries 30 \ vol-22cd9c7b \ vol-a98bdaf0 \ vol-018ddc58 \ vol-c58cdd9c echo "Completed snapshot!"

wget https://raw.github.com/alestic/ec2-consistent-snapshot/master/ec2-consistent-snapshot

After a restart, sometimes the mdvolume changes to a different number, and you need to mount like this:

mount -o noatime /dev/md127 /var/mysql

[Edit]