Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Amazon EC2 API tools should be installed on the instance,
- # especially /usr/local/bin/ec2-create-snapshot
- #
- # MySQL username and password are stored in $HOME/.my.cnf in the
- # usual manner following this format:
- #
- # [client]
- # user=MYUSERNAME
- # password=MYPASSWORD
- #
- # Author:
- #
- # Eric Hammond <ehammond@thinksome.com>
- #
- use strict;
- use DBI;
- BEGIN {
- $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin:/root/bin/ec2-api-tools-1.3-30349/bin';
- }
- my ($mountpoint, $volume_id) = @ARGV;
- die "Usage: $0 XFSMOUNTPOINT VOLUMEID" unless $mountpoint && $volume_id;
- # Get the MySQL username/password from $HOME/.my.cnf and connect
- my ($username, $password);
- open(FH, "$ENV{HOME}/.my.cnf") or die "Unable to open .my.cnf: $!";
- while ( defined (my $line = <FH>) ) {
- $username = $1 if $line =~ m%^\s*user\s*=\s*(\S+)%;
- $password = $1 if $line =~ m%^\s*password\s*=\s*(\S+)%;
- }
- close(FH);
- my $dbh = DBI->connect('DBI:mysql:;host=localhost', $username, $password);
- # Flush, lock, freeze
- $dbh->do(q{ FLUSH TABLES WITH READ LOCK });
- my ($logfile, $position) = $dbh->selectrow_array(q{ SHOW MASTER STATUS });
- system('sudo', 'xfs_freeze', '-f', $mountpoint);
- # Snapshot
- my $snapshot_output = `/root/bin/ec2-api-tools-1.3-30349/bin/ec2-create-snapshot $volume_id`;
- my ($snapshot_id) = ($snapshot_output =~ m%(snap-[0-9a-f]{8})%);
- # Thaw, unlock
- system('sudo', 'xfs_freeze', '-u', $mountpoint);
- $dbh->do(q{ UNLOCK TABLES });
- print $snapshot_id ?
- "$snapshot_id (master_log_file=\"$logfile\", master_log_pos=$position)\n"
- :
- "snapshot FAILED\n";
Add Comment
Please, Sign In to add comment