Remove Million Log Files from Exchange Server

Customer is running Exchange 2010 with NetBackup for backup. At some point the backup stalled and the Exchange server (passive node) froze. Only hard reboot turned the node back to life.

After lots of troubleshooting it turned out that there were several million (small) log files located in C:\Program Files\Veritas\NetBackup\online_util\ which caused the backup to freeze.

The problem is… how do you remove so many files from a (local) hard disk? A command prompt or Windows Explorer is generally speaking not a good idea, but you can do this with PowerShell.

First load the file into an array with this command:

$Logfiles = [System.IO.Directory]::GetFiles("C:\Program Files\VERITAS\NetBackup\online_util\_fi_cntl", "*.*")

It took approx. 3 minutes to load all files in the $Logfiles array.

To remove the first 100,000 files and determin the time needed the following commands was used:

a=get-date;$Logfiles[0..99999]|%{[System.IO.file]::delete($_)};
$b=get-date

This took only 61 seconds. Disk activity never came over 15%

As a side note: The admins also tried it using a command prompt and a standard del command, this took approx. 53 minutes to remove 100,000 files.

A second batch with 2,000,000 logfiles took 1500 seconds (15 minutes) to remove. Disk activity however kept raising during this 15 minutes up to 100%. To prevent too many issues with (disk) performance customer decided to remove the logfiles in batches of 500,000 items until all logfiles are removed.

Special thanks to Kees de Groot (Big-IT.nl and ex2013.com)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s