POUWIEL|COM

JeroenPouwiel

HYPER-V :: backup VM’s locally

Running Windows Server 2012 R2 HYPER-V Core but what to do regarding backups..!?

Easy.

Install the Windows Server Backup feature. As I am using HYPER-V Core, I can install the feature using server manager on my laptop.
Than, create a shared folder on my HYPER-V server with:

net share BCK=C:\BCK /GRANT:Everyone,FULL

And finally, backup the virtual machine using wbadmin.exe, like so:

WBADMIN START BACKUP -backupTarget:\\<servername>\BCK -hyperv:<vm_name>

Because I’ve got Swiss cheese for memory, I created a little script to do this for me:

@ECHO OFF

:HOUSEKEEPING
ECHO.

:CHECKFORSWITCHES
IF -%1-==-- (
    ECHO.:: ##########!! WARNING !!##############################################################
    ECHO.:: ## No parameters were passed. Please look through the Usage section
    ECHO.:: ##  & GOTO DISPINFO
) ELSE IF '%1'=='/H' (
    GOTO DISPINFO
) ELSE IF '%1'=='/h' (
    GOTO DISPINFO
) ELSE IF '%1'=='/?' (
    GOTO DISPINFO
) ELSE IF EXIST "C:\VMS\%1" (
    GOTO MAIN
) ELSE (
    ECHO.:: ##########!! WARNING !!##############################################################
    ECHO.:: ## Provided parameter was not recognized/valid. Please look through the Usage section
    ECHO.:: ##  & GOTO DISPINFO    
)

:DISPINFO
ECHO.:: ##########~~ INFORMATION ~~##########################################################
ECHO.:: ## BACKUP
ECHO.::
ECHO.:: Description:
ECHO.::     Backs up a single Virtual Machine to the local shared folder BCK @ \\<servername>\BCK
ECHO.::     The command used is: "WBADMIN START BACKUP -backupTarget:\\<servername>\BCK -hyperv:{vm_name}"
ECHO.::
ECHO.:: Usage:
ECHO.::     c:\Users\Administrator\Documents\backup.bat {vm_name}
ECHO.::
ECHO.:: Parameter List:
ECHO.::     /?             Displays this help message.
ECHO.::     vm_name        When given a vm_name, it will be passed as argument to the wbadmin program
ECHO.::
ECHO.:: Resources:
ECHO.::     WBADMIN        @ https://blogs.msdn.microsoft.com/virtual_pc_guy/2013/02/25/backing-up-hyper-v-virtual-machines-from-the-command-line/
ECHO.::                    @ https://virtualizationreview.com/blogs/virtual-insider/2013/02/back-up-hyper-v-vms.aspx
ECHO.::
ECHO.::     BATCH script   @ http://stackoverflow.com/questions/26551/how-to-pass-command-line-parameters-to-a-batch-file
ECHO.::                    @ http://stackoverflow.com/questions/13684259/show-help-message-if-any-command-line-argument-equals
ECHO.
ECHO.
GOTO :END

:MAIN
set arg1=%1
echo starting "WBADMIN START BACKUP -backupTarget:\\<servername>1\BCK -hyperv:%arg1%"
WBADMIN START BACKUP -backupTarget:\\<servername>\BCK -hyperv:%arg1%
:END



May not be the most elegant of code or robust, but it gets the job done.

//JP

Comments are closed.

Categories