切换到宽版
  • 11038阅读
  • 1回复

[求助]使用脚本对Exchange信息存储进行碎片整理 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-10
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:Visual Basic
  • 适合版本:Exchange 2003
  • 适用平台:
  • 脚本作用:使用些脚本可以对Exchange信息存储进行碎片整理。
使用些脚本可以对Exchange信息存储进行碎片整理,完成自动的工作。

@Echo off
:: ExMaint Version 1.2
:: Matthew Jones -
:: Script must include Exchagne Server name as part of parameter {ie: Scriptname.cmd Servername}
::
:: Purpose: Take Exchange Information Store off-line - Backup EDB and STM file.  Perform Defrag.  Reboot Server
::
:: Why: So I can get some sleep while the Exchange Store does a poor mans defrag.
::
:: Assumpsion 1: The Exchange program is installed to c:\program files\exchsrvr {for eseutil access}
:: Assumption 2: You have enough space in the backup path to accomodate the store backup.
:: Assumption 3: You have the shutdown utility in a common path {i.e: winnt\system32}.
CLS

:: What directory do you want the report to generate in?
set ReportPath=c:\scripts\reports\
if not exist %reportpath% mkdir c:\scripts\reports

set ReportName=%reportpath%%1.txt

:: location to back up EDB and STM files
set backuppath=d:\exchbup\

:: Create backup path if it does not exist
if not exist %backuppath% mkdir %backuppath%

:: location where Exchange Store DB resides
set datalocation=d:\InfoStore\

:: Exchange Store Name
set dataname=priv1.edb

:: location where Exchange Store STM resides
set streamlocation=d:\InfoStore\

:: Exchange STM filename
set streamname=priv1.stm

date /t  > %ReportName%
time /t >> %ReportName%

echo Server Name is : %1 >> %ReportName%
echo Report Path    : %reportpath% >> %ReportName%
echo Report Name    : %reportname% >> %ReportName%
echo                  ---------------- >> %ReportName%
echo Backup Path    : %backuppath% >> %ReportName%
echo Data Location  : %datalocation% >> %ReportName%
echo Data Name      : %dataname% >> %ReportName%
echo Stream Location: %streamlocation% >> %ReportName%
echo Stream Name    : %streamname% >> %ReportName%

echo Server Name is : %1
echo Report Path    : %reportpath%
echo Report Name    : %reportname%
echo                  ----------------
echo Backup Path    : %backuppath%
echo Data Location  : %datalocation%
echo Data Name      : %dataname%
echo Stream Location: %streamlocation%
echo Stream Name    : %streamname%


if %1 == "" goto :errorfound

set ExchServer=%1
echo The Server Name is: %ExchServer%

:StartJob
Echo Stopping the Exchange Store on %ExchServer%
Echo Stopping the Exchange Store on %ExchServer% >> %ReportName%

net stop "Microsoft Exchange Information Store" >> %ReportName%
Echo Exchange Store Stopped
Echo Exchange Store Stopped >> %ReportName%
date /t  > %ReportName%
time /t >> %ReportName%

Echo Delete Old Copy - Backup Production Info Store
if exist %BackupPath%%dataname% del %BackupPath%%dataname%
if exist %BackupPath%%streamname% del %BackupPath%%streamname%
Echo Delete Old Copy - Backup Production Info Store >> %ReportName%

Echo Copy STM File to %backuppath%.
Copy %streamlocation%%streamname% %backuppath%
Echo Copy of STM File Completed. >> %ReportName%
Echo Copy of STM File Completed.

Echo Copy %dataname% to %backuppath%. >> %ReportName%
Echo Copy %dataname% to %backuppath%.
Copy %datalocation%%dataname% %backuppath%
Echo Copy of STM File Completed. >> %ReportName%
Echo Copy of STM File Completed.

if errorlevel = 0 goto :STARTESEUTIL

:failcopy
Echo The Copy process failed - Process aborted!
Echo The Copy process failed - Process aborted! >> %ReportName%
goto :ENDMAINT

:STARTESEUTIL
Echo Starting ESEUTIL
Echo Starting ESEUTIL>> %ReportName%
date /t >> %ReportName%
time /t >> %ReportName%

"c:\program files\exchsrvr\bin\eseutil.exe" /d %datalocation%%dataname%
Echo ESEUTIL Defragmentation Completed >> %ReportName%
Echo ESEUTIL Defragmentation Completed
date /t >> %ReportName%
time /t >> %ReportName%




:StartServices

Echo Starting Microsoft Exchange Information Store
Echo Starting Microsoft Exchange Information Store >> %ReportName%
net start "Microsoft Exchange Information Store" >> %ReportName%
date /t >> %ReportName%
time /t >> %ReportName%

echo Rebooting Server >> %ReportName%
echo Rebooting Server
shutdown /l /r /t:20
goto :ENDMAINT


:errorfound
Echo You did not set a Server name as a parameter of the script.
Echo Please use the Exchange Servername as a parameter in the script.

:ENDMAINT
Echo Script Ended >> %ReportName%
date /t >> %ReportName%
time /t >> %ReportName%
:: notepad %ReportName%


分享到
只看该作者 1楼  发表于: 2014-02-13
感谢诶分享天津海魔方
快速回复
限60 字节
 
上一个 下一个