If not IsValidObject(internalobjRegExp) then If not IsValidObject(internalobjFSO) then set internalobjFSO = CreateObject("Scripting.FileSystemObject") 'Return name washes for anything that the filesystem can handleįilenameFix = objRegExp.Replace(sFilename, "-") ObjFSO.CopyFile sSource, sRealDestination, True ![]() If not objFSO.FileExists(sRealDestination) then 'WScript.Echo "Destination: " & sRealDestination Log "Truncated filename to: " & sRealDestination SRealDestination = Left(sRealDestination, 251) & ".eml" Log "Truncated filename from: " & sRealDestination SRealDestination = DESTINATION & sDestination 'Set real destination and trunc it if it exceds 255 chars 'Helper to copy files and overcome filesystem restrictions If not objFSO.FolderExists(DESTINATION & sDir) then InternalobjLog.WriteLine(FixDate(Now) & " " & sText) Log "ValidateFile: Size indifference source: " & objFileSource.size & " and destination: " & objFileDestination.size If not objFileSource.size = objFileDestination.size then Set objFileDestination = objFSO.GetFile(sDestination) Set objFileSource = objFSO.GetFile(sSource) Log "ValidateFile: Destination does not exists" If not objFSO.FileExists(sDestination) then Log "ValidateFile: Source does not exists" 'Creates a directory if it does not existsįunction ValidateFile(sSource, sDestination) 'If there are subfolders, do the next oneĬall RecursiveFolder(oFolder.SubFolders, nSelYear, sFolder & "\", nLevel + 1)ĭim objFSO, objFileSource, objFileDestination Log replace(space(nLevel), " ", "-") & oFolder.Name & " found " & nCountFound & " of " & oMessages.Count & " (" & FormatNumber(nSize / 1024, 2) & " MB)" '& " -> " & nIntCount & "/" & oFld.Count - 1 'Print out the folder, message count and size If Year(CDate(oMessage.InternalDate)) = 0 then 'Loop through each message and sum up the sizes Log replace(space(nLevel), " ", "-") & "Now scanning " & oFolder.Name & " (Total " & oMessages.Count & " messages)" 'Inform the user before we start the scan SFolder = sBaseDir & FilenameFix(oFolder.Name)Ĭall CreateDirectory(nSelYear & "\" & sFolder) ![]() 'Recursize function that will be called again and again until no more subfolders existsįunction RecursiveFolder(oFld, nSelYear, sBaseDir, nLevel)ĭim nIntCount, oFolder, oMessages, oMessage, nSize, nCountFound, sFolder, sFinalDestination, z, sIntSource Log "Total used space: " & oAccount.Size & " MB"Ĭall RecursiveFolder(oFolders, nYear, "\" & oDomain.Name & "\" & oAccount.Address & "\", 0) 'Loop through all domains, accounts and then recursive count all the mailsĬall CreateDirectory(nYear & "\" & oDomain.Name)Ĭall CreateDirectory(nYear & "\" & oDomain.Name & "\" & oAccount.Address) Log "Selected year: " & nYear & " (and older)" Log "Backupscript with delete started " & Now Set oApp = CreateObject("hMailServer.Application", HMSSERVER)Ĭall oApp.Authenticate(HMSADMINUSER, HMSADMINPWD) Set internalobjLog = GetFSO.OpenTextFile(DESTINATION & FixDate(Now) & ".log", 8, True) If nYear 1 then bDelete = false 'No matter what the user enter turn off delete Wscript.echo "Please enter the year with numeric value, eg: 2018" 'Set the year variable and check if it is valid WScript.echo "Will *copy* all emails in users directory hierarchy to the destination" Wscript.echo "Eg: cscript hmailserver-backup.vbs 2019 NODELETE (will just copy all mails from 2019 and older)" Wscript.echo "Eg: cscript hmailserver-backup.vbs 2018 (will copy & delete all mails from 2018 and older)" Wscript.echo "Usage: cscript.exe hmailserver-backup.vbs " ' Backup all mails to a destination and delete the old ones (if applicable)Ĭonst HMSADMINUSER = "Administrator" ' Admin usernameĬonst HMSADMINPWD = "xxxxxxxx" ' Admin passwordĬonst HMSSERVER = "localhost" ' hMailServer Server (host / DCOM)Ĭonst DESTINATION = "D:\Backup-nach-aufreaumen\" ' Destination, remember to end with trail (\)ĭim oApp, oDomain, oAccount, oFolders, internalobjFSO, internalobjRegExp, internalobjLog
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |