VMware Cloud Community
kapplah
Enthusiast
Enthusiast

ESX Backup Script

Hello,

I've created for our own purposes a hot backup script for ESX servers. features are:

\- autodetect all VMs to be backed up: You can specify a single VM, save all powered on VMs or simply all VMs on one ESX host

\- send a email to an administrative account if backup was successful or not and send another mail with a summary per ESX host

\- Backups older than a specified period are deleted automatically

\- Uses a ESX storage to transfer the backup files (can be managed via VI Client)

\- Skip VMs with their names stored in a external file

Configuration:

\- store file ESXBackup in /usr/bin and chmod it executable

\- store file sendmail.pl in /usr/bin and chmod it executable

\- open port 25 in ESX firewall if you intend to send mails

\- create storage in ESX GUI (we use NFS storage, which works well)

\- create local Account ESXBackup on each ESX host where you want to run the backup. This account has to be a ESX administrator

\- Modify the configuration section in the ESXBackup script to meet your configuration settings. The config settings should be self-explaining

\- Create a file on your Backup storage with names of VMs which should not be backupped automatically. You can later specify this file at backup time, the named VMs will be skipped

Usage: Log onto the console of the ESX host and run "ESXBackup" without parameters. Some informations will be displayed.

To backup a single VM use this command: "ESXBackup -v VMNAME"

To backup all powered on VMs use that: "ESXBackup -v poweredon"

You may want to use ESXBackup in your crontab, be sure to modify roots crontab "crontab -e -u root" ...

Known bugs and issues:

\- Sometimes backup ends with error code 141. This error indicates, that vcbMounter has created, but not deleted a snapshot. Delete this snapshot manually or the next backup won't run anyway.

\- In our environment, the NFS server seems to be not fast enough to handle the transfer rate some time, so the NFS client (our ESX server) receives an error and the transfer stops. If this is the case use a sync export or your nfs share instead of a async (but this slows down backup time dramatically) or mount the nfs share via ESX console and not as a ESX storage.

\- VMs should not be moved from one ESX host to another during backup.

\- Logiles are stored on /var/log - if you don't use them anymore, delete them manually

\- Be aware that VM-Names are CASE-sensitiv. If you use the exludelist, write one VM's name per line without spaces and tabs.

Planned enhancements:

\- Detect and delete "lost" \_VCB-SNAPSHOT_ snapshots

\- Retry backup if one VM fails

Note: This script is "at is it" - no warranty or other features. Feature request are welcome. This was my first "more-than-a-three-liner" shell script, so many improvements can be made.

If you find this script useful (or not) please let me know ...

Have fun,

Alex

0 Kudos
66 Replies
espi3030
Expert
Expert

Alex,

New issue, after the copy is successful when I register the VM in a new datacenter I am prompted to Create or Keep the UUID. No matter what option I choose the VM does not power on, I get "A file cannot be found" error. Any suggestions on that?

0 Kudos
roodi
Contributor
Contributor

does this script work on 3.5? sorry i am new to all of this. Also do anyone have step by step info on how to do this?

0 Kudos
BBergmann
Contributor
Contributor

Hope this Script is not dead, i think it is one of the best ways to backup virtual machines. We have an Open-E ISCSI-Filer for backups and the script works fine when i start it from console. But we noticed some problems backing up the machines at high load times, so i decided to plan the backups in a special order. Therefore i wrote a batch like /root/ESXBackup -v vm1 -r 3 -l 3 -t 1 && /root/ESXBackup -v vm2 ....... and scheduled it with cron. The account ist always root, but now the script does not run correctly. Sometimes it does not start, some times it starts and tries to backup the first machine, sometimes it also tries the second. What am i doing wrong.

startESXBackups looks like this (i have different files for different groups of VMs):

#!/bin/bash

/root/ESXBackup -v vm1 -r 3 -l 3 -t 1 -m ADDRESS &&

/root/ESXBackup -v vm2 -r 3 -l 3 -t 1 -m ADDRESS &&

/root/ESXBackup -v vm3 -r 3 -l 3 -t 1 -m ADDRESS

crontab looks like this:

30 21 * * 1 /root/startESXBackupSYS > /root/log/cronSYS.log 2>&1

0 Kudos
NLodoen
Contributor
Contributor

I am having the exact same problem as Bonduelle where the script is hanging on the purge/find command and can't figure it out. About the only possible cause that I can think of is that my backups are going to a very slow NFS attached NAS device and perhaps it is not responding in a timely manner to the find command. I am running the ESXBackup script multiple times out of a shell script which is called by cron. This script simply runs the ESXBackup script once for each of four or five VMs sequentially and it seems to always hang on the second or third VM - even if I switch the order of the VMs around. If anyone else has run into a similar problem and has figured it out I'd like to hear from you. Thanks.

Nathan

0 Kudos
lamw
Community Manager
Community Manager

Check out this backup script, it's compatible with both ESX and ESXi

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

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

--William

VMware ESX/ESXi scripts and resources at:

0 Kudos
ollivetti
Contributor
Contributor

Hi, first of all thank you for the hard work - unfortunately I get this strange error:

Error: Could not find host abc.abc.de on this VirtualCen

ter instance.

The hostname of the esx is correct so I don't really understand the problem.

Maybe you can support me... to solve the problem...

Thank's

Regards

0 Kudos
BBergmann
Contributor
Contributor

Is there anybody out there still using this script? Out Backups seem to run, but suddenly it stops sending mails. On each reboot or disconnection of the Open-E iSCSI-Filer i get the mails that all backups failed.

0 Kudos