Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

virtual server backup

Posted on 2008-10-13
6
Medium Priority
?
599 Views
Last Modified: 2012-06-27
looking for a reason as to why the fallowing script will not give the reason why the xcopy failed
any info will be helpfull thanks
Set objShell = CreateObject ("WScript.Shell")
 
'local computer computer name
strTime = "local computer"
 
'net use share name
strNetShare= "share name here"
 
'backup computer name
strRemotepc = "ipaddress here"
 
'backup freenas server name
strnasdevice = "computer name here"
 
'location for the daily backup
strold = "W:"
 
'backup location for the old files
strolderfiles = "ip address here"
 
'backup directory drive
strBackupDrive= "Z:"
 
'Drive containing Virtual Machines
strVMdrive = "E:" 
 
'VM folder path
strVMfolder = "\virtual"
 
'available drive letter used to mount shadow copy
strTempDrive = "x:"
 
'nas device drive
strnas = "N:"
'nas computername
strnascomputer = "nas name here"
'nas sharename
strnasdevice ="nas share here"
 
'shadow command file
sExCmd = "CreateVSS.cmd"
 
'logs for program
sLog = "logs.txt"
 
'cleanup file
scleanup = "cleanup.cmd"
 
 
'email variables
'-------------------------------
 
'email address 1
stremail1 = "bla2@bla.com"
 
'email address 2
stremail2 = "bla@bla.com"
 
'from host email
strfrom = "backup@bla.com"
 
'mailserver
strmailserver = "mail.bla.com"
 
'message subject
strsubject= "bla backup"
 
'===================YOU SHOULD NOT NEED TO CHANGE ANYTHING BELOW THIS LINE========================================
 
 
 
 
 
 
dim result
'get the day of week
'---------------------------------
dtmTargetDate = date()  
intDay = WeekDay(dtmTargetDate)
if intDay= 1 then
strday = "Sun"
end if
if intDay= 2 then
strDay = "Mon"
end if
if intDay= 3 then
strDay = "Tues"
end if
if intDay= 4 then
strDay = "Wed"
end if
if intDay= 5 then
strDay = "thurs"
end if
if intDay= 6 then
strDay = "fri"
end if
if intDay= 7 then
strDay = "Sat"
end if
'---------------------------------
'get the week number 1-6
'-------------------------------------------------
dtmDay = DatePart("d", dtmTargetDate)
dtmMonth = DatePart("m", dtmTargetDate)
dtmYear = DatePart("yyyy", dtmTargetDate)
dtmStartDate = dtmMonth & "/1/" & dtmYear
dtmStartDate = CDate(dtmStartDate)
intWeekday = Weekday(dtmStartDate)
intAddon = 8 - intWeekday
intWeek1 = intAddOn
intWeek2 = intWeek1 + 7
intWeek3 = intWeek2 + 7
intWeek4 = intWeek3 + 7
intWeek5 = intWeek4 + 7
intWeek6 = intWeek5 + 7
'-------------------------
'get the day of the week
'-------------------------
If dtmDay <= intWeek6 Then
    strTime1 = "Week 6"
End If
If dtmDay <= intWeek5 Then
    strTime1 = "Week 5"
End If
If dtmDay <= intWeek4 Then
    strTime1 = "Week 4"
End If
If dtmDay <= intWeek3 Then
    strTime1 = "Week 3"
End If
If dtmDay <= intWeek2 Then
    strTime1 = "Week 2"
End If
If dtmDay <= intWeek1 Then
    strTime1 = "Week 1"
End If
 
'--------------------------------------------------
 
'daily backup
stroldbackup = strold &"\"& strDay
 
' Backup target folder or UNC path
strBackupDir = strBackupDrive &"\" & strTime
 
'log file creation
set FileSys = CreateObject("Scripting.FileSystemObject")
if FileSys.FileExists(sLog) then FileSys.DeleteFile(sLog)
set oLog = FileSys.CreateTextFile(sLog,CopyOverwrite)
 
'write all vars to the log file for verfication
olog.writeline("local computer computer name: "& strTime)
olog.writeline("backup computer name: "& strRemotepc)
olog.writeline("backup freenas server name: "&strnasdevice)
olog.writeline("location for the daily backup: "&strold)
olog.writeline("backup directory drive: "&strBackupDrive)
olog.writeline("Drive containing Virtual Machines: "&strVMdrive)
olog.writeline("VM folder path: "& strVMfolder)
olog.writeline("available drive letter used to mount shadow copy: "& strTempDrive)
olog.writeline("nas device drive: "& strnas)
olog.writeline("shadow command file: "& sExCmd)
olog.writeline("logs for program: "& sLog)
 
 
'place time of day in file
olog.writeline("backup created at" &date &" "& time)
 
'create commands for shadow copy
Set oFileSys = CreateObject("Scripting.FileSystemObject")
if oFileSys.FileExists(sExCmd) then oFileSys.DeleteFile(sExCmd)
set oExCmd = oFileSys.CreateTextFile(sExCmd, CopyOverwrite)
 
' Create Shadow copy of VM drive
oExCmd.WriteLine "set startdate=%date%"
oExCmd.WriteLine "set starttime=%time%"
oExCmd.WriteLine "vshadow.exe -script=setvar1.cmd -p " & strVMdrive
oExCmd.WriteLine "call setvar1.cmd"
oExCmd.WriteLine "vshadow.exe -el=%SHADOW_ID_1%," &strTempDrive
oExCmd.WriteLine "net use "&strBackupDrive&" \\"&strRemotepc&"\"&strNetShare
oExCmd.WriteLine "net use "&strnas&" \\"&strnascomputer&"\"&strnasdevice
oExCmd.WriteLine strnas
oExCmd.WriteLine "mkdir " & strTime1
oExCmd.WriteLine "net use "&strold&" \\"&strolderfiles&"\V_M_backup"
oExCmd.WriteLine "dir "&strold
oExCmd.WriteLine "dir "&strBackupDrive
oExCmd.WriteLine "dir "&strnas
oExCmd.WriteLine strBackupDrive
oExCmd.Close
 
'run shadow copy
'result = read_lines(sExCmd)
'if u want to log the shadowcopy data please uncomment above line and then comment between the lines
'---------------------------------------------
 set objExecObject = objShell.exec(sExCmd)
  Do Until objExecObject.StdOut.AtEndOfStream
   strLine = objExecObject.StdOut.ReadLine()
   strIP = Instr(strLine,"Address")
  Loop
'---------------------------------------------
olog.writeline("shadow copy completed at "& Month(Now) & "-" & Day(Now) & "-" & Year(Now) &_
  "_" & hour(now) & "-" &  minute(now))
'create backup of old data every day
olog.writeline ""
olog.writeline ""
olog.writeline "--------------------old files data-----------------------------"
olog.writeline "moving old files to the backup directory time is now "& Time
olog.writeline ("xcopy "&strBackupDir &" " &stroldbackup&" /s /i /y")
result = read_lines("xcopy "&strBackupDir &" " &stroldbackup&" /s /i /y")
olog.writeline "finnished moving old data at " & Time
olog.writeline "--------------------end of old files move----------------------"
olog.writeline ""
olog.writeline ""
 
'weekly backups only runs on firday 
'intday = 1-6
'1 = Sunday
'2 = Monday
'3 = Tuesday
'4 = Wendsday
'5 = Thursday
'6 = Friday
'7 = Saturday
 
if intDay = 6 then
olog.writeline "preparing for nasbackup"
'start backup to nas device
olog.writeline ""
olog.writeline ""
olog.writeline "-----------------------friday backup data----------------------------"
olog.writeline "backup for freenas started at"& time
olog.writeline ("xcopy "&strTempDrive&strVMfolder& " " &strnas&"\"&strTime1&" /s /i /y")
result = read_lines("xcopy "&strTempDrive&strVMfolder& " " &strnas&"\"&strTime1&" /s /i /y")
olog.writeline "backup to freenas ended at" & time
olog.writeline "-----------------------friday data ended-----------------------------"
olog.writeline ""
olog.writeline ""
end if
 
 
'startbackup
olog.writeline "-------------------------virtual server data----------------------"
olog.writeline "backup to vs2 started at"& time
olog.writeline "xcopy "&strTempDrive&strVMfolder& " " &strBackupDir&" /s /i /y"
result = read_lines("xcopy "&strTempDrive&strVMfolder& " " &strBackupDir&" /s /i /y")
olog.writeline "backup to vs2 ended at" & time
olog.writeline "-------------------------virtual sever data end-------------------"
olog.writeline ""
olog.writeline ""
 
'cleanup starts
 
Set oFileSys1 = CreateObject("Scripting.FileSystemObject")
set oExCmd1 = oFileSys.CreateTextFile(scleanup, CopyOverwrite)
oExCmd1.writeline "Echo y | vshadow.exe -da"
oExCmd1.writeline "net use "& strBackupDrive &" /delete"
oExCmd1.writeline "net use "& strnas &" /delete"
oExCmd1.writeline "net use "& strold&" /delete"
oExCmd1.writeline "Echo y | del C:\setvar1.cmd"
oExCmd1.writeline "Echo y | del C:\CreateVSS.cmd"
oExCmd1.writeline "Echo y | del C:\cleanup.cmd"
oExCmd1.close
result = read_lines("C:\cleanup.cmd")
 
'email
result = read_lines("C:\sendEmail.exe -f "&strfrom&" -u "&strsubject&" -t "&stremail2&" -o message-file=C:\logs.txt -s "&strmailserver)
result = read_lines("C:\sendEmail.exe -f "&strfrom&" -u "&strsubject&" -t "&stremail1&" -o message-file=C:\logs.txt -s "&strmailserver)
 
'-------------function that will launch the exe / bat ect. to read the output to a text file creating a log
Function read_lines(x)
 set objExecObject = objShell.exec(x)
  Do Until objExecObject.StdOut.AtEndOfStream
   strLine = objExecObject.StdOut.ReadLine()
   strIP = Instr(strLine,"Address")
   oLog.WriteLine strLine
  Loop
End Function
oLog.Close

Open in new window

0
Comment
Question by:03671328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Author Comment

by:03671328
ID: 22706840
other info that i didnt add...
runing windows 2003 server enterprice in a domain controler enviremnet.

example of the log output



local computer computer name: vs1
backup computer name: 10.0.0.60
backup freenas server name: Internal_backup
location for the daily backup: W:
backup directory drive: Z:
Drive containing Virtual Machines: E:
VM folder path: \virtual
available drive letter used to mount shadow copy: x:
nas device drive: N:
shadow command file: CreateVSS.cmd
logs for program: logs.txt
backup created at10/13/2008 3:13:00 PM
shadow copy completed at 10-13-2008_15-13
 
 
--------------------old files data-----------------------------
moving old files to the backup directory time is now 3:13:32 PM
xcopy Z:\vs1 W:\Mon /s /i /y
Z:\vs1\Log Server.vhd
0 File(s) copied
 
finnished moving old data at 3:53:51 PM
--------------------end of old files move----------------------
 
-------------------------virtual server data----------------------
backup to vs2 started at3:53:51 PM
xcopy x:\virtual Z:\vs1 /s /i /y
X:\virtual\bla\bla.vhd
X:\virtual\bla\bla.vmc
X:\virtual\bla\bla.vsv
X:\virtual\freenas\backup.vhd
X:\virtual\freenas\data.vhd
X:\virtual\freenas\freenas.vmc
X:\virtual\freenas\freenas.vsv
X:\virtual\freenas\_backup.vhd
X:\virtual\linux\dyndnslinux.vmc
X:\virtual\linux\linux.vhd
X:\virtual\Log Server\Log Server.vmc
X:\virtual\LOGSERVER\C_2008-10-09T194226.vhd
X:\virtual\LOGSERVER\LOGSERVER.vmc
X:\virtual\LOGSERVER\LOGSERVER.vsv
X:\virtual\MikroTik\MikroTik.vhd
X:\virtual\MikroTik\MikroTik.vmc
X:\virtual\MikroTik\MikroTik.vsv
X:\virtual\Name Server 1\Name Server 1.vmc
X:\virtual\Virtual Web 1\data.vhd
backup to vs2 ended at4:46:20 PM
-------------------------virtual sever data end-------------------
 
 
 
C:\>Echo y   | vshadow.exe -da 
 
VSHADOW.EXE 2.2 - Volume Shadow Copy sample client
Copyright (C) 2005 Microsoft Corporation. All rights reserved.
 
 
(Option: Delete all shadow copies)
This will delete all shadow copies in the system. Are you sure? [Y/N] 
- Setting the VSS context to: 0xffffffff
- Deleting shadow copy {7b398665-82d0-4c2f-80c2-f22dccdb4af1} on \\?\Volume{727228eb-6f09-4db6-87c3-16609e706842}\ from provider {b5946137-7b9f-4925-af80-51abd60b20d5} [0x00520009]...
 
C:\>net use Z: /delete 
Z: was deleted successfully.
 
 
C:\>net use N: /delete 
N: was deleted successfully.
 
 
C:\>net use W: /delete 
W: was deleted successfully.
 
 
C:\>Echo y   | del C:\setvar1.cmd 
 
C:\>Echo y   | del C:\CreateVSS.cmd 
 
C:\>Echo y   | del C:\cleanup.cmd 
Oct 13 16:46:24 vs1 sendEmail.exe[7416]: Email was sent successfully!
Oct 13 16:46:24 vs1 sendEmail.exe[1748]: Email was sent successfully!

Open in new window

0
 
LVL 3

Assisted Solution

by:pit1140
pit1140 earned 1000 total points
ID: 22720074
may help: i have seen, that moving (maybe copying) the virtual server vhd may have problems when you have vmrc running and the stopped (!) machine is running...

try your script after removing the machine from vmrc.

and use data protection manager - with vss you may get online backups while die vm is running (when windows)! ;)
0
 
LVL 1

Author Comment

by:03671328
ID: 22721286
the whole idea of the script is to make shure the virtual machines stay running. for no down time. So i create a shadow copy then mount it, and copy the data from the shadow to anouther drive. I would like to add why it would error out. as in why it would not copy.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:pit1140
ID: 22721534
what is the specific error of xcopy?
0
 
LVL 1

Author Comment

by:03671328
ID: 22721591
thats what i need to find out it dont say.
0
 
LVL 1

Accepted Solution

by:
03671328 earned 0 total points
ID: 22763670
well i figgured it out need to add the

strerror = objExecObject.StdErr.ReadLine()

to get the error output
Function read_lines(x)
 set objExecObject = objShell.exec(x)
  Do Until objExecObject.StdOut.AtEndOfStream
   strLine = objExecObject.StdOut.ReadLine()
   strerror = objExecObject.StdErr.ReadLine()
   strIP = Instr(strLine,"Address")
   oLog.WriteLine strLine &"             "&strerror
	if strerror="" Then
	else
	errors= errors &strLine&vbCrLf&strerror&vbCrLf&"_________"&time()&"_________"&vbCrLf
	end if
  Loop
'error logging
if strerror="" Then
	   olog.writeline "no errors occured"
	else
  	   olog.writeline ""
  	   olog.writeline ""
  	   olog.writeline "errors"
  	   olog.writeline ""
  	   olog.writeline errors
end if

Open in new window

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction There are many ways to achieving a goal - some are wrong, some are right - and some just appear to be right, but are wrong.  Hyper-V Clustering and VMM has taught me all three, and I'm here to share with you how to avoid the pitfalls…
Introduction Many people don't know about it - and it's almost like a huge secret, but Hyper-V is one of the most cost-effective Virtual solutions out there, and I'll tell you why. In a single word - Licensing. The Breakdown Microsoft gi…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question