ChrisInTexas
Contributor
Contributor

Free ESXi Backup Solution for Windows

I have spent the last few days trying to find a free backup solution to the newly free ESXi for windows only enviroments (in particular Windows XP). The solution for me was the following:

1. Installing Windows Services for UNIX (WSFU)

2. Copying the ESXi Server password and group files to Windows

3. Configuring WSFU for accepting ESX Server connections

4. Sharing the Windows folder for NFS compatibility

5. Configuring the ESXi Server to mount the Window NFS Share as Datastore.

6. Setup Backup Script

Attached is the complete steps.

I take NO credit for any of this. This is just a complation of others work formated to suit my needs and felt others could benift from it as I have.

by Jason Mattox from Vizioncore (direct copy of his work, I just added more information to make it work in Windows XP)

(NFS Server port information)

by robink (The backup script)

(ssh on ESXi)

Tags (3)
0 Kudos
522 Replies
kraemerb
Contributor
Contributor

Hi Lamw

I also switched from perl scripting to ghettoVCB - and it runs great.

Thanks for the lot of work you do here !

I made two small "addons" to your script

1) gzipping target

2) chmod to adjust permissions

Maybe someone also needs this

...

#do not continue until all snapshots have been committed

echo "Removing snapshot from $ ..."+ while ls "$" | grep -q delta; do sleep 3 done INSERT +echo -e "#################### Compressing backup for $####################\n"

INSERT gzip -1 $/*+ INSERT chmod arw $/*

checkVMBackupRotation "$" "$"

...

Since my backups go to a small RAID5-NAS ( QNAP ) my backup speed is limited to 10 MB/s - and the gzip

also needs a lot of time afterwards.

That's okay for me at the moment, but I think about gzipping to a local ESXi datastore and sending the compressed

output to the NFS-Box. This probably would better performance a lot - the drawback is, that you need enough

local storage to holf the largest VM twice ( temporary ).

regards & thanks again !

Bernd

( 3x ESXi @ IBM x346 - 12/8/8 GB RAM, 430/876/656 GB Disk as Raid10 - hosting several SAP Development & Test Systems from 46B up to ECC 60 )

0 Kudos
lamw
Community Manager
Community Manager

Thanks, I'm glad everything is in working order. Just curious, how often are you scheduling your backups?

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
lamw
Community Manager
Community Manager

Hi kraemerb,

Glad the script is working out for your environment as well.

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
kraemerb
Contributor
Contributor

Hi Lamw

I make a ESXi full backup of each SAP instance once a week with your script ( including complete SAP/oracle database )

The database "differentials" are backed up via oracle db redo logs out of the running VM.

Important filesystem changes do not often occur in a SAP environment ( if not SAP kernel/db binary are patched ) so this is okay for me.

regards Bernd

0 Kudos
shechtl
Contributor
Contributor

Hi lamw,

there seems to be a problem like descr. from NoSa in your new enh. version.

I have a vm which was converted from Server 1.0 to Esx. To get better performance I changed the buslogic controller to lsi with a second lsi disk which I later removed.

The remove was with gui, the disk file was delteted. There is now only this old disk reference in the vmx file.

If I have only this vm in the machine reference list backup is working. If there is more then one vm in the refernce list I get this error:

Powering off initiated for cn-portal, backup will not begin until VM is off...

VM is still on - Iteration: 1 - waiting 3secs

VM is still on - Iteration: 2 - waiting 3secs

VM is off

Starting backup for cn-portal ...

Destination disk format: VMFS thick

Cloning disk '/vmfs/volumes/iscsi2dsa1/cn-portal/cn-portal.vmdk'...

Clone: 100% done.

DiskLib_Check() failed for source disk The system cannot find the file specified (25).

Powering back on cn-portal

Completed backup for cn-portal!

Hope you can help

0 Kudos
lamw
Community Manager
Community Manager

Updated: refer to the next post.

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
lamw
Community Manager
Community Manager

I see what the error was, my VMDK array was not resetted, so what happened was it appended the previous VMDK(s) to the current backup. So what happens is it tries to backup the previous VMDK with respect to the path of the current VM. I just posted the fix and upload the new script, sorry about that.

http://communities.vmware.com/docs/DOC-8760

Please let me know if you have any more issues.

=========================================================================

--William

VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

0 Kudos
shechtl
Contributor
Contributor

Hi lamw,

thanks for your fast help.

I tried your new version and my problematic VMs are backing up now perfect.

0 Kudos
lamw
Community Manager
Community Manager

Great to hear

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
odessit
Contributor
Contributor

Thank you lamw for the backup script

I noticed that ESXi has GnuPG installed. Is it possible to add backup encryption option? It is only a one liner...

gpg --encrypt --recipient $PUBLIC_KEY_RECEPIENT $FILE_TO_ENCRYPT

GnuPG also compresses data by default.

Thanks!

0 Kudos
Jsbosch
Contributor
Contributor

Helo Lamw,

Two questions, we are running the latest version of ESXi but we need to restart in order to enable SSH. Is there a method restarting the ssh client/inetservices without reboot? I have too many machines running to want to reboot right now.

I've tested your script on another test ESXi server with a testclient, it seems to work perfectly. I got stuck with a run error at first, but further down the line I read that I had to start the backup with ./backup.sh instead of just typing backup.sh.

I've noticed that it does not copy all the files, I'm worried that this might cause problems with our Back-ups.

Most of our machines are comming from Vmware server by convert, thus it is important that all files are being copied. Right now I've noticed that it does not take the following with the back-up : .vmsd .vmxf and nvram.

I've only back-uped a 8gb machine without a OS, so I will try to convert a machine to this test server and back it up and see if I can restore it.

The main question is, if we do use your script on our production servers, can you answer the following questions :

- Does the script contain any delete lines or anything which could delete a vm or cause any data corruption? Or does it only " copy " ?

- We rather not power down servers to run this back-up script, so we disabled the power vm down option, are there any disadvantages in running the back-up on live machines?

- Let's say we have some servers with 1,2 snapshots in the directory, it does skip ovre these machines right? Is it possible to back them up anyway and take the snapshots with them? The reason why I'm asking this, allot of servers running on our ESXi server have one snapshot (fall back). Your script wouldn't work on half of our servers because I understand that your back-up script skips servers with snapshots? May I ask why?

- Do you have any experience with Windows NFS services? To get ESXi to see the NFS share we had to allow anonymous access. As a microsoft certified engineer, the word "full control, everyone and anoymous" is a no go for me.. especially when complete copies of our servers are located here, anybody could access this share. Do you have any idea's on how I could allow only my ESXi servers to access this NFS share?

Thanks in advance for your replies.

0 Kudos
jlorenzo
Contributor
Contributor

When i tried this script from my windows machine i received this error:

C:\Archivos de programa\VMware\VMware VI Remote CLI\bin>copia.pl

2009-01-09 09:47:14 ***** Script Start *************************

2009-01-09 09:47:14

-


Create Snapshots of running VM's

-


Operation :: Snapshot SnapProject for virtual machine Snt_vm1 created sucessfully under host esxi

Operation :: Snapshot SnapProject for virtual machine Sntvm2 created sucessfully under host esxi

Operation :: Snapshot SnapProject for virtual machine vima-ovf-124830 created sucessfully under host esxi

2009-01-09 09:47:31

-


Copy VM files to local storage

-


GET unsuccessful : 500 Internal Server Error

GET unsuccessful : 500 Internal Server Error

2009-01-09 09:47:39

-


Remove Snapshots of running VM's

-


Operation :: Remove Snapshot SnapProject For Virtual Machine Snt_v1 under host esxi completed sucessfully

Operation :: Remove Snapshot SnapProject For Virtual Machine Sntv2 under host esxi completed sucessfully

Operation :: Remove Snapshot SnapProject For Virtual Machine vima-ovf-124830 under host esxi completed sucessfully

2009-01-09 09:47:56 ***** Taring files **************************El formato del parámetro no es correcto: "snt_v1".

El formato del parámetro no es correcto: "sntv2".

2009-01-09 09:47:56 ***** Script End ***************************

How can i know the correct port for the URL? i did not changed it..

Thanks

0 Kudos
lamw
Community Manager
Community Manager

Hi Jsbosch,

To enable SSH as of ESXi 3.5u2, the method is slightly different than ESXi 3.5/3.5u1 but it does not require a reboot of the host.

You can find out how on my site and here is the link located at: http://engr.ucsb.edu/~duonglt/vmware/#esxi_ssh

In terms of backing up the other files, they're not required for the backup process. You can find more detail information about each type of file located at: http://www.vmware.com/support/ws5/doc/ws_learning_files_in_a_vm.html

The script allows you to backup either a running virtual machine, by taking a snapshot of the system, which unlocks the VMDK disk for read and directs all changes to delta file. This then allows you to "vmkfstools" copy the disk to your backup storage, along with the .vmx or VM descriptor file. Once the backup has successfully finished for all disks, the snapshot will be removed and the changes will be merged back into the VM.

The script also allows you to backup a VM in an power off state, in which it will initiate a guestOS shutdown or hard power off if you enable the feature. It will then backup the VM and since it's off, there is no need to take a snapshot and once the backup process is complete, it will power on the VM.

Again, the 2nd backup process is optional, most users have used the script while the VM is live. The restore process is pretty easy as you can either vmkfstools copy the VM back or mount your backup storage, browse the datastore and register your VM and bring it online in just a few minutes.

In terms of advantages/disadvantages of running live backups, I know some have recommended not to backup systems that constantly changes like database or exchange server. It'll depend on the type of system, if an application makes constant changes, your snapshot can grow pretty quickly.

So currently, the script will skip over VMs that have previous snapshots (these snapshots should not be kept for long durations), it's not a best practice, especially if they continue to grow in size. It's best they're committed back to the VM, and this process can be few minutes to few hours. The script will also skip over VMs with RDMs. For compatibility on both ESX/ESXi server, the script utilizes "vimsh" as the toolset to complete most of the automation, one downside to the snapshot functionality of one of the command is the explicit passing of index value to specify which snapshot to remove. I only bring this up because if you have other snapshots, the "index" value in which the snapshot is to be removed will differ. So to backup a VM with snapshots is possible, but you'll need to modify the script to fit your environment.

To your last question, no I don't have any experience in setting up Windows NFS services, I know many on this thread have, you could ask or search the VMTN forums or even MSFT.

Hopefully this answered your question and good luck with setting up your backup process. Remember to test in a development environment or dev VM prior to putting this into production Smiley Happy

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
HarisB
Contributor
Contributor

Hi all,

Running the script gives me below output (with devel_mode set to 1). Nothing is backed up, I tried creating a snapshot on one VM to trigger echo command saying there is snapshot, no changes.

This is running the latest "enhanced" script, and without NFS enabled (so only local backup for now). Config first, then output:

Any ideas?

*************************************************

  1. directory that all VM backups should go (e.g. /vmfs/volumes/SAN_LUN1/mybackupdir)

VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/VMBackup_Snapshots

  1. Split VMDK into 2GB sparse files 1=yes, 0=no

ENABLE_2GB_SPARSE=0

  1. Number of backups for a given VM before deleting

VM_BACKUP_ROTATION_COUNT=3

  1. Directory naming convention for backup rotations (please ensure there are no spaces!)

VM_BACKUP_DIR_NAMING_CONVENTION="$(date +%F)"

  1. Shutdown guestOS prior to running backups and power them back on afterwards

  2. This feature assumes VMware Tools are installed, else they will not power down and loop forever

  3. 1=on, 0 =off

POWER_VM_DOWN_BEFORE_BACKUP=0

  1. enable shutdown code 1=on, 0 = off

ENABLE_HARD_POWER_OFF=0

  1. if the above flag "ENABLE_HARD_POWER_OFF "is set to 1, then will look at this flag which is the # of iterations

  2. the script will wait before executing a hard power off, this will be a multiple of 3

  3. (e.g) = 4, which means this will wait up to 12secs before it just powers off the VM

ITER_TO_WAIT_SHUTDOWN=10

##########################################################

  1. NON-PERSISTENT NFS-BACKUP ONLY

  2. ENABLE NON PERSISTENT NFS BACKUP 1=on, 0=off

ENABLE_NON_PERSISTENT_NFS=0

  1. umount NFS datastore after backup is complete 1=yes, 0=no

UNMOUNT_NFS=0

  1. IP Address of NFS Server

NFS_SERVER=172.30.0.195

  1. Path of exported folder residing on NFS Server (e.g. /some/mount/point )

NFS_MOUNT=/nfsshare

  1. Non-persistent NFS datastore display name of choice

NFS_LOCAL_NAME=nfs_storage_backup

  1. Name of backup directory for VMs residing on the NFS volume

NFS_VM_BACKUP_DIR=mybackups

*********************************************************

Output :

/vmfs/volumes/4949de4d-50790a18-c2a3-001a64c78e08/VMBackup_Scripts # ./VMBackup_Script.sh VMs_To_Backup_List.txt

##########################################

Virtual Machine: VM-BACKUP

VM_ID: 224

VMX_PATH: /vmfs/volumes/datastore1/VM-BACKUP/VM-BACKUP.vmx

VMX_DIR: /vmfs/volumes/datastore1/VM-BACKUP

VMX_CONF: VM-BACKUP/VM-BACKUP.vmx

VMFS_VOLUME: datastore1

##########################################

##########################################

Virtual Machine: VS-POS

VM_ID: 256

VMX_PATH: /vmfs/volumes/datastore1/VS-POS/VS-POS.vmx

VMX_DIR: /vmfs/volumes/datastore1/VS-POS

VMX_CONF: VS-POS/VS-POS.vmx

VMFS_VOLUME: datastore1

##########################################

##########################################

Virtual Machine: VS-VPN

VM_ID: 64

VMX_PATH: /vmfs/volumes/datastore1/VS-VPN/VS-VPN.vmx

VMX_DIR: /vmfs/volumes/datastore1/VS-VPN

VMX_CONF: VS-VPN/VS-VPN.vmx

VMFS_VOLUME: datastore1

##########################################

Start time: Sat Jan 10 01:08:08 UTC 2009

End time: Sat Jan 10 01:08:09 UTC 2009

Duration : 1 Seconds

Completed backing up specified Virtual Machines!

/vmfs/volumes/4949de4d-50790a18-c2a3-001a64c78e08/VMBackup_Scripts #

0 Kudos
lamw
Community Manager
Community Manager

The outcome is in line with the configuration. You've enabled the "DEVEL_MODE" variable from 0 to 1, this is meant for development purposes and troubleshooting. No backups will take place. If you open the file you'll see that this variable is part of the "do not modify" section.

If you change the variable back to 0 as by default, your backups should take place. Hope this answers your question

btw, you didn't like our script name "ghettoVCB.sh", I see that you've modified it Smiley Wink

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
HarisB
Contributor
Contributor

Hi,

I'll have to test this on Monday, I think I modified devel_mode in an attempt to see what's going on. The first attempts failed with some error message about being unable to get VMID or something, but that turned out to be ^M characters at the end of each line in backup list.

On a side note, about 18 months ago I modified VCB scripts to accept "exclusion" list of VMs, rather than "inclusion". This means less maintenance in growing environment, you don't have to remember to specifically include newly created VMs in backup. I wonder if a simple change can be implemented at some point to list all VMs from the host and back them up UNLESS they are on the exclusion list. Nothing like trying to restore a production VM and realizing it was never backed up because someone forgot to include it in the list - yikes!

Or has this been included in latest changes? I'm just skimming through release notes...

And yes, I modified the name - I'm setting this up for a company as a contractor and the word "ghetto" would likely raise eyebrows once I hand this over to others Smiley Happy

Thanks

0 Kudos
aelus
Contributor
Contributor

When I try to start the backup script, I get the following notification:

/vmfs/volumes/c02cd51c-186b18c5/scripts/SK-VM-3012 # ./VCB_SK-VM-3012.sh vmlist_
Error: failed to extract VM_ID for AOE8SER!
Error: failed to extract VM_ID for Solaris_10_TEST!
Error: failed to extract VM_ID for SYS18SER!
Error: failed to extract VM_ID for VK-APP-3010!
Error: failed to extract VM_ID for VK-APP-9021!
Error: failed to extract VM_ID for VK-DC-3002!
Error: failed to extract VM_ID for VK-PC-9045!
Start time: Mon Jan 12 14:56:08 UTC 2009
End time: Mon Jan 12 14:56:09 UTC 2009
Duration : 1 Seconds
Completed backing up specified Virtual Machines!

Does anybody else got this failure? In which case this error appears?

0 Kudos
lamw
Community Manager
Community Manager

Are you executing this on ESX/ESXi 3.5+ ?

You can also execute the script with the following to get some debug information:

sh -x ./VCB_SK-VM-3012.sh vmlist_

There is also a flag named DEVEL_MODE, you can change that from 0 to 1 and provide the output for one of the VMs that failed to extract the VmId value.

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
HarisB
Contributor
Contributor

@Aelus : see the post above yours, I've had the same problem, editing script in windows introduces ^M character at the end of each line, you must use something to remove it. Notepad++ does it nicely, just make sure you set the option in preferences to use Unix style saving.

Apart from above recommendation to have "exclusions" list rather than "inclusions", I'd like to propose another addition to the script: Compression/reduction before moving to another datastore.

The problem we all have is that exporting thick vmdks will get us nowhere fast because we may have 16GB vmdk which ESXRanger will backup within 1.5 GB, saving precious backup time and destination disk space. I'm sure we can do this with either gzip on the fly or by using vmkfstools to export the vmdk. I'm far from feeling comfortable in implementing either of these options myself, but hope there is common interest in getting this into the new version of ghettoVCB (there I said it Smiley Happy).

Thanks

0 Kudos
lamw
Community Manager
Community Manager

In terms of an inclusion/exclusion list, that is something more specific to your environment and specifically, to your customer's environment. I would imagine when new VMs are provisioned, it would go through some type of change control or document processes prior to "automatically" assumed to be backed up. I would also think that different VMs may have different type of backup schedules, some more frequent than others.

Again, this script was created to provide a simple backup solution for both ESX/ESXi 3.5+, procedural changes can be added/modified to fit any operating environment. This also goes the same for the compression, if you require it, you can always add a line at the end to zip up the backedup directory (take a look at some previous post about adding compression).

Since you're providing this solution to your customer as a consultant, it's definitely best that you're able to fully support them with any changes they may need, especially if they run into any issues or require new use cases.

Good luck

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos