<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:clearspace="http://www.jivesoftware.com/xmlns/clearspace/rss" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>VMware Communities: Message List - Linux LVM Snapshot VM Backup Script</title>
    <link>http://communities.vmware.com/community/vmtn/server/server1?view=discussions</link>
    <description>Most recent forum messages</description>
    <language>en</language>
    <pubDate>Thu, 08 Oct 2009 13:59:51 GMT</pubDate>
    <generator>Clearspace 1.10.12 (http://jivesoftware.com/products/clearspace/)</generator>
    <dc:date>2009-10-08T13:59:51Z</dc:date>
    <dc:language>en</dc:language>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/1384783?tstart=0#1384783</link>
      <description>&lt;br /&gt;
Hi,&lt;br /&gt;
&lt;p /&gt;
 can anyone give me an indication on how much extra space you need for snapshot for a machine (in percentages that is).  I guess it's related to how much the files change in that timespan, but this is really hard to predict with VMware.&lt;br /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
Thank you,&lt;br /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
Bart</description>
      <pubDate>Thu, 08 Oct 2009 13:59:51 GMT</pubDate>
      <author>bcnx</author>
      <guid>http://communities.vmware.com/message/1384783?tstart=0#1384783</guid>
      <dc:date>2009-10-08T13:59:51Z</dc:date>
      <clearspace:dateToText>1 month, 2 weeks ago</clearspace:dateToText>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/997801?tstart=0#997801</link>
      <description>It all depends what you mean by "should work right". Snapshot would complete successfully. Would that snapshot be worth anything? That depends.</description>
      <pubDate>Sat, 19 Jul 2008 18:47:19 GMT</pubDate>
      <author>Peter_vm</author>
      <guid>http://communities.vmware.com/message/997801?tstart=0#997801</guid>
      <dc:date>2008-07-19T18:47:19Z</dc:date>
      <clearspace:dateToText>1 year, 4 months ago</clearspace:dateToText>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/997743?tstart=0#997743</link>
      <description>so I can ignore the "suspending" part of that scrip and it still should work right</description>
      <pubDate>Sat, 19 Jul 2008 15:54:23 GMT</pubDate>
      <author>allenby</author>
      <guid>http://communities.vmware.com/message/997743?tstart=0#997743</guid>
      <dc:date>2008-07-19T15:54:23Z</dc:date>
      <clearspace:dateToText>1 year, 4 months ago</clearspace:dateToText>
      <clearspace:replyCount>1</clearspace:replyCount>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/997570?tstart=0#997570</link>
      <description>Yes.&lt;br /&gt;
&lt;br /&gt;
It also possible to power-off VM without running shutdown.</description>
      <pubDate>Sat, 19 Jul 2008 00:27:18 GMT</pubDate>
      <author>Peter_vm</author>
      <guid>http://communities.vmware.com/message/997570?tstart=0#997570</guid>
      <dc:date>2008-07-19T00:27:18Z</dc:date>
      <clearspace:dateToText>1 year, 4 months ago</clearspace:dateToText>
      <clearspace:replyCount>2</clearspace:replyCount>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/997491?tstart=0#997491</link>
      <description>is it possible to do the snapshot with out suspending the vm?</description>
      <pubDate>Fri, 18 Jul 2008 21:16:16 GMT</pubDate>
      <author>allenby</author>
      <guid>http://communities.vmware.com/message/997491?tstart=0#997491</guid>
      <dc:date>2008-07-18T21:16:16Z</dc:date>
      <clearspace:dateToText>1 year, 4 months ago</clearspace:dateToText>
      <clearspace:replyCount>3</clearspace:replyCount>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/963316?tstart=0#963316</link>
      <description>&lt;br /&gt;
Is this a script tied to VM Server or is this a tool that could be used with ESX ?  Where are the LVM snapshots being created inside the VMs or on VM Server or ESX ?&lt;br /&gt;
&lt;p /&gt;
&lt;br /&gt;</description>
      <pubDate>Wed, 04 Jun 2008 21:34:42 GMT</pubDate>
      <author>postonra</author>
      <guid>http://communities.vmware.com/message/963316?tstart=0#963316</guid>
      <dc:date>2008-06-04T21:34:42Z</dc:date>
      <clearspace:dateToText>1 year, 5 months ago</clearspace:dateToText>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/901816?tstart=0#901816</link>
      <description>You should be able to backup the files to any location by either modifying the &lt;b&gt;my $backupdir = "/vm/Backups/daily";&lt;/b&gt; variable or by mounting an nfs or cifs share to /vm/Backups/daily.</description>
      <pubDate>Tue, 01 Apr 2008 14:59:29 GMT</pubDate>
      <author>gordho</author>
      <guid>http://communities.vmware.com/message/901816?tstart=0#901816</guid>
      <dc:date>2008-04-01T14:59:29Z</dc:date>
      <clearspace:dateToText>1 year, 7 months ago</clearspace:dateToText>
      <clearspace:replyCount>1</clearspace:replyCount>
    </item>
    <item>
      <title>Re: Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/885579?tstart=0#885579</link>
      <description>Thanks for your script. I have been meaning to do something like this for a while now, but never came round to it. Could you please give us some more details on what it does? I have had a quick look at the script and this is what I understand (correct me if I am wrong):&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;the local server name, username and password need to be filled in&lt;/li&gt;
&lt;li&gt;it automatically enumerates all the vm&lt;/li&gt;
&lt;li&gt;vm which are running are first suspended (via vmware), a lvm snapshot is taken, and then the vm is resumed via vmware&lt;/li&gt;
&lt;li&gt;the backup uses the vmware files directly, or from the lvm snapshot (when needed)&lt;/li&gt;
&lt;li&gt;backups with tar+gzip goes to a local file&lt;/li&gt;
&lt;li&gt;lvm snapshots are deleted once the backup is completed&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
A few comments/requests:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;using lzop compression instead of gzip would put much less stress on the server by compressing faster (~80%) and with only ~10% extra space required; an option to choose between lzop and gzip would be useful&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;can the backups go somewhere else than the local server, and if so, how?&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;an exclude list of vm would be useful&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;same for the possibilty to run the script to backup only 1 specific vm&lt;/li&gt;
&lt;/ul&gt;</description>
      <pubDate>Thu, 13 Mar 2008 14:46:53 GMT</pubDate>
      <author>arman68</author>
      <guid>http://communities.vmware.com/message/885579?tstart=0#885579</guid>
      <dc:date>2008-03-13T14:46:53Z</dc:date>
      <clearspace:dateToText>1 year, 8 months ago</clearspace:dateToText>
      <clearspace:replyCount>2</clearspace:replyCount>
    </item>
    <item>
      <title>Linux LVM Snapshot VM Backup Script</title>
      <link>http://communities.vmware.com/message/885108?tstart=0#885108</link>
      <description>I thought it might be useful to someone so I'm posting the perl script I use to do daily backups of my Virtual Machines.&lt;br /&gt;
&lt;br /&gt;
The script handles running machines by suspending them, taking an LVM snapshot, then resuming the VM and doing a backup of the snapshot. This gives me a window of less than 60 seconds of downtime per running virtual machine. You will need to customize this to your own LVM volume names, paths, etc.&lt;br /&gt;
&lt;p /&gt;
Note: The editor seems to modify the text so I have attached the script. &lt;br /&gt;
&lt;p /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
#&lt;br /&gt;
&lt;p /&gt;
&lt;ol&gt;
&lt;li&gt;VM Server Virtual Machine Snapshot Backups&lt;/li&gt;
&lt;/ol&gt;
#&lt;br /&gt;
&lt;br /&gt;
use VMware::VmPerl;&lt;br /&gt;
use VMware::VmPerl::VM;&lt;br /&gt;
use VMware::VmPerl::Server;&lt;br /&gt;
use VMware::VmPerl::ConnectParams;&lt;br /&gt;
use File::Basename;&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
my $backupdir = "/vm/Backups/daily";&lt;br /&gt;
my $log_file = "/var/log/vmware/vmbackup.log";&lt;br /&gt;
&lt;br /&gt;
my ($server, $vm);&lt;br /&gt;
&lt;br /&gt;
my $server_name = undef;&lt;br /&gt;
my $user        = undef;&lt;br /&gt;
my $passwd      = undef;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Use the default port of 902.  Change this if your port is different.&lt;/li&gt;
&lt;/ol&gt;
my $port = 902;&lt;br /&gt;
&lt;br /&gt;
open LOG, "&amp;gt;&amp;gt;$log_file";&lt;br /&gt;
log_stuff( "Starting backups" );&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Connect to VMware Server&lt;/li&gt;
&lt;/ol&gt;
#&lt;br /&gt;
my $connect_params = VMware::VmPerl::ConnectParams::new($server_name,$port,$user,$passwd);&lt;br /&gt;
$server = VMware::VmPerl::Server::new();&lt;br /&gt;
&lt;br /&gt;
if (!$server-&amp;gt;connect($connect_params)) {&lt;br /&gt;
my ($error_number, $error_string) = $server-&amp;gt;get_last_error();&lt;br /&gt;
log_stuff( "Connect to server: $error_number: $error_string\n" );&lt;br /&gt;
die "Could not connect to server: Error $error_number: $error_string\n";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Get list of Virtual Machines&lt;/li&gt;
&lt;/ol&gt;
#&lt;br /&gt;
my @vmlist = $server-&amp;gt;registered_vm_names();&lt;br /&gt;
if (!defined($vmlist[0])) {&lt;br /&gt;
my ($error_number, $error_string) = $server-&amp;gt;get_last_error();&lt;br /&gt;
log_stuff( "get_vms: $error_number: $error_string" );&lt;br /&gt;
die "Could not get list of VMs from server: Error $error_number: $error_string\n";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Virtual Machine Backup&lt;/li&gt;
&lt;/ol&gt;
#&lt;br /&gt;
foreach my $conf (@vmlist) {&lt;br /&gt;
my ($name,$vmdir,$suffix) = fileparse($conf, '\..*' );&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;connect to virtual machine&lt;/li&gt;
&lt;/ol&gt;
$vm = VMware::VmPerl::VM::new();&lt;br /&gt;
if (!$vm-&amp;gt;connect($connect_params, $conf)) {&lt;br /&gt;
my ($error_number, $error_string) = $vm-&amp;gt;get_last_error();&lt;br /&gt;
log_stuff( "Connect to $conf: $error_number: $error_string\n" );&lt;br /&gt;
die "Could not connect to $conf: Error $error_number: $error_string\n";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Get the virtual machine display name&lt;/li&gt;
&lt;/ol&gt;
my $displayName = $vm-&amp;gt;get_config("displayName");&lt;br /&gt;
$displayName =~ s/&lt;a class="jive-link-adddocument" href="http://communities.vmware.com/community-document-picker.jspa?communityID=&amp;subject=%5C%28%29"&gt;\()&lt;/a&gt;//g;  # remove special characters&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Build the path for the backup filename&lt;/li&gt;
&lt;/ol&gt;
my $backup = "$backupdir/$displayName.tar.gz";&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Get the current state for the virtual machine&lt;/li&gt;
&lt;/ol&gt;
my $state =  $vm-&amp;gt;get_execution_state();&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Log what we are doing&lt;/li&gt;
&lt;/ol&gt;
log_stuff( "$displayName: Starting backup" );&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;handle virtual machines that are running by using lvm snapshot with a suspend&lt;/li&gt;
&lt;/ol&gt;
if ( $state eq VM_EXECUTION_STATE_ON )&lt;br /&gt;
{&lt;br /&gt;
log_stuff( "$displayName: Suspending Virtual Machine" );&lt;br /&gt;
if (!$vm-&amp;gt;suspend()) {&lt;br /&gt;
my ($error_number, $error_string) = $vm-&amp;gt;get_last_error();&lt;br /&gt;
log_stuff( "suspend $conf: $error_number: $error_string\n" );&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
log_stuff( "$displayName: Creating LVM Snapshot" );&lt;br /&gt;
log_stuff( `lvremove -f /dev/data/vmsnapshot` );&lt;br /&gt;
log_stuff( `lvcreate -L9.85G -s -n vmsnapshot /dev/data/vmware` );&lt;br /&gt;
&lt;br /&gt;
log_stuff( "$displayName: Resuming Virtual Machine" );&lt;br /&gt;
if (!$vm-&amp;gt;start()) {&lt;br /&gt;
my ($error_number, $error_string) = $vm-&amp;gt;get_last_error();&lt;br /&gt;
log_stuff( "start $conf: $error_number: $error_string\n" );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
log_stuff( "$displayName: Mounting LVM Snapshot" );&lt;br /&gt;
log_stuff( `mount -t ext3 -v -r /dev/data/vmsnapshot /mnt` );&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;fix directory to use the snapshot instead of the actual file&lt;/li&gt;
&lt;/ol&gt;
$vmdir =~ s!/vm/Machines!/mnt!g;&lt;br /&gt;
log_stuff( "$displayName: Backup $vmdir -&amp;gt; $backup.tmp" );&lt;br /&gt;
log_stuff( `tar czpf $backup.tmp -C $vmdir .` );&lt;br /&gt;
&lt;br /&gt;
log_stuff( "$displayName: Removing LVM Snapshot" );&lt;br /&gt;
log_stuff( `umount -v /mnt` );&lt;br /&gt;
log_stuff( `lvremove -f /dev/data/vmsnapshot` );&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;regular backup of suspended or offline machines&lt;/li&gt;
&lt;/ol&gt;
log_stuff( "$displayName: Backup $vmdir -&amp;gt; $backup.tmp" );&lt;br /&gt;
log_stuff( `tar czpf $backup.tmp -C $vmdir .` );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
log_stuff( "$displayName: Moving $backup.tmp to $backup" );&lt;br /&gt;
log_stuff( `mv -vf $backup.tmp $backup` );&lt;br /&gt;
log_stuff( "$displayName: Backup Completed" );&lt;br /&gt;
$vm-&amp;gt;disconnect();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;/ol&gt;
#&lt;br /&gt;
sub log_stuff&lt;br /&gt;
{&lt;br /&gt;
my $msg = shift();&lt;br /&gt;
&lt;br /&gt;
if ( $msg )&lt;br /&gt;
{&lt;br /&gt;
chomp($msg);&lt;br /&gt;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);&lt;br /&gt;
printf LOG "%4d-%02d-%02d %02d:%02d:%02d $msg\n", $year+1900,$mon+1,$mday,$hour,$min,$sec;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Destroys the server object, thus disconnecting from the server.&lt;/li&gt;
&lt;/ol&gt;
$server-&amp;gt;disconnect();&lt;br /&gt;
undef $server;&lt;br /&gt;
&lt;br /&gt;
log_stuff( "Completed backups" );&lt;br /&gt;
close LOG;</description>
      <pubDate>Thu, 13 Mar 2008 00:11:21 GMT</pubDate>
      <author>bradsjm</author>
      <guid>http://communities.vmware.com/message/885108?tstart=0#885108</guid>
      <dc:date>2008-03-13T00:11:21Z</dc:date>
      <clearspace:dateToText>1 year, 8 months ago</clearspace:dateToText>
      <clearspace:replyCount>8</clearspace:replyCount>
    </item>
  </channel>
</rss>

