1

I have written a script to backup a data directory of our TM1 cube system. The script creates a new folder and copies files across (excluding some files / folders). This works fine.

The script then zips the new folder. This seems to fail after around 10 minutes.

Around 2000 objects are being backed up, including some cube files which are up to 3GB in size. Total is around 7GB before zipping.

I have been testing this on my C: drive with a full copy of files and structure to be backed up. It creates around 350 objects, including some of the cube files, in the zip and then fails.

ERROR: Object required: 'Namespace(...)'

Any ideas?

Here is my script:

' http://stackoverflow.com/questions/15139761/zip-a-folder-up

' ArchiveFolder "E:\Tm1dev9\Backups\Friday.zip", "E:\Tm1dev9\Backups\Friday"


' ***** Varialbles to set ******
'
strWeekday  = weekday(now())-1
strSourceFolder = "C:\Temp\TM1\ZipTesting\TM1_Data"     ' do not use backslash at end
strDestFolder   = "C:\Temp\TM1\ZipTesting\Day" & strWeekday     ' do not use backslash at end
strExclude  = "C:\Temp\TM1\ZipTesting\ExcludeList.txt"
strZipFile  = "C:\Temp\TM1\ZipTesting\Day" & strWeekDay & ".zip"

dim fso
dim objShell
dim blnFinished


Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

CopyFiles
WScript.Sleep 2000
ArchiveFolder strZipFile, strDestFolder



' Copy contents over to a backup folder excluding items in 'ExcludeList.txt'
Sub CopyFiles() 

    If fso.FolderExists(strDestFolder) Then  
        fso.DeleteFolder strDestFolder      
    End If

    If fso.FileExists (strZipFile) Then
        fso.DeleteFolder strZipFile
    End If

    objShell.run "xcopy " & strSourceFolder & "\*.* " & chr(34) & strDestFolder & "\*.*" & chr(34) & " /d /e /c /g /h /r /y /EXCLUDE:" & strExclude , 1, TRUE

End Sub



' Create Zip file from backup folder, then delete backup folder
Sub ArchiveFolder (zipFile, sFolder)

    With CreateObject("Scripting.FileSystemObject")
        zipFile = .GetAbsolutePathName(zipFile)
        sFolder = .GetAbsolutePathName(sFolder)

            With .CreateTextFile(zipFile, True)
            .Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, chr(0))
            End With
    End With

    WScript.Sleep 2000 

    With CreateObject("Shell.Application")

        .NameSpace(zipFile).CopyHere .NameSpace(sFolder).Items

        Do Until .NameSpace(zipFile).Items.Count = _
                    .NameSpace(sFolder).Items.Count
                    WScript.Sleep 1000 
        Loop

    End With

    'WScript.Sleep 1000 

    If fso.FolderExists(strDestFolder) Then  
        fso.DeleteFolder strDestFolder      
    End If

End Sub
freginold
  • 3,946
  • 3
  • 13
  • 28
winshent
  • 13
  • 6
  • Can you tell us what line the error occurred on? The error output should indicate what line... – Tony Hinkle Jun 19 '15 at 13:05
  • @Tony The script errors on this line `Do Until .NameSpace(zipFile).Items.Count = _ .NameSpace(sFolder).Items.Count` – winshent Jun 19 '15 at 14:56
  • Instead of `fso.DeleteFolder strZipFile` should be `fso.DeleteFile strZipFile` or even `fso.DeleteFile strZipFile, True` inside `Sub CopyFiles()`. However, the script works anyway for me: truly, tested on a considerably less file sample... Are there some _unusually_ attributed files, or junctions etc.? – JosefZ Jun 19 '15 at 15:39
  • I've seperated the 'ArchiveFolder ' sub out to an individual script and then run this a couple more times today. I've noticed it occasiionally creates/ deletes a temp file of the zip file 'Day1.zip#RF1a64bc7.TMP'... I now get error messages of 'Missing or Empty zip file'... – winshent Jun 22 '15 at 15:53

0 Answers0