|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-users] snapshot - backup for xen vm's
Nico Kadel-Garcia schrieb: > Ralf Schenk wrote: >> it-news (Josef Lahmer) schrieb: >> >>> dear list, >>> >>> is there a way to make a lvm-snapshot of an running xen-vm to >>> implement a function like "snapshot-backup"? >>> >>> >> - Connect to mysql of VM and issue "FLUSH TABLES WITH READ LOCK;FLUSH >> LOGS" >> >>> #) make snapshot >>> >> - Connect to mysql of VM and issue "UNLOCK tables" >> >>> #) mount snapshot >>> #) copy files >>> #) umount snapshot >>> #) remove snapshot >>> >>> eg (http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html) >>> >>> regards >>> josy >>> >>> interessting: How to mount a XenVM filesystem on XenServer Host: >>> http://kb.xensource.com/entry.jspa?categoryID=14&externalID=162 >>> >> >> Hello ! >> >> I do this every day. I added two points to your plan which I do with a >> small perl script to get consistent Backups of my mysql Databases. I >> also create/destroy the snapshot via this skript and mount the snapshot >> volume. If you are interested I can send it via Mail. >> > Could I talk you into publishing that tool on the list, please? Or > sending me a copy to save me some work? > Hello, there is no secret except that I'm not a real programming guy in the few lines.... Bye -- __________________________________________________ Ralf Schenk fon (02 41) 9 91 21-0 fax (02 41) 9 91 21-59 rs@xxxxxxxxxx Databay AG Hüttenstraße 7 D-52068 Aachen www.databay.de Vorstand: Jens Conze, Ralf Schenk, Aresch Yavari Aufsichtsratvorsitzender: Ansgar Vögeli Sitz/Amtsgericht Aachen HRB:8437 USt-IdNr.: DE 210844202 Databay - einfach machen. _________________________________________________ #!/usr/bin/perl
# Take perfect snapshot of mysql LVM by flushing mysql tables and
# setting a lock while creating the LVM snapshot
#
# usage: $0 (start|stop) [-v]
#
# Configurable
#
$dbi = "mysql";
$dbserver= "server.office.databay.de";
$dbport = "3306";
$dbname = "mysql";
$dbuser = "backup";
$passwd = "JzJe:64xUnrYKQus";
$mysql_vg = "/dev/server";
$mysql_lv = "/vm01";
$snapshot_name = "vm01_snap";
$snapshot_size = "5G";
$snapshot_mountpoint = "/mnt/vm01_snapshot";
#
# Normally you shouldn't change anything below this line
#
#---------------------------------------------------------------------------------------
use Time::Local;
#use POSIX qw(strftime);
use DBI;
my $start = (@ARGV && $ARGV[0] eq 'start');
my $stop = (@ARGV && $ARGV[0] eq 'stop');
my $verbose = (@ARGV && $ARGV[1] eq '-v' && shift);
if ($start) {
#
# Connect to database
#
my $connect = "DBI:".$dbi.":".$dbname.":".$dbserver.":".$dbport;
my $dbh = DBI->connect($connect,
$dbuser, $passwd,
{ RaiseError => 1})
or die "connecting : $DBI::errstr\n";
#
# Flush tables and lock mysql for writing
#
my $start = time;
my $sth = $dbh->do("FLUSH TABLES WITH READ LOCK;");
my $sth = $dbh->do("FLUSH LOGS;");
printf "Flushed and locked tables and logs in %d seconds.\n", time-$start
unless !$verbose;
#
# Create LVM snapshot
#
my $start2 = time;
printf "Executing /bin/sync;/sbin/lvcreate -s -L ".$snapshot_size." -n
".$snapshot_name." ".$mysql_vg."/".$mysql_lv."\n" unless !$verbose;
system("/bin/sync;/sbin/lvcreate -s -L ".$snapshot_size." -n
".$snapshot_name." -p r ".$mysql_vg."/".$mysql_lv);
printf "Created LVM snapshot ".$snapshotname." in %d seconds.\n",
time-$start2 unless !$verbose;
#
# Unlock tables
#
my $start3 = time;
my $sth = $dbh->do("UNLOCK TABLES;");
printf "Unlocked tables in %d seconds.\n", time-$start3 unless !$verbose;
printf "Overall time for snapshot: %d seconds.\n", time-$start unless
!$verbose;
#
# Disconnect from database
#
$dbh->disconnect;
#
# Mount snapshot
#
printf "Executing /bin/mount ".$mysql_vg."/".$snapshot_name."
".$snapshot_mountpoint."\n" unless !$verbose;
system ("/bin/mount ".$mysql_vg."/".$snapshot_name."
".$snapshot_mountpoint);
}
if ($stop) {
printf "Executing /bin/umount ".$mysql_vg."/".$snapshot_name."\n" unless
!$verbose;
system ("/bin/umount ".$mysql_vg."/".$snapshot_name);
printf "Executing /sbin/lvremove -f ".$mysql_vg."/".$snapshot_name."\n";
system ("/sbin/lvremove -f ".$mysql_vg."/".$snapshot_name);
}
exit 0;
#
# Sub routines
#
sub fmtdate {
my $string = shift;
my ($DD, $MM, $YY, $hh, $mm, $ss) = ($string =~ m/(\d+).(\d+).(\d+)
(\d+):(\d+):(\d+)/);
return sprintf strftime("%y-%m-%d %H:%M:%S", $ss, $mm, $hh, $DD, $MM-1,
$YY);
}
sub now {
my ($SEC, $MIN, $HOUR, $DAY, $MONTH, $YEAR) = (localtime)[0..5];
return sprintf ("%04d-%02d-%02d %02d:%02d:%02d", $YEAR+1900, $MONTH+1,
$DAY, $HOUR, $MIN, $SEC);
}
sub epoch {
my $string = shift;
my ($YYYY, $MM, $DD, $hh, $mm, $ss) = ($string =~ m/(\d+)-(\d+)-(\d+)
(\d+):(\d+):(\d+)/);
return timelocal($ss, $mm, $hh, $DD, $MM-1, $YYYY);
}
_______________________________________________ Xen-users mailing list Xen-users@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-users
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |