Archives pour la catégorie ‘LVM’

Xen : sauvegarde d’un VM Windows par LVM + clonage NTFS

root@xen:~# apt-get install ntfsprogs kpartx

Sauvegarde

root@xen:~# lvcreate -s -L1G -nvm_backup /dev/vg/xen_vm
root@xen:~# kpartx -a /dev/vg/xen_vm_backup
root@xen:~# ls -l /dev/mapper/vg-xen_vm_backup*
lrwxrwxrwx 1 root root      7 Oct 24 12:21 /dev/mapper/vg-xen_vm_backup -> ../dm-6
lrwxrwxrwx 1 root root      7 Oct 24 12:22 /dev/mapper/vg-xen_vm_backup1 -> ../dm-9
root@xen:~# ntfsclone -s -o vm-20121024.img /dev/mapper/vg-xen_vm_backup1
root@xen:~# lvdisplay vg/xen_vm > vm-20121024.txt
root@xen:~# kpartx -d /dev/vg/xen_vm_backup
root@xen:~# lvremove vg/xen_vm_backup

Restauration

root@xen:~# kpartx -a /dev/vg/xen_vm
root@xen:~# ntfsclone -r -O /dev/mapper/vg-xen_vm vm-20121024.img
root@xen:~# kpartx -d /dev/vg/xen_vm

MySQL : script de sauvegarde par snapshot LVM

# cat mysql_backup.sh
#!/usr/bin/perl -w

my $host = 'localhost';
my $dbname = 'mysql';
my $user = 'backup';
my $passwd = 'kV6qcZUbH0';
my $vg = 'vg';
my $lv = 'sql';
my $size = '1G';
my $backupdir = '/home/backup/mysql';

### SCRIPT ###

use POSIX;
use DBI;

my $snapshot = $lv . "_" . strftime("%Y%m%d_%H%M%S", localtime);
print "Creating snapshot $snapshot...\n";

$dbh = DBI->connect("dbi:mysql:$dbname;host=$host", $user, $passwd)
or die "Connection error: $DBI::errstr\n";

$dbh->do("SET SESSION AUTOCOMMIT=0");
$dbh->do("FLUSH TABLES WITH READ LOCK");

system("lvcreate -s -L$size -n$snapshot $vg/$lv");

$sth = $dbh->prepare("SHOW MASTER STATUS");
$sth->execute();
while ($row = $sth->fetchrow_hashref) {
 foreach $col (keys %{$row}) {
 print "$col: " . $$row{$col}."\n";
 }
}

$dbh->do("UNLOCK TABLES");

system("mkdir -p $backupdir/tmp");
system("mount /dev/mapper/$vg-$snapshot $backupdir/tmp");
system("tar czf $snapshot.tar.gz -C $backupdir/tmp .");
system("umount /dev/mapper/$vg-$snapshot");
system("rm -fr $backupdir/tmp");
system("lvremove -f $vg/$snapshot");

print "Done.\n";
Haut de page