Solved Broken Link in Old Post

September 4, 2012 at 13:55:10
Specs: Windows XP
What happened to the link in Thread #22

http://www.computing.net/answers/pr...

This sounds like a very useful script and after a lot of searching, does appeat to be one of the only places something like this, is located.


See More: Broken Link in Old Post

Report •

✔ Best Answer
September 5, 2012 at 13:00:36
I am the author of the script in question. Per a request from the OP in this thread I have re-posted the original script to the following URL: http://damato.net/dev/backupscript.htm

There were several other features I had started to implement but never got around to completing, But, I continue to get inquiries regarding this script after 6 years, so I might go back and finish those at some point.

Michael J



#1
September 4, 2012 at 16:50:32
It looks like the website disappeared sometime between now and six years ago. The script doesn't look like it did anything robocopy didn't, so you could see if that's a viable replacement.

How To Ask Questions The Smart Way


Report •

#2
September 4, 2012 at 17:14:25
I have been fighting with robocopy on this; integrated into a For loop. It hasn't been going well.

Report •

#3
September 4, 2012 at 17:19:23
You should probably use robocopy to determine what you want to copy, and not a FOR loop.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
September 5, 2012 at 00:43:07
Post your requirement. Maybe we can script it.


====================================
Life is too important to be taken seriously.

M2


Report •

#5
September 5, 2012 at 08:57:13
What I want to do was outlined in the old thread I mentioned previously. I have included it here with a few modifications.

Replication
1. Starts with the source folder and if it doesn't exist on the target, creates zero byte place holders for all folders and files to prevent fragmentation (see /CREATE option in Robocopy).
2. If the source folder does exist on the target it checks the files in that folder and copies any missing files or files with later modified dates to the target.
3. Recurses through all subfolders (all levels) in the source, repeating steps 1 & 2 for each.

Synchronization
4. Starts with target folder and if it does not exist in the source deletes it.
5. If the target folder does exist in source it goes through all files in the target folder and deletes them if they do not exist in the source.
6. Recurses through all sub folders (all levels) in the target, repeating steps 4 & 5 for each.

Notes:
- A silent switch will suppress dialogs used for testing.
- A replicate switch will determine if steps 1-3 are performed.
- A synchronize switch will determine if steps 4-6 are performed.
- The script will process a list of file and folder exclusions.
- Contains switches to bypass hidden files and/or folders.


Here is what I have so far using Robocopy:

set Source=UNC path with spaces
set Destination1=UNC path1 without spaces
rem set Destination2=UNC path2 with spaces
dir "%Source%\59-*" /a:d /b /s >folders.txt (doesn't output subfolders even with /s)
for /f "usebackq delims=, tokens=*" %%A in (folders.txt) do robocopy "%%A" "%Destination1%\%%~nxA" /CREATE /E /L /XF *.bak *.drf *.fix *.htm *.log *.rsc *.s01 *.xls *.avi *.db *.zip *.sat *.msg *.tmp *.err *.txt /R:5 /W:5 /LOG+:c:\LogFile.log

As you can see, I plan on allowing for multiple "Destinations" or targets. Once the tree structure is established, the batch file will repeat the process without the /CREATE option (outlined above).

Perhaps the two following .vbs scripts I found could be tweaked and combined?


Script One came from here.

'Creates zero-byte copies of an entire directory tree

Option Explicit

Main

Sub Main()
Dim fs, strSource, strDest
    Set fs = CreateObject("Scripting.FileSystemObject")
    'Get and verify input arguments (source and destination folders)
    If WScript.Arguments.Count > 2 Then
        Help
        Exit Sub
    End If
    'Get source
    If WScript.Arguments.Count > 0 Then
        strSource = WScript.Arguments(0)
    Else
        strSource = BrowseForFolder("Select source folder") 
    End If
    If Not fs.FolderExists(strSource) Then
        MsgBox "The source folder """ & strSourceFolder & """ does not exist."
        Exit Sub
    End If
    'Get destination
    If WScript.Arguments.Count = 2 Then
        strDest = WScript.Arguments(1)
    Else
        strDest = BrowseForFolder("Select destination folder") 
    End If
    If Not fs.FolderExists(strDest) Then
        MsgBox "The destination folder """ & strSourceFolder & """ does not exist."
        Exit Sub
    End If
    RecurseFiles strSource, strDest
End Sub

Sub RecurseFiles(strSource, strDest)
Dim ts, fs, fils, fil, fol, fols, strFolder
Const ForWriting = 2
    Set fs = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
    'Be sure the destination folder exists
    If Not fs.FolderExists(strDest) Then
        fs.CreateFolder strDest
    End If
    'Check all the source files
    Set fils = fs.GetFolder(strSource).Files
    If Err.Number <> 0 Then Exit Sub
    'Create the zero-byte destination files
    For Each fil In fils
        Status fil.Path
        Set ts = fs.OpenTextFile(fs.BuildPath(strDest, fil.Name), ForWriting, True)
        ts.Close
    Next
    'Check for any sub folders and recursively process them
    Set fols = fs.GetFolder(strSource).SubFolders
    For each fol in fols
        If Lcase(fol.Name) <> "recycled" Then
            RecurseFiles fol.Path, fs.GetAbsolutePathName(fs.BuildPath(strDest, fol.Name))
        End If
    Next
End Sub

Sub Help()
Dim strAlert
    strAlert = "This script will create a zero-byte mirror of a folder. You "
    strAlert = strAlert & "can pass a source and destination folder "
    strAlert = strAlert & "as arguments. If you don't supply arguments, "
    strAlert = strAlert & "you'll be prompted for them. For example:" & vbCrLf
    strAlert = strAlert & WScript.ScriptName & " ""C:\source"" ""C:\dest""" & vbCrLf
    strAlert = strAlert & "would copy everything in and under the C:\source "
    strAlert = strAlert & "folder into the C:\dest folder -- except that all "
    strAlert = strAlert & "files created in the C:\dest folder would be zero "
    strAlert = strAlert & "bytes in size." 
    WScript.Echo strAlert
End Sub

Function BrowseForFolder(strPrompt)
'Uses the "Shell.Application" (only present in Win98 and newer)
'to bring up a file/folder selection window. Falls back to an
'ugly input box under Win95.
'Shell32.ShellSpecialFolderConstants
Const ssfPERSONAL = 5 'My Documents
Const ssfDRIVES = 17 'My Computer
Const SFVVO_SHOWALLOBJECTS = 1
Const SFVVO_SHOWEXTENSIONS = 2 
    Dim sh, fol, fs, lngView, strPath
    Set sh = CreateObject("Shell.Application")
    If Instr(TypeName(sh), "Shell") = 0 Then
    	BrowseForFolder = InputBox(strPrompt, "Select Folder", CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName))
    	Exit Function
    End If
    Set fs = CreateObject("Scripting.FileSystemObject")
    lngView = SFVVO_SHOWALLOBJECTS Or SFVVO_SHOWEXTENSIONS
    strPath = ""
    Set fol = sh.BrowseForFolder(&0, strPrompt, lngView, ssfDRIVES)
    Err.Clear
    On Error Resume Next
    strPath = fol.ParentFolder.ParseName(fol.Title).Path
    'An error occurs if the user selects a drive instead of a folder
    If Err.Number <> 0 Then
        BrowseForFolder = Left(Right(fol.Title, 3), 2) & "\"
    Else
        BrowseForFolder = strPath
    End If
End Function

Sub Status(strMessage)
    If Lcase(Right(Wscript.FullName, 12)) = "\cscript.exe" Then
        Wscript.Echo strMessage
    End If
End Sub

Script Two:

'=========================
' Name:     file_replication.vbs
' Date:     April 3rd, 2006
' Author:    Cale Dunlap (cale.dunlap@trx.com)
' Purpose:    Copies files from one location to multiple locations based on date information
'=========================

'========================= BEGIN GLOBALS
strLogDestination = "C:\scripts\"     ' Destination for the log file
iNumSites = 2     ' Number of desintation locations
strSourceFolder = "\\vappfil007\va_a6cv_ng\259_MatlH\Detailed Design\07-Vendor Data and Drawings"    ' Source location

Dim arrDestinationFolders(1)     ' Array of destinations
ReDim arrDesintationFolders(iNumSites)    ' Redim the array to the appropriate number

' List of all destination locations
arrDestinationFolders(0) = "\\vappfil007\va_a6cv_ng\CAD\259_MATERIAL_HANDLING\DWGVA\Vendor"
'arrDestinationFolders(1) = "\\atl30559\site3"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFolder = objFSO.GetFolder(strSourceFolder)

'========================= END GLOBALS
''''''''''''''''''''''''''
'========================= BEGIN ROUTINES AND FUNCTIONS
Sub WriteLogEntry( strMessage )
    Set objLogFile = objFSO.OpenTextFile(strLogDestination & "replog.txt", 8, True, 0)
    objLogFile.WriteLine Now() & " :: " & strMessage
    objLogFile.Close
End Sub

Sub Replicate( objSource, objDestination )
    ' Copy the files first
    For Each objFile In objSource.Files
        If objFSO.FileExists( Replace(objFile.Path, objSource.Path, objDestination.Path) ) Then
            Set objFileDest = objFSO.GetFile( Replace(objFile.Path, objSource.Path, objDestination.Path) )
            MinutesOld = DateDiff("n", objFile.DateLastModified, objFileDest.DateLastModified)
            If MinutesOld <> 0 Then
                strSourcePath = objFile.Path
                strDestinationPath = objFileDest.Path
                objFSO.CopyFile strSourcePath, strDestinationPath, True
                WriteLogEntry "Copied " & objFile.Path & " to " & objFileDest.Path & " because the source date modified different from the destination date modified."
            End If
        Else
            strSourcePath = objFile.Path
            strDestinationPath = Replace( strSourcePath, objSource.Path, objDestination.Path)

            objFSO.CopyFile strSourcePath, strDestinationPath, True
            WriteLogEntry "Copied " & strSourcePath & " to " & strDestinationPath
        End If
    Next

    ' Copy the folders now
    For Each objSubfolder In objSource.Subfolders
        If Not objFSO.FolderExists( Replace(objSubFolder.Path, objSource.Path, objDestination.Path) ) Then
            objFSO.CreateFolder Replace(objSubFolder.Path, objSource.Path, objDestination.Path)
            WriteLogEntry "Created folder " & Replace(objSubFolder.Path, objSource.Path, objDestination.Path) & " because it existed on the source, but not the destination."
        End If

        Replicate objSubfolder, objFSO.GetFolder( Replace(objSubFolder.Path, objSource.Path, objDestination.Path) )

    Next

End Sub
'========================= END ROUTINES AND FUNCTIONS
''''''''''''''''''''''''''
'========================= BEGIN MAIN PROGRAM
WriteLogEntry("Script Started.")

' Begin the replication
For Each destFolder In arrDestinationFolders
    Set objDestFolder = objFSO.GetFolder(destFolder)
    Replicate objSourceFolder, objDestFolder
Next

' Notify of completion
WScript.Echo "Complete"
WriteLogEntry("Script completed.")
'========================= END MAIN PROGRAM


Report •

#6
September 5, 2012 at 13:00:36
✔ Best Answer
I am the author of the script in question. Per a request from the OP in this thread I have re-posted the original script to the following URL: http://damato.net/dev/backupscript.htm

There were several other features I had started to implement but never got around to completing, But, I continue to get inquiries regarding this script after 6 years, so I might go back and finish those at some point.

Michael J


Report •

#7
September 6, 2012 at 00:39:58
@echo off
rd/s/q d:\bakup
xcopy c:\files d:\bakup\ /s/r/y/d/c/e > nul 2> nul


====================================
Life is too important to be taken seriously.

M2


Report •

#8
September 6, 2012 at 16:58:17
Thank you @mjdamato for posting the link to your script.

@Mechanix2Go - your xcopy script seems simplified compared to what I described.

What is the purpose of having /s and /e in the same line?

Thanks.


Report •

Ask Question