| How to Automate Backups of VMWare Virtual Machines on a Windows Host Machine |
|
|
|
|
I am a big proponent of virtualization. I have realized that there are various inherent benefits from the technology. A few benefits that I have noticed immediately from using Virtual Machines are
With a virtual machine you can use NAT for network routing or you can use Bridged Mode to allow your virtual machine full access to the entire network. I will now show you a technique that I developed for automating backups of my virtual machine on a dedicated machine across the internet. The base machine powers the guest system down, makes a copy, zips up the copy, then automatically sends a copy of the server via FTP to my local network where I keep copies of the development and production virtual machines. The process is a bit processor intensive as you are zipping up the virtual machine, but it is worthwhile in my situation as I have regular backups which are delivered to me automatically offsite. So here is the process. The secret lies in a series of Windows Batch Files that I created. I set mine up on my second drive D:\ in a folder called BATCH D:\BATCH In there I created a file called BACKUP_VM.BAT These are the contents of that file (Please note you need to replace [YOUR MACHINE FOLDER] with the folder name of your virtual machine and [machine file] with the machine vmx file name. If you have different locations, you will need to change other things as well.) @REM BATCH FILE FOR VM BACKUP @REM delete last nights backup call D:\BATCH\CLEANUP_BAKS.BAT FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B SET date=%mm%%dd%%yyyy% call "C:\Program Files\VMware\VMware Server\vmware-cmd" "D:\VIRTUALMACHINES\[YOUR MACHINE FOLDER]\[machine file].vmx" stop mkdir D:\Backups mkdir D:\Backups\CSI_VM_%date% xcopy /e /y D:\VIRTUALMACHINES\[YOUR MACHINE FOLDER] D:\Backups\CSI_VM_%date% call "C:\Program Files\VMware\VMware Server\vmware-cmd" "D:\VIRTUALMACHINES\[YOUR MACHINE FOLDER]\[machine file].vmx" start call D:\BATCH\ZIP_BACKUPS.BAT rename d:\TEMP\vm_bak.zip vm_bak%date%.zip call D:\BATCH\REMOTE_BAK.BAT What this batch file is doing is it deletes the previous backups first. Then it stops the Virtual Machine. The new folders are created to store the backups. Then, we make a copy of the virtual machine to another folder. We restart the virtual machine and use the copy to create the zip file, which is done in the ZIP_BACKUPS.BAT file. The generic zip file that is created for the backup is then renamed to a backup with today's date on it. Lastly, the REMOTE_BAK.BAT file will upload the backup to my local network. Here are the contents of CLEANUP_BAKS.BAT: rd /s /q "D:\Backups\" del /q d:\temp\*.* Here are the contents of ZIP_BACKUP.BAT: d:\batch\7za a "d:\TEMP\vm_bak.zip" "d:\backups\" (You need to copy the 7zip command line application to the BATCH folder in order for this to work). This will create a vm_bak.zip file with the contents of the backups folder. And now you will need the REMOTE_BAK.BAT contents: ftp -s:d:\batch\ftpRemoteBackup YOURLOCALDOMAIN.COM This command runs the command line ftp program. It calls a an ftp script called "ftpRemoteBackup". You will need to place this file in the same folder. These are the contents of the ftpRemoteBackup file: FTPUSERNAME FTPPASSWORD prompt mput d:\TEMP\vm*.zip close quit You will need to use your own FTPUsername and FTPPassword here. The prompt command assumes that you are not there to answer yes/no and will assume yes for commands. The mput command takes all the virtual machine files in the temp folder and sends them to my local network. This can take quite some time depending on your connection speed. Please feel free to use this method, but please give credit to Clear Sky Innovations, Inc and/or Mauricio Zuniga if you use my technique for automating backups of your virtual machine. |
| < Prev | Next > |
|---|







