#!/usr/bin/perl -w use strict; use Sys::Virt; my ($local,$remote) = undef; eval { $local = Sys::Virt->new( uri => 'qemu:///system' ); }; if ($@){ # No connection to the local libvirt # We can't do anything die 'Error connecting to libvirt on URI: qemu:///system: '. $@; } eval { $remote = Sys::Virt->new( uri => 'qemu+ssh://fws@peer/system' ); }; if ($@){ # No connection to the remote server # Let's try to managed save all running domain foreach my $dom ($local->list_all_domains()){ next unless $dom->is_active; $dom->managed_save(); } } else{ # We have a connection to both the local and # the remote libvirt. Lets try to migrate # all our running domain to our friend foreach my $dom ($local->list_all_domains()){ next unless $dom->is_active; $dom->migrate($remote, Sys::Virt::Domain::MIGRATE_LIVE | Sys::Virt::Domain::MIGRATE_PEER2PEER | Sys::Virt::Domain::MIGRATE_TUNNELLED); } }