
virt_server> p2v.py foo full WORKING WITH SERVER: 'foo' READING CONFIG FOR 'foo' CHECKING LOCAL CONFIG CHECKING LOCAL CONFIG FOR 'foo' COMPLETED SUCCESSFULLY CHECKING REMOTE CONFIG CHECKING NODUMP FLAG: "lsattr -d /home/backupman/dumps | egrep '[\\w-]+d[\\w-]+[ ]/data/dumps'" CHECKING REMOTE DUMP: 'sudo /sbin/dump a0f /dev/null /dev/null' CHECKING IF WE ARE ABLE TO SSH TO: "ssh -T backupman@foo 'if [ -d /data/dumps ] ; then exit 0 ; else exit 1 ; fi'" CHECKING REMOTE CONFIG FOR 'foo' COMPLETED SUCCESSFULLY DUMPING FILESYSTEMS GETTING THE DUMPS STOPPING VM: foo2 MAKING FS TYPE: ext3 ON PARTITION: /dev/mapper/foo RESTORING DUMPS FOR: foo INSTALLING BOOTLOADER FOR: foo RESTORING CONFIG FOR: foo STARTING VM: /etc/xen/foo.xm dump utility. Considerations are as follows:scp , because at our speeds, the network is still the bottleneck, and therefore the cost of encrypting files during transmission is not terriblerestore utility/etc/network/interfaces, /etc/hostname, /etc/mailname, /etc/aliases , etc.)virt_server , as well as a physical server that needs to be cloned, server1 .server1 clone lies on virt_server in /etc/xen/server1.xmserver1 virtual machine is: /dev/mapper/server1server1:/dumps/server1/ in server1:/dumps/server1/ , and copy to virt_server:/dumps/server1server1 'll keep the virt_server:/dumps/server1/cfg/ in virt_server:/dumps/server1/cfg/server1 you need to add the user backupman , and allow him to sudo dump without a password. On virt_server you need to configure key authentication to backupman@server1 . On virt_server we will do everything from under root. root@virt_server> xm destroy server1 root@virt_server> ssh backupman@server1 backupman@server1$ sudo dump -a0f /dumps/server1.root / backupman@server1$ for i in var usr home ; do sudo dump a0f /dumps/server1.$i /$i ; done backupman@server1$ exit root@virt_server> scp backupman@server1:/dumps/server1.* /dumps/server1/ root@virt_server> mkfs.ext4 /dev/mapper/server1 root@virt_server> mount /dev/mapper/server1 /mnt/server1 root@virt_server> cd /mnt/server1 root@virt_server> restore -rf /dumps/server1.root root@virt_server> for i in var usr home ; do cd /mnt/$i && restore /dumps/server1.$i ; done root@virt_server> dd if=/usr/share/syslinux/mbr.bin of=/dev/mapper/server1 root@virt_server> extlinux --install /dev/mapper/server1 root@virt_server> scp -R /dumps/server1/cfg/* /mnt/server root@virt_server> xm start server1.xm dump utilitybackupman userbackupman ALL=NOPASSWD: /sbin/dumpchattr +d directory on this directory so that the dumps are not dumped [server1] vm_config = /etc/xen/server1.xm vm_name = server1 ssh = backupman@server1.site scp = backupman@server1.site dumps_list = /,/var,/usr,/home remote_dumps_dir = /home/bakupman/dumps local_dumps_dir = /dumps/server1 mount_dir = /mnt/server1 partition = /dev/mapper/server1 fs = ext3 ssh and scp . These parameters define the format of the ssh and scp call, respectively, and both are needed because the ssh port will get the -p key, and the scp key will have the -P key. def main(): """Main function, calls all other ones""" if len(sys.argv) < 3: sys.exit('Usage: %s <servername> <action> (check|full|dump|get|restore)' % sys.argv[0]) server = sys.argv[1] action = sys.argv[2] print "\nWORKING WITH SERVER: %r\n" % server if action == "check": try: conf=read_config(server) check_config_local(conf) check_config_remote(conf except Exception, e: sys.exit("\nERROR: %r\n" % e) elif action == "full": try: conf=read_config(server) check_config_local(conf) check_config_remote(conf) stop_vm(conf) dump_physical(conf) get_dumps(conf) restore_vm(conf) install_bootloader(conf) restore_config(conf) start_vm(conf) except Exception, e: cleanup(conf) sys.exit("\nERROR: %r\n" % e) <...>  def check_config_local(conf): """Checks config by trying to ssh, checking existence of local and remote folders, destination partition, mount point, and remote dump utility""" print "\nCHECKING LOCAL CONFIG\n" # check for ensuring we won't delete accidentaly specified host os parittion if conf['partition'] == "/dev/sda" or conf['partition'] == "/dev/sda1" or \ conf['partition'] == "/dev/sda2" or conf['partition'] == "/dev/sda3" or \ conf['partition'] == "/dev/sda4" or conf['partition'] == "/dev/sda5": raise Exception, "DON'T KILL THE SERVER! %S IS A SYSTEM PARTITION!!" % conf['partition'] Source: https://habr.com/ru/post/144655/
All Articles