当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 截断 Exchange 日志

作者:精品下载站 日期:2024-12-14 22:30:52 浏览:13 分类:玩电脑

使用 PowerShell 截断 Exchange 日志


Exchange 日志磁盘已满,并且您想要截断 Exchange 日志而不进行备份。但是,如果启用循环日志记录以清除 Exchange 数据库事务日志,则必须在更改生效之前卸载并装载数据库。如果有一种方法可以在不卸载和安装数据库的情况下删除 Exchange 数据库日志怎么办?在本文中,您将了解如何使用 PowerShell 截断 Exchange 数据库日志。

信息

在开始之前,最好知道 Exchange 数据库日志应该在备份运行时截断。如果它无法正常运行,您必须排除故障并查看发生了什么。有时您没有时间,磁盘已满,您需要临时修复来清除 Exchange 数据库日志。

有多种方法可以截断 Exchange 数据库日志:

  1. 启用循环日志记录>卸载数据库>挂载数据库

  2. VSSTester PowerShell 脚本(本文)

这两个选项最终都会做同样的事情; 截断 Exchange 数据库日志。但是,他们的做法存在显着差异

选项 1

您必须启用循环日志记录、卸载数据库并安装数据库,这会导致用户中断。如果邮箱数据库很大并且有 TB 的日志,这将需要时间。另外,除非你有DAG并执行服务器切换,否则你必须在下班后进行。

选项 2

它将保持数据库已安装。这意味着数据库不会离线,用户也不会受到任何干扰。它还将创建数据库和日志卷的快照。

运行脚本之前

目前,邮箱数据库日志量显示只有1,40 GB是免费的。

[玩转系统] 使用 PowerShell 截断 Exchange 日志

准备截断 Exchange 日志 PowerShell 脚本

1. 下载 VSSTester.ps1 PowerShell 脚本:

  • 来自 GitHub 的 Exchange Server 2013/2016/2019 (VSSTester.ps1)

  • Exchange Server 2010 从此处 (VSSTester_v1.2.ps1)

2. 将其保存在 Exchange 服务器上

3. 在 (C:) 驱动器上创建 scripts 文件夹,并将脚本放置在 C:\scripts 中。

[玩转系统] 使用 PowerShell 截断 Exchange 日志

使用 PowerShell 脚本截断 Exchange 日志

要使用 VSSTester PowerShell 脚本截断 Exchange 日志,请按照以下步骤操作:

1. 以管理员身份启动 PowerShell 并运行 VSSTester.ps1 PowerShell 脚本。

PS C:\> C:\scripts\.\VSSTester.ps1

2.有两个选项。我们正在寻找的是选项1。使用内置 Diskshadow 测试备份。

输入1并按Enter

PS C:\> C:\scripts\.\VSSTester.ps1

****************************************************************************************
****************************************************************************************
**                                                                                    **
**                 VSSTESTER SCRIPT (for Exchange 2013, 2016, 2019)                   **
**                                                                                    **
****************************************************************************************
****************************************************************************************



Saturday, October 17, 2020 7:02:38 PM


Please select the operation you would like to perform from the following options:


  1. Test backup using built-in Diskshadow
  2. Enable logging to troubleshoot backup issues


Selection: 1

3.指定目录路径。例如,C:\temp,然后按Enter

Please specify a directory other than root of a volume to save the configuration and output files.
Directory path (e.g. C:\temp): C:\temp

它将验证 Exchange Server 版本和 VSS 编写器状态。之后,它会检查哪些邮箱数据库可用,并询问我们要备份哪一个。

4. 在我们的示例中,我们要清除邮箱数据库 DB02(编号 1)的日志。

输入1并按Enter

Saturday, October 17, 2020 7:09:39 PM
Getting Server name...

--------------------------------------------------------------------------------------------------------------

EX01-2016


Saturday, October 17, 2020 7:09:39 PM
Verifying Exchange version...

--------------------------------------------------------------------------------------------------------------

EX01-2016 is an Exchange 2016 server.


Saturday, October 17, 2020 7:09:43 PM
Checking VSS Writer Status: (All Writers must be in a Stable state before running this script)

--------------------------------------------------------------------------------------------------------------

Writer name: 'Task Scheduler Writer'
   State: [1] Stable

Writer name: 'VSS Metadata Store Writer'
   State: [1] Stable

Writer name: 'Performance Counters Writer'
   State: [1] Stable

Writer name: 'System Writer'
   State: [1] Stable

Writer name: 'ASR Writer'
   State: [1] Stable

Writer name: 'Registry Writer'
   State: [1] Stable

Writer name: 'Shadow Copy Optimization Writer'
   State: [1] Stable

Writer name: 'COM+ REGDB Writer'
   State: [1] Stable

Writer name: 'IIS Metabase Writer'
   State: [1] Stable

Writer name: 'IIS Config Writer'
   State: [1] Stable

Writer name: 'Microsoft Exchange Writer'
   State: [1] Stable

Writer name: 'MSMQ Writer (MSMQ)'
   State: [1] Stable

Writer name: 'WMI Writer'
   State: [1] Stable

Writer name: 'BITS Writer'
   State: [1] Stable



Saturday, October 17, 2020 7:09:45 PM
Getting databases on server: EX01-2016

--------------------------------------------------------------------------------------------------------------


Number Name Mounted Server
------ ---- ------- ------
     0 DB01    True EX01-2016
     1 DB02    True EX01-2016





Select the number of the database to backup : 1

5.检查哪个驱动器未被使用。在我们的示例中,驱动器 X: 未使用,而这正是我们将使用的。

输入X:,然后按Enter

The database guid for 'DB02' is: 313554ce-1503-4f81-8796-4ab0764d80c2

The database is mounted on server: EX01-2016

Saturday, October 17, 2020 7:15:58 PM
Status of 'DB02' and its replicas (if any)

--------------------------------------------------------------------------------------------------------------

DB02\EX01-2016 is Mounted



Saturday, October 17, 2020 7:15:58 PM
Creating diskshadow config file...

--------------------------------------------------------------------------------------------------------------


The selected database path is 'G:\DB02\DB02.edb' so adding volume G: to backup scope


The selected database log folder path is 'H:\DB02' so adding volume H: to backup scope



Adding the volume for DSH file
add volume G: alias vss_test_G
Adding the volume for DSH file
add volume H: alias vss_test_H


Saturday, October 17, 2020 7:15:58 PM
Getting drive letters for exposing backup snapshot
--------------------------------------------------------------------------------------------------------------


Since different volumes are used for this database's EDB and logs, we need two drive
letters to expose the backup snapshot.


Enter an unused drive letter with colon (e.g. X:) to expose the DATABASE volume : X:

6. 这次,它要求为日志卷提供未使用的驱动器盘符。我们将使用驱动器号Y:,因为它未被使用。

Y:,然后按Enter

Enter an unused drive letter with colon (e.g. Y:) to expose the LOG volume : Y:


Saturday, October 17, 2020 7:18:48 PM
Enabling Diagnostics Logging...

--------------------------------------------------------------------------------------------------------------

MSExchange Repl\Service  -  Expert

MSExchange Repl\Exchange VSS Writer  -  Expert


Saturday, October 17, 2020 7:18:49 PM
Enabling VSS Tracing...

--------------------------------------------------------------------------------------------------------------

The command completed successfully.

Saturday, October 17, 2020 7:18:49 PM
Enabling ExTRA Tracing...

--------------------------------------------------------------------------------------------------------------


LastWriteTime : 10/17/2020 7:18:49 PM
Length        : 0
Name          : EnabledTraces.Config



Creating Exchange Trace data collector set...
The command completed successfully.
Starting Exchange Trace data collector...
The command completed successfully.



Saturday, October 17, 2020 7:18:49 PM
Starting DiskShadow copy of Exchange database: DB02

--------------------------------------------------------------------------------------------------------------

Running the following command:

"C:\Windows\System32\diskshadow.exe /s C:\temp\diskshadow.dsh /l C:\temp\diskshadow.log"


Microsoft DiskShadow version 1.0
Copyright (C) 2013 Microsoft Corporation
On computer:  EX01-2016,  10/17/20 19:18:49

-> set verbose on
-> set context persistent
->
-> writer exclude {e8132975-6f93-4464-a53e-1050253ae220}
-> writer exclude {2a40fd15-dfca-4aa8-a654-1f8c654603f6}
-> writer exclude {35E81631-13E1-48DB-97FC-D5BC721BB18A}
-> writer exclude {be000cbe-11fe-4426-9c58-531aa6355fc4}
-> writer exclude {4969d978-be47-48b0-b100-f328f07ac1e0}
-> writer exclude {a6ad56c2-b509-4e6c-bb19-49d8f43532f0}
-> writer exclude {afbab4a2-367d-4d15-a586-71dbb18f8485}
-> writer exclude {59b1f0cf-90ef-465f-9609-6ca8b2938366}
-> writer exclude {542da469-d3e1-473c-9f4f-7847f01fc64f}
-> writer exclude {4dc3bdd4-ab48-4d07-adb0-3bee2926fd7f}
-> writer exclude {41e12264-35d8-479b-8e5c-9b23d1dad37e}
-> writer exclude {12ce4370-5bb7-4C58-a76a-e5d5097e3674}
-> writer exclude {cd3f2362-8bef-46c7-9181-d62844cdc062}
-> writer exclude {dd846aaa-A1B6-42A8-AAF8-03DCB6114BFD}
-> writer exclude {B2014C9E-8711-4C5C-A5A9-3CF384484757}
-> writer exclude {BE9AC81E-3619-421F-920F-4C6FEA9E93AD}
-> writer exclude {F08C1483-8407-4A26-8C26-6C267A629741}
-> writer exclude {6F5B15B5-DA24-4D88-B737-63063E3A1F86}
-> writer exclude {368753EC-572E-4FC7-B4B9-CCD9BDC624CB}
-> writer exclude {5382579C-98DF-47A7-AC6C-98A6D7106E09}
-> writer exclude {d61d61c8-d73a-4eee-8cdd-f6f9786b7124}
-> writer exclude {75dfb225-e2e4-4d39-9ac9-ffaff65ddf06}
-> writer exclude {0bada1de-01a9-4625-8278-69e735f39dd2}
-> writer exclude {a65faa63-5ea8-4ebc-9dbd-a0c4db26912a}
->
-> writer exclude "Microsoft Exchange Writer:\Microsoft Exchange Server\Microsoft Information Store\EX01-2016\e18b64
16e-4bb8-bac2-a06b14ae35c7"
->
-> Begin backup
-> add volume G: alias vss_test_G
-> add volume H: alias vss_test_H
-> create

COM call "lvssObject4->GetRootAndLogicalPrefixPaths" failed.
Component "\Microsoft Exchange Server\Microsoft Information Store\EX01-2016\e18b648d-916e-4bb8-bac2-a06b14ae35c7" fr
riter "Microsoft Exchange Writer" is explicitly excluded.
Component "\config\sysq" from writer "MSMQ Writer (MSMQ)" is excluded from backup,
because it requires volume C:\ which is not in the shadow copy set.
Component "\config\registry" from writer "MSMQ Writer (MSMQ)" is excluded from backup,
because it requires volume C:\ which is not in the shadow copy set.
Component "\config\mapping" from writer "MSMQ Writer (MSMQ)" is excluded from backup,
because it requires volume C:\ which is not in the shadow copy set.
Component "\storage\queue" from writer "MSMQ Writer (MSMQ)" is excluded from backup,
because it requires volume C:\ which is not in the shadow copy set.
Component "\Microsoft Exchange Server\Microsoft Information Store\EX01-2016\e18b648d-916e-4bb8-bac2-a06b14ae35c7\Fil
rom writer "Microsoft Exchange Writer" is excluded from backup,
because it requires volume E:\ which is not in the shadow copy set.
Component "\Microsoft Exchange Server\Microsoft Information Store\EX01-2016\e18b648d-916e-4bb8-bac2-a06b14ae35c7\Log
rom writer "Microsoft Exchange Writer" is excluded from backup,
because it requires volume F:\ which is not in the shadow copy set.
Component "\config" from writer "MSMQ Writer (MSMQ)" is excluded from backup,
because it has an excluded descendent: "sysq".
Component "\storage" from writer "MSMQ Writer (MSMQ)" is excluded from backup,
because it has an excluded descendent: "queue".
Component "\Microsoft Exchange Server\Microsoft Information Store\EX01-2016\e18b648d-916e-4bb8-bac2-a06b14ae35c7" fr
riter "Microsoft Exchange Writer" is excluded from backup,
because it has an excluded descendent: "File".
The writer "MSMQ Writer (MSMQ)" is now entirely excluded from the backup,
because it does not contain any components that can be included.

* Including writer "Microsoft Exchange Writer":
        + Adding component: \Microsoft Exchange Server\Microsoft Information Store\EX01-20163554ce-1503-4f81-8796
0764d80c2

Alias vss_test_G for shadow ID {b4ba1ded-6ed4-46b1-8f13-9cce0de8ee71} set as environment variable.
Alias vss_test_H for shadow ID {02c7fb75-39c3-4b97-9f43-2b26933ad5ec} set as environment variable.
Alias VSS_SHADOW_SET for shadow set ID {406ad2fd-7850-48b4-b1e1-c49c4aa41606} set as environment variable.
Inserted file Manifest.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file BCDocument.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM0.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM1.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM2.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM3.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM4.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM5.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM6.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM7.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM8.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM9.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM10.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM11.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM12.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file WM13.xml into .cab file 20-10-17_-18-58_EX01-2016.cab
Inserted file diskshadow.log into .cab file 20-10-17_-18-58_EX01-2016.cab

Querying all shadow copies with the shadow copy set ID {406ad2fd-7850-48b4-b1e1-c49c4aa41606}

        * Shadow copy ID = {b4ba1ded-6ed4-46b1-8f13-9cce0de8ee71}               %vss_test_G%
                - Shadow copy set: {406ad2fd-7850-48b4-b1e1-c49c4aa41606}       %VSS_SHADOW_SET%
                - Original count of shadow copies = 2
                - Original volume name: \?\Volume{b050fa5e-48f1-4941-bde7-c8175378669e}\ [G:\]
                - Creation time: 17/10/2020 19:18:58
                - Shadow copy device name: \?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1
                - Originating machine: EX01-2016.exoip.local
                - Service machine: EX01-2016.exoip.local
                - Not exposed
                - Provider ID: {b5946137-7b9f-4925-af80-51abd60b20d5}
                - Attributes:  No_Auto_Release Persistent Differential

        * Shadow copy ID = {02c7fb75-39c3-4b97-9f43-2b26933ad5ec}               %vss_test_H%
                - Shadow copy set: {406ad2fd-7850-48b4-b1e1-c49c4aa41606}       %VSS_SHADOW_SET%
                - Original count of shadow copies = 2
                - Original volume name: \?\Volume{114715bf-ed89-4814-ac77-d82735a68f92}\ [H:\]
                - Creation time: 17/10/2020 19:18:58
                - Shadow copy device name: \?\GLOBALROOT\Device\HarddiskVolumeShadowCopy2
                - Originating machine: EX01-2016.exoip.local
                - Service machine: EX01-2016.exoip.local
                - Not exposed
                - Provider ID: {b5946137-7b9f-4925-af80-51abd60b20d5}
                - Attributes:  No_Auto_Release Persistent Differential

Number of shadow copies listed: 2
->
-> expose %vss_test_G% X:
-> %vss_test_G% = {b4ba1ded-6ed4-46b1-8f13-9cce0de8ee71}
The shadow copy was successfully exposed as X:\.
-> expose %vss_test_H% Y:
-> %vss_test_H% = {02c7fb75-39c3-4b97-9f43-2b26933ad5ec}
The shadow copy was successfully exposed as Y:\.
-> end backup
->

Saturday, October 17, 2020 7:19:00 PM
Disabling ExTRA Tracing...

--------------------------------------------------------------------------------------------------------------


Stopping Exchange Trace data collector on EX01-2016...
The command completed successfully.
Deleting Exchange Trace data collector on EX01-2016...
The command completed successfully.



Saturday, October 17, 2020 7:19:01 PM
Disabling Diagnostics Logging...

--------------------------------------------------------------------------------------------------------------

MSExchange Repl\Service  -  Lowest

MSExchange Repl\Exchange VSS Writer  -  Lowest


Saturday, October 17, 2020 7:19:01 PM
Disabling VSS Tracing...

--------------------------------------------------------------------------------------------------------------

The command completed successfully.


Saturday, October 17, 2020 7:19:01 PM
Checking VSS Writer Status: (after backup)

--------------------------------------------------------------------------------------------------------------


Writer name: 'Task Scheduler Writer'
   State: [1] Stable

Writer name: 'VSS Metadata Store Writer'
   State: [1] Stable

Writer name: 'Performance Counters Writer'
   State: [1] Stable

Writer name: 'System Writer'
   State: [1] Stable

Writer name: 'ASR Writer'
   State: [1] Stable

Writer name: 'IIS Config Writer'
   State: [1] Stable

Writer name: 'IIS Metabase Writer'
   State: [1] Stable

Writer name: 'Registry Writer'
   State: [1] Stable

Writer name: 'Microsoft Exchange Writer'
   State: [1] Stable

Writer name: 'BITS Writer'
   State: [1] Stable

Writer name: 'Shadow Copy Optimization Writer'
   State: [1] Stable

Writer name: 'COM+ REGDB Writer'
   State: [1] Stable

Writer name: 'WMI Writer'
   State: [1] Stable

Writer name: 'MSMQ Writer (MSMQ)'
   State: [1] Stable


Saturday, October 17, 2020 7:19:06 PM
Diskshadow Snapshots

--------------------------------------------------------------------------------------------------------------


If the snapshot was successful, the snapshot should be exposed as drive(s) X: and Y:.
You should be able to see and navigate the snapshot with File Explorer. How would you like to proceed?

NOTE: It is recommended to wait a few minutes to allow truncation to possibly occur before moving past this point.
      This allows time for the logs that are automatically collected to include the window for the truncation to occur.

When ready, choose from the options below:

  1. Remove exposed snapshot now
  2. Keep snapshot exposed

WARNING: Selecting option 1 will permanently delete the snapshot created, i.e. your backup will be deleted.

Selection :

7.启动文件资源管理器并查看X:Y:驱动器。

[玩转系统] 使用 PowerShell 截断 Exchange 日志

8. 选择选项1并按Enter删除快照。

Selection : 1

LastWriteTime : 10/17/2020 7:26:44 PM
Length        : 0
Name          : removeSnapshot.dsh

Microsoft DiskShadow version 1.0
Copyright (C) 2013 Microsoft Corporation
On computer:  EX01-2016,  10/17/20 19:26:44

-> delete shadows exposed X:
Deleting shadow copy {b4ba1ded-6ed4-46b1-8f13-9cce0de8ee71} on volume \?\Volume{b050fa5e-48f1-4941-bde7-c8175378669e}\
from provider {b5946137-7b9f-4925-af80-51abd60b20d5} [Attributes: 0x00120009]...

1 shadow copy deleted.
-> delete shadows exposed Y:
Deleting shadow copy {02c7fb75-39c3-4b97-9f43-2b26933ad5ec} on volume \?\Volume{114715bf-ed89-4814-ac77-d82735a68f92}\
from provider {b5946137-7b9f-4925-af80-51abd60b20d5} [Attributes: 0x00120009]...

1 shadow copy deleted.
-> exit

Saturday, October 17, 2020 7:26:44 PM
Getting events from the application and system logs since the script's start time of (10/17/2020 19:02:38)

--------------------------------------------------------------------------------------------------------------

Getting application log events...
Getting system log events...
Getting events complete!


Saturday, October 17, 2020 7:26:49 PM
Stopping transcript log...

--------------------------------------------------------------------------------------------------------------

Transcript stopped, output file is C:\temp\vssTranscript.log



Please use the <Enter> key to exit...:

9.Enter 退出PowerShell 脚本。

验证 Exchange 数据库日志

验证脚本是否删除了快照并清除了日志。

[玩转系统] 使用 PowerShell 截断 Exchange 日志

打开数据库日志卷并验证 Exchange 数据库截断是否已成功完成。

[玩转系统] 使用 PowerShell 截断 Exchange 日志

看起来很棒。这是否可以帮助您在没有备份的情况下截断 Exchange 数据库日志?

继续阅读:在 Exchange Server 中安装免费的 Let’s Encrypt 证书 »

结论

您学习了如何使用 PowerShell 截断 Exchange 数据库日志。如果突然出现高峰值,并且事务日志增长得非常快,那么该脚本非常好。或者如果备份突然不起作用。

使用 PowerShell 脚本安全地清除 Exchange 数据库日志。更改会立即应用。无需卸载和安装数据库。这很好,因为您不会打扰任何用户。

您喜欢这篇文章吗?您可能还喜欢将 Exchange 数据库移动到另一个驱动器。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯