Please help modify this script to add directory capability


Author
Message
joseph
joseph
Talented Member
Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)Talented Member (111 reputation)
Group: Forum Members
Posts: 38, Visits: 90
I'd like to modify the vbs script below, which is a standard script generated by Reflect, so that it backs up not to a fixed directory, but rather one that  includes the month&year.  The purpose is to restrict retains to a single directory.
Right now it it backups to a fixed directory of E:\reflect\joseph\(IMAGEID)-00-00.mrig
I'd like it to backup to a directory that is the same, but has the moth+year,lets call it newvar in this way
E:\reflect\joseph\newvar\(IMAGEID)-00-00.mrig
Newvar could be in the short alphabetic month name, ex:feb, and the year as 4 digits , ex;2016
I thought it would be easy but.... hopefully it is for someone.
-----------------------vbs script follows-------------------

'* Input:   None
'*
'* Output:  None
'*
'******************************************************************************
Sub VBMain()
    Dim objShell
    Dim ExitCode

' Elevate this script for Admin privileges in Vista
    Elevate

    Set objShell = WScript.CreateObject("WScript.Shell")

' Do the backup
    ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE> ""C:\Users\joseph\Documents\Reflect\joseph_image.xml""")

' done
    Set objShell = nothing
    wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose:  Calls Reflect.exe passing an XML BDF as a parameter
'*
'* Input:    strCmdLine Command Line Arguments
'* Output:   Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
    Dim objShell
    Dim objExecObject
    Dim iReturnCode

    strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
    Set objShell = WScript.CreateObject("WScript.Shell")
    iReturnCode = objShell.Run(strCmdLine, 1, true)

    if iReturnCode = 2 then
' Handle XML validation error

    elseif iReturnCode = 1 then
' Handle backup error
    elseif iReturnCode = 0 then
' Everything OK
    end if
    Backup = iReturnCode
    Set objShell = nothing
End Function


'******************************************************************************
'* Sub:     Elevate
'*
'* Purpose: Elevates this script for Vista UAC.
'*          This means that only one UAC Elevation prompt is displayed and
'*          functions/programs will not fail if they require admin privileges
'*
'* Input:   None
'* Output:  None
'*
'******************************************************************************
Sub Elevate
    Dim ShellApp
    Dim objShell
    Dim objWshProcessEnv

    ' Don't elevate if run from Windows Task Scheduler
    If WScript.Arguments.Count > 0 Then
        If WScript.Arguments.Item(0) = "-s" then
              Exit Sub
        End If
    End If

    Set objShell = WScript.CreateObject("WScript.Shell")
    Set objWshProcessEnv = objShell.Environment("PROCESS")

    If objWshProcessEnv("ELEVATED_APP") <> "True" Then
        objWshProcessEnv("ELEVATED_APP") = "True"
        Set ShellApp = CreateObject("Shell.Application")
        Call ShellApp.ShellExecute("""" &  WScript.FullName  & """", """" & WScript.ScriptFullName & """" & " " & GetBackupTypeParameter,  , "runas")
        set ShellApp = nothing
        Set objWshProcessEnv = nothing
        wscript.quit
    End If
    Set objWshProcessEnv = nothing
    Set objShell = nothing
End Sub

'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose:  determines the backup type from command line parameter
'*           -full Full backup
'*           -inc  Incremental backup
'*           -diff Differential backup
'*
'* Input:    None
'* Output:   the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
        If Wscript.Arguments(i) = "-full" OR _
           Wscript.Arguments(i) = "-inc" OR _
           Wscript.Arguments(i) = "-diff" Then
            GetBackupTypeParameter = Wscript.Arguments(i)
            Exit Function
        End If
    Next

    GetBackupTypeParameter  = ""

End Function


RayG
RayG
Advanced Member
Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)
Group: Forum Members
Posts: 241, Visits: 1.1K
Hi Joseph

I have a script that I can change to create move the current directory to some other name and then create a new directory for the next backup. This could easliy be done on a monthly basis.

I can let you have a copy of the current one if you wanted to give it a try. It also names the files with a date/time but that is constant between two full backups - this is an MR limitation. It will also save a text file along with the backup that will also indicate what type (full, diff or inc) the backup is along with the date/time that backup actually happened e.g.
In the text file: WIN10-X64 #2016-04-20-17-00#-00-00-full.txt you would have the following content:
The backup type was        : -full
The date and time was      : 2016-04-20 @ 17:00:25
The parameters were        : -shutdown
The file set name is       : WIN10-X64 #2016-04-20-17-00#*.*
The destination drive      : W:\Macrium Backup\Win10-x64\
The drive label            : Macrium
Drive Size:[1024.00 GB] Free Space:[684.19 GB]

and the next file: WIN10-X64 #2016-04-20-17-00#-01-01-inc.txt has the following content
The backup type was        : -inc
The date and time was      : 2016-04-25 @ 17:33:41
The parameters were        : -shutdown
The destination drive      : W:\Macrium Backup\Win10-x64\
The drive label            : Macrium
Drive Size:[1024.00 GB] Free Space:[688.29 GB]




Regards
RayG
Windows10 X64 V1803 B17134.48 MR v7.1.3196

Drac144
Drac144
Expert
Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)Expert (622 reputation)
Group: Forum Members
Posts: 393, Visits: 1.3K
You could create the newvar thusly:
Newvar=monthname(month(date),True)+cstr(year(date))

After the above the Newvar variable will have the month name abbreviation and the year. You could then use this to "build" a path name. for example:
path="E:\backups\"+newvar+"\"

You can use that anywhere in your script that you want to specify the path to your date named folder.
Note that "date" as use in the above code is a VBScript function that returns today's date.  So today the newvar above would be: Apr2016


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search