Posted On March 31, 2019

Script to Backup Exchange Server

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

PowerShell: HashMap Enumeration Example – Set Active-X on Internet Explorer

function allowActiveX($zone='Trusted'){ #Source: https://learn.microsoft.com/en-us/previous-versions/troubleshoot/browsers/security-privacy/ie-security-zones-registry-entries #Reference table: #Value Setting #------------------------------ #0 My Computer #1 Local Intranet…

PowerShell: check whether the current user is a member of Domain Admins

# short snippet to check whether the currently login user is a domain admin$CurrentUser =…

PowerShell: Get SQL Server Backup Statuses

$computername='sql01' function getSqlBackupInfo ($sqlInstanceName=$env:computername, $dbName){ [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") $location=if($sqlInstanceName.Contains("`\")){ "SQLSERVER:\SQL\$sqlInstanceName\Databases" }else{ "SQLSERVER:\SQL\$sqlInstanceName\DEFAULT\Databases" } function getPacificTime($time){ if($time){ [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($time,'Pacific…