Backup Hyper-V
It is possible to backup a Hyper-V server without taking it down using the Hyper-V VSS writer.
The way I do it is with a small batch file that is run as a scheduled task. The command is quite simple.
WBADMIN START BACKUP -backupTarget:”\\SERVER\BACKUP_SHARE” -user:DOMAIN\USERNAME -password:PASSWORD -include:C:,D: -vssFull -quiet > c:\Backup\hyperbackup.log
As you can see the command is output to a text file located at c:\Backup\hyperbackup.log so that you can check the progress.
As I will always forget to check on it I set another scheduled task to run a VBS file to e-mail the log to me.
This is the vbscript I use.
Const cdoSendUsingPickup = 1 ‘Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 ‘Send the message using the network (SMTP over the network).Const cdoAnonymous = 0 ‘Do not authenticate
Const cdoBasic = 1 ‘basic (clear-text) authentication
Const cdoNTLM = 2 ‘NTLMDim arrFileLines()
i = 0
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile(“LOCATIONOFFILETOEMAIL“, 1)Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.CloseSet objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “SUBJECT”
objMessage.From = “”"FROM“” <FROM@DOMAIN.co.uk>”
objMessage.To = “TO@DOMAIN.co.uk”For l = Ubound(arrFileLines)-10 to Ubound(arrFileLines)
‘ write the output to the file
objMessage.TextBody = objMessage.TextBody + arrFileLines(l) + VbCrLF
Next‘objMessage.TextBody = “This is some sample message text..” & vbCRLF & “It was sent using SMTP authentication.”
objMessage.AddAttachment “LOCATIONOFFILETOEMAIL”‘==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “SMTPSERVER”‘Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = cdoBasic‘Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “USERNAME”‘Your password on the SMTP server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “PASSWORD”‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25‘Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = False‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60objMessage.Configuration.Fields.Update
‘==End remote SMTP server configuration section==
objMessage.Send
To save having to open the attachment the last ten lines (or so!) are in the body of the e-mail. This allows you to see if the backup has been successful or failed at a glance.
