Script to Backup Exchange Server

REM exchange.txt

D:\Exchange2010\mailbox\TempDatabase
D:\Exchange2010\mailbox\Mailbox-Database-20150403
D:\Exchange2010\mailbox\Public Folder Database 1998117930
REM exchangebackup.bat

echo off

net use S: \\FILESERVER01\backups\EXCHANGE-2010


REM -------------------------------------------------------
REM PARSE THE DATE CODE
REM -------------------------------------------------------
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set weekday=%%a& set month=%%b& set day=%%c& set year=%%d)
echo The day is %WEEKDAY% %DAY%
echo The month is %MONTH%
set DCODE=%MONTH%.%DAY%.%YEAR%.rar
ECHO %DCODE%

REM -----------------------------------------------------------
REM GET THE DATE, AND MAKE A DIRECTORY IN THE BACKUP TREE
REM -----------------------------------------------------------
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do (set cdate=%%a.%%c)
ECHO %cdate%

rem GOTO END_PROGRAM

IF NOT EXIST D:\backup (
ECHO "BACKUP DIR"
MKDIR D:\backup
)

IF NOT EXIST D:\backup\%cdate% (
ECHO "MAKING DIRECTORY"
MKDIR D:\backup\%cdate%
)

REM -----------------------------------------------------------
REM NOTIFY ALL USERS
REM -----------------------------------------------------------
REM net send * "backup service shall begin immediately. exit apps now."

echo you are logged into %COMPUTERNAME%
set RAREXEC="C:\Program Files\WinRAR\WinRar.exe"
set RAREXEC="C:\Program Files\WinRAR\Rar.exe"

set MD5SUMEXEC="C:\SYS\MD5SUM"

GOTO GROUP3

:GROUP3
echo "***************** NT SERVER SHARE 1 ********************"
set EXCLUSION="-x*.m4a -x*.mp3 -x*.ipa -x*.mp3"
ECHO %EXCLUSION%

net stop "Microsoft Exchange Information Store"

%RAREXEC% a -r -m0 D:\backup\%cdate%\exchange2010.%DCODE% @C:\SYS\EXCHANGE.TXT

net start "Microsoft Exchange Information Store"

:END_PROGRAM


rem net use S: /delete
' cleanlogs.vbs

'#################################################################
Option Explicit
On Error Resume Next
Dim oFSO, oFolder, sDirectoryPath
Dim oFileCollection, oFile, sDir
Dim iDaysOld, iAge

' Specify Directory Path From Where You want to clear the old files

sDirectoryPath = "D:\Exchange2010\logs\Mailbox Database 0048122154"

' Specify Number of Days Old File to Delete

iDaysOld = 60

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection

'This section will filter the log file as I have used for for test case
'Specify the Extension of file that you want to delete
'and the number with Number of character in the file extension

If LCase(Right(Cstr(oFile.Name), 3)) = "log" Then

If oFile.DateLastModified < (Date() - iDaysOld) Then
iAge = Date() - oFile.DateLastModified
Wscript.Stdout.Write "Deleting log file: "+oFile.Name + " Age: "
WScript.Echo iAge
oFile.Delete(True)
else
Wscript.Stdout.Write "."
End If

End If
Next

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

'#################################################################

Leave a Reply

Your email address will not be published. Required fields are marked *