I have a quick question about my syntax for the below script. I have set a script to ask the end user if they want to backup their files, it maps a network drive to their home directory, and I am trying to use Robocopy to copy all of their files at first, then only copy new/changed files. Everything looks to be running ok, except for robocopy, i get a popup command box then nothing. My script does not show any errors when ran through primalscript but I know that my Syntax for Robocopy is probably wrong.. Can anyone help ???
'File backup Script
Dim backupdriveletter,objnetwork,WshNetwork,strUser,fso,backupfolder,stime,objshell,objFSO
Dim spath,dpath,s0,strpath,WSHShell
'Declarations
Set fso = WScript.CreateObject("Scripting.FileSystemObject") 'Standard File System Object
Set WshNetwork = WScript.CreateObject("WScript.Network") 'Standard Network Object
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
spath = "C:\Documents and Settings\" & strUser & "\My Documents " 'Source Path we will be copying
dpath = backupdriveletter & ":\" & backupfolder 'Destination Path
s0 = "/MIR /XA:SH /XD appData /XJD /R:5 /W:15 /V /NP /M /LOG+:Backup.txt" ' backup switches for Robocopy, including the /m switch to only copy new/modified files
strUser = WshNetwork.UserName 'Pulls User Name, used to find user's profile folder
BackupDriveLetter = "Q" 'The Drive Letter for the users subdirectory on the Application Server.
'Asks to start the backup ******************************************************************************
X=MsgBox(" Good Afternoon todays date is " & Date & " **** Are you currently logged into VPN ?? **** ",36,"My Documents BackUp Utility")
If X = 6 Then 'If MsgBox is answered YES
X=MsgBox("Please press OK to proceed with your file backup",48,"My Documents BackUp Utility")
StartBackup() 'Start main Subroutine
Else
X=MsgBox("Please make sure you first login to VPN before trying again ",48,"My Documents BackUp Utility")
WScript.Quit 'If MsgBox is answered NO
End If
'Main Program ****************************************
Sub StartBackup()
'Check for Backup Drive
If (Not fso.DriveExists(BackupDriveLetter)) Then
Set objnetwork = WScript.CreateObject("WScript.Network")
' You must change the server name to the server where the GroupMarketing users home directory resides
objNetwork.MapNetworkDrive "Q:" , "\\HomeServer\users\" & strUser
End If
' Check to see if the My Documents Path exhists ********************************************************
Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
strPath = "Q:\My Documents"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
Wscript.Echo "The folder exists."
Else
backupfolder = "\My Documents"
FSO.CreateFolder(backupdriveletter & ":\" & backupfolder) 'Create the backupdoc folder
End If
' ******************************************************************************************************
Set WSHShell = CreateObject("Wscript.Shell")
Call WshShell.Run("cmd.exe /c C:\robocopy.exe " & spath & " " & dpath & "-" & ".txt" & " " & s0)
End Sub
'File backup Script
Dim backupdriveletter,objnetwork,WshNetwork,strUser,fso,backupfolder,stime,objshell,objFSO
Dim spath,dpath,s0,strpath,WSHShell
'Declarations
Set fso = WScript.CreateObject("Scripting.FileSystemObject") 'Standard File System Object
Set WshNetwork = WScript.CreateObject("WScript.Network") 'Standard Network Object
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
spath = "C:\Documents and Settings\" & strUser & "\My Documents " 'Source Path we will be copying
dpath = backupdriveletter & ":\" & backupfolder 'Destination Path
s0 = "/MIR /XA:SH /XD appData /XJD /R:5 /W:15 /V /NP /M /LOG+:Backup.txt" ' backup switches for Robocopy, including the /m switch to only copy new/modified files
strUser = WshNetwork.UserName 'Pulls User Name, used to find user's profile folder
BackupDriveLetter = "Q" 'The Drive Letter for the users subdirectory on the Application Server.
'Asks to start the backup ******************************************************************************
X=MsgBox(" Good Afternoon todays date is " & Date & " **** Are you currently logged into VPN ?? **** ",36,"My Documents BackUp Utility")
If X = 6 Then 'If MsgBox is answered YES
X=MsgBox("Please press OK to proceed with your file backup",48,"My Documents BackUp Utility")
StartBackup() 'Start main Subroutine
Else
X=MsgBox("Please make sure you first login to VPN before trying again ",48,"My Documents BackUp Utility")
WScript.Quit 'If MsgBox is answered NO
End If
'Main Program ****************************************
Sub StartBackup()
'Check for Backup Drive
If (Not fso.DriveExists(BackupDriveLetter)) Then
Set objnetwork = WScript.CreateObject("WScript.Network")
' You must change the server name to the server where the GroupMarketing users home directory resides
objNetwork.MapNetworkDrive "Q:" , "\\HomeServer\users\" & strUser
End If
' Check to see if the My Documents Path exhists ********************************************************
Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
strPath = "Q:\My Documents"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
Wscript.Echo "The folder exists."
Else
backupfolder = "\My Documents"
FSO.CreateFolder(backupdriveletter & ":\" & backupfolder) 'Create the backupdoc folder
End If
' ******************************************************************************************************
Set WSHShell = CreateObject("Wscript.Shell")
Call WshShell.Run("cmd.exe /c C:\robocopy.exe " & spath & " " & dpath & "-" & ".txt" & " " & s0)
End Sub