Tuesday, September 11, 2007

VMware on NFS: Backup Tricks

Ok, so if you've decided to use VMware over NFS. Then there's always some guy who's find something to neatpick about and so he'll say "Well, can't run VCB on NFS". He's right but I don't see this as an issue? Sometimes it takes imagination to find a solution to a challenge.

Using NFS as a protocol on VMware you have similar choices and flexibility as with VCB and you can mount the NFS volume or a snapshot of the volume on a server other an ESX...Other = Linux in this case.

So if you are deploying VMware on NFS here's a way to backup whole VMDK images or files within VMDKs using Netapp Snapshots given that the Snapshots are accessible to the NFS client.

Mind you that with this approach you do all kinds of cool things and not just backups without impacting the ESX host. You can also restore, or you could also provision...

So here's the process:

1) Install the Linux NTFS driver if it's not already in your Linux built.

Note: For RHEL and Fedora installs click on the About RedHat/FC RPMs

2) Mount the export onto your linux server
# mount xx.xx.xx.xx:/vol/nfstest /mnt/vmnfs

So now you can backup VMDK images or you can drill into the .snapshot directory and back them up from there.

Next step is to backup files within VMDKs by accessing the snapshot...and you get to pick from which one. For this test, I select from the hourly.3 the snapshot named testsnap

3) Mount the VMDK as a loopback mount specifying the starting offset (32256) and NTFS file system type

# mount /mnt/nfstest/.snapshot/hourly.3/testsnap/nfs-flat.vmdk /mnt/vmdk -o ro,loop=/dev/loop2,offset=32256 -t ntfs

Here's your NTFS disk as seen from Linux:

# cd /mnt/vmdk
# ls -l

total 786844
dr-x------ 1 root root 0 Dec 19 03:03 013067c550e7cf93cc24
-r-------- 1 root root 0 Sep 11 2006 AUTOEXEC.BAT-
r-------- 1 root root 210 Dec 18 21:00 boot.ini
-r-------- 1 root root 0 Sep 11 2006 CONFIG.SYS
dr-x------ 1 root root 4096 Dec 18 21:10 Documents and Settings
-r-------- 1 root root 0 Sep 11 2006 IO.SYS
-r-------- 1 root root 0 Sep 11 2006 MSDOS.SYS
-r-------- 1 root root 47772 Mar 25 2005 NTDETECT.COM
-r-------- 1 root root 295536 Mar 25 2005 ntldr
-r-------- 1 root root 805306368 Mar 13 16:42 pagefile.sys
dr-x------ 1 root root 4096 Sep 11 2006 Program Files
dr-x------ 1 root root 0 Sep 11 2006 RECYCLER
dr-x------ 1 root root 0 Sep 11 2006 System Volume Information
dr-x------ 1 root root 0 Dec 19 00:35 tempd
r-x------ 1 root root 65536 Mar 13 17:41 WINDOWS
dr-x------ 1 root root 0 Sep 11 2006 wmpub

The nice thing about the loopback mount is that Linux will see a VMDK's content for any filesystem it recognizes...so now you can backup Windows and Linux VMs.

Here's a more indepth presentation on VMware over NFS including the backup trick from Peter Learmonth as well as a customer presentation from the VMworld breakout sessions. Login and passwords are proivided below:

user name: cbv_rep
password: cbvfor9v9r


Cheers

7 comments:

Christopher Kusek said...

"Install the Linux NFTS driver if it's not already in your Linux built."

You have it listed as NFTS instead of NTFS.

Otherwise, absolutely great read!

Nick Triantos said...

Thanks Christopher. Fixed it.

It'd help if I were to proof read that stuff every now and then.

Steven said...

What about mounting an NTFS volume that has more then one partition, such as drive C and drive D. Also is the same vmdk mounting command used for Linux VM's ?

Nick Triantos said...

If you have an NTFS volume with multiple partitions you need to specify the partition starting offset.

Run msinfo32.exe -> Components -> Storage -> Disks

You will see:

Disk#0 Partition#0 and Disk#0 Partition#1 as well as the partition sizes and the starting offsets for each partition. You then need to specify the offset for each partition as part of the mount command.

For linux you'd have to run "fdisk -lu" to get the partition size in sectors instead of cylinders.

Steven said...

Thanks, that helps...execpt for linux, when i try to mount linux using this command i get

mount /mnt/vmnfs/.snapshot/hourly.0/WEB2051/
WEB2051-flat.vmdk /mnt/vmdk -o ro,loop=/dev/loop2,offset=4203118080 -t ext3

wrong fs type, bad option, bad superblock on /dev/loop2,
missing codepage or other error

then i enter dmesg | tail and get

EXT3-fs: INFO: recovery required on readonly filesystem.
EXT3-fs: write access unavailable, cannot proceed.

I have the correct offset using fdisk -lu, then the value * 512

Nick Triantos said...

Steven,

For linux because it requires RW access, create a flexclone (if you have a netapp box), then mount it without the read-only option. Again, make sure you specify the offset for each partition:

Here's my test:

# mount /mnt/RHEL4U4/RHEL4U4-flat.vmdk -o loop,offset=32256 -t ext3 /vmdk


10.26.89.13:/vol/vmesx01nfsclone
50331648 30877568 19454080 62% /mnt
/mnt/RHEL4U4/RHEL4U4-flat.vmdk
1004024 23496 929524 3% /vmdk

# ls -l /vmdk

[root@linuxvm vmdk]# ls -l /vmdk
total 5644
-rw-r--r-- 1 root root 50333 Jul 12 2006 config-2.6.9-42.EL
-rw-r--r-- 1 root root 49926 Jul 12 2006 config-2.6.9-42.ELsmp
drwxr-xr-x 2 root root 4096 Oct 16 18:20 grub
-rw-r--r-- 1 root root 528540 Oct 16 18:02 initrd-2.6.9-42.EL.img
-rw-r--r-- 1 root root 518279 Oct 16 18:02 initrd-2.6.9-42.ELsmp.img
drwx------ 2 root root 16384 Oct 16 12:58 lost+found
-rw-r--r-- 1 root root 23108 Aug 3 2005 message
-rw-r--r-- 1 root root 21282 Aug 3 2005 message.ja
-rw-r--r-- 1 root root 749462 Jul 12 2006 System.map-2.6.9-42.EL
-rw-r--r-- 1 root root 766260 Jul 12 2006 System.map-2.6.9-42.ELsmp
-rw-r--r-- 1 root root 1504146 Jul 12 2006 vmlinuz-2.6.9-42.EL
-rw-r--r-- 1 root root 1444452 Jul 12 2006 vmlinuz-2.6.9-42.ELsmp

Paul said...

Silly question...in the file permission space, if you do a file level backup via this method, does the backup maintain your ACLs on your files and folders? Does file permissions matter in general in the backup space?