cancel
Showing results for 
Search instead for 
Did you mean: 

Script for deleting Old IMG Folders and BKF Files

Armin_Kerl
Level 3
Partner Accredited

Also in BE12 SP1 we have the problem that not always the B2D Media is deleted in the B2D Folder on the Filesystem, even the Disk Space is filling up.

The Media is Overwriten and deleted as BE Media Entry, but not in the FileSystem.

 

So I have made a little Batch Script to free up the B2D Disk Space.

I add it as Post Command to the B2D Job (run on Media Server).

 

The Script reads the existing Media's known by the BE B2D Device.

This Media's are compared to the  existing Media's in the Filesystem Folder.

All BKF Files and IMG Folders that no longer exist in BE are deleted.

 

(In our Config BE does not release the Handle for esent.dll is in the IMG Folders, this does "net stop winmgmt")

Before first Run, please change the rd and del command to echo for testing.

 +++++++++++++++++++++++++++++++++++

set Device=GRT-Mail1
set Folder=E:\GRT-Mail1\

if exist %Folder%Media.txt del %Folder%Media.txt
if exist %Folder%Media1.txt del %Folder%Media1.txt
if exist %Folder%Media2.txt del %Folder%Media2.txt
if exist %Folder%Dir.txt del %Folder%Dir.txt
if exist %Folder%Del.txt del %Folder%Del.txt
if exist "c:\Program Files\Symantec\Backup Exec\bemcmd.exe" set BEPath="c:\Program Files\Symantec\Backup Exec\bemcmd.exe"
if exist "c:\Programme\Symantec\Backup Exec\bemcmd.exe" set BEPath="c:\Programme\Symantec\Backup Exec\bemcmd.exe"
if BEPath=="" Echo "Kann Pfad zu BackupExec nicht finden!" & goto End

net stop winmgmt

%BEPath% -o132 -j%Device% >%Folder%Media1.txt
if not errorlevel=1 net send %computername% Fehler beim auflisten der BackupExec GRT Medien! & goto End

findstr /c:"LABEL: "  %Folder%Media1.txt >%Folder%Media2.txt
for /f "tokens=3 delims= " %%m in (%Folder%Media2.txt) do echo %%m >>%Folder%%Media.txt
for %%d in (%Folder%*.bkf) do echo %%~nd >>%Folder%Dir.txt
for /d %%d in (%Folder%*.) do echo %%~nd >>%Folder%Dir.txt

findstr /v /g:%Folder%Media.txt %Folder%Dir.txt >%Folder%Del.txt

for /f %%i in ('findstr /b IMG %Folder%Del.txt') do rd /s/q %%i
for /f %%b in ('findstr /b B2D %Folder%Del.txt') do del /f/q %%b.bkf

:End

net start winmgmt
+++++++++++++++++++++++++++

 

If it Helps You, please add a Note.

 

Armin

19 REPLIES 19

Andrew_McHale
Level 3

Hi Armin,

 

can you provide details about how to run this script please?

 

I only seem to be able to enter a single line in the POST command text field. Should I dump your entire script into a file and call it "script.bat" and then just link to this file in the POST command text field? Or should I copy every line in seperating them with something like ; or | ?

 

Also, will this script run on every B2D folder or do I have to put it in the POST field of at least one backup job per B2D folder?

 

Many thanks

 

Andrew

Armin_Kerl
Level 3
Partner Accredited
Hi Andrew,
you are right.
Put it in to a Batch Script (DelMedia.bat), but do not call it by Post Job.
It does not run all Times if it is running as Post Job Command.
I run it by Windows Scheduler at 15:00.

You have to set Your "Overwrite Protection Period" of the MediaPool so, that the Media is Overwriting before the Disk is Full (for example to 1 or 2 Days).

set MediaSet = This is the Name of the Media Set (not the B2D Device Name).

Here is a Updated Version:
(If you fond this Smiley Wink, replace it by ) , I dont know why this Editor do this.) 

set MediaSet=B2D
set GRTFolder=E:\B2D\

del "%GRTFolder%*.txt"
if not exist "%DSMI_DIR%BemCMD.exe" Echo "Can not find Path to BackupExec!" & goto End
"%DSMI_DIR%BemCMD.exe" -o132 -j%MediaSet% >"%GRTFolder%Media1.txt"
if not errorlevel=1 net send %computername% Error listing BackupExec GRT Media! & goto End
findstr /c:"LABEL: " "%GRTFolder%Media1.txt" >"%GRTFolder%Media2.txt"
for /f "usebackq tokens=3 delims= " %%m in ("%GRTFolder%Media2.txt") do echo %%m >>"%GRTFolder%Media.txt"
for %%d in ("%GRTFolder%*.bkf") do echo %%~nd >>"%GRTFolder%Dir.txt"
for /d %%d in ("%GRTFolder%*.") do echo %%~nd >>"%GRTFolder%Dir.txt"
findstr /v /g:"%GRTFolder%Media.txt" "%GRTFolder%Dir.txt" >"%GRTFolder%Del.txt"
for /f %%i in ('findstr /b IMG "%GRTFolder%Del.txt"') do rd /s/q "%GRTFolder%%%i"
for /f %%b in ('findstr /b B2D "%GRTFolder%Del.txt"') do del /f/q "%GRTFolder%%%b.bkf"
:End

Armin
Message Edited by Armin Kerl on 11-15-2008 11:05 AM

Andrew_McHale
Level 3

Hi Armin,

 

thank you for the updated version and clearer instructions. I still have a few questions though.

 

1. My B2D media set is named 'B2D Folders' (including a space). Can I just put set MediaSet=B2D Folders or do I need to incase the name in speech marks like set MediaSet="B2D Folders"?

 

2. I cannot find a GRT folder. Should I have one of these and if so where should I look?

 

3. When I run the script and it errors it doesn't end the script but instead pastes everyline as normal text (see image below)

 

Any help you can offer is greatly appreciated.

 

Andrew

 

Armin_Kerl
Level 3
Partner Accredited

Hello Andrew,

 

1. Space is alwas a Problem, try it "..." or even better Rename the Media Set without using Space.

 

2. The GRT Folder Name is the Path you define in your Backup to Disk Device (Device > Backup-to-Disk-Folder > Your B2D Device > Properies)

In this Path you schould find the changer.cfg and the B2D... Files.

 

(I call it GRT Folder, because I only using B2D for GRT Mail backup.

Naming it B2D Folder schould make it clearer.)

 

3. I think the errors come, because the Path is not correct. Setting the Folder Name to your B2D Destination schould solve it.

 

Armin

 

QuickComputerSv
Not applicable

Thanks for the work to get this put together, Armin!  I really appreciated finding this.

 

I needed to make a couple changes to get the script to work on my server (Windows Server 2007 x64).  I went ahead and formatted it and added a failsafe to ensure random execution didn't cause problems (in this version, you must specify /run in order to actually delete files, otherwise it just lists them.)  Here's the revised version:

 

 

@Echo Off
:: A script to delete BKF files and IMG folders no longer needed by Backup Exec.
::
:: Original by Armin Kerl, modifications by Matthew Miller.
::
:: If you have comments or questions, please join the forum and post on the thread at:
:: https://forums.symantec.com/syment/board/message?board.id=be12_exchange&thread.id=380
::
:: Note that this will run properly only on a machine running Windows 2003 or XP SP2 with
:: command extensions turned on (which is the default on those systems).
::
:: History
:: 2008-08-19 AK Original Version
:: 2008-12-31 MM Modified to English, added formatting & comments.
:: Changed to run test only unless /run parameter is specified.
:: Added recursion through B2D subdirectories (since Backup Exec
:: adds \Veritas\B2D to all removable B2D directories on our systems)

:CONFIGURE
SETLOCAL
PUSHD
::
:: Change the following 3 items below to match your installation.
::
:: * MediaSet - the Backup Exec Media Set Name you're using for backup-to-disk jobs
:: (It's best to make this a name without spaces)
:: * B2Dfolder - the full path to the backup-to-disk folder you're using for the job
:: * BEPath - the full path to the Backup Exec executables (specifically, bemcmd.exe).
:: (If you didn't change it, this is C:\Program Files\Symantec\Backup Exec\becmd.exe,
:: on US English systems)

SET MediaSet=Beniton
SET B2Dfolder=F:\
SET BEPath="D:\Program Files\Symantec\Backup Exec\bemcmd.exe"

SET Action=ECHO
SET ActionDir=ECHO
IF /I "%1" EQU "/run" SET Action=DEL & SET ActionDir=RD
IF /I "%1" EQU "-run" SET Action=DEL & SET ActionDir=RD


:PREPARE
:: First, some general cleanup to be sure we're starting fresh

IF BEPath=="" Echo "Cannot find the path to BackupExec! Please edit the command script." & goto End
IF EXIST %B2Dfolder%Media.txt DEL %B2Dfolder%Media.txt
IF EXIST %B2Dfolder%Media1.txt DEL %B2Dfolder%Media1.txt
IF EXIST %B2Dfolder%Media2.txt DEL %B2Dfolder%Media2.txt
IF EXIST %B2Dfolder%Dir.txt DEL %B2Dfolder%Dir.txt
IF EXIST %B2Dfolder%%Del%.txt DEL %B2Dfolder%Del.txt

:: You may need to stop the winmgmt service, because at least in some environments, it keeps
:: handles open to files we may be planning to delete. If necessary, uncomment the following
:: (remove the initial "::" from the line).
:: **** Also uncomment it below (in the CLEANUP section) ***

:: NET STOP winmgmt

:MAIN
:: Now we're ready to delete old files (as long as /run was specified,
:: otherwise we'll just display a list)

:: First, dump a list of all the media labels Backup Exec is currently using. If we can't get this,
:: quit with an error.
%BEPath% -o132 -j%MediaSet% >%B2Dfolder%Media1.txt
IF NOT Errorlevel=1 net send %computername% Error getting listing of Backup Exec B2D Media! & GOTO Cleanup

:: Next, extract all the lines showing an actual in-use media (these will be the backup-to-disk file names)
FINDSTR /c:"LABEL: " %B2Dfolder%Media1.txt > %B2Dfolder%Media2.txt
FOR /f "tokens=3 delims= " %%m in (%B2Dfolder%Media2.txt) do ECHO %%m >>%B2Dfolder%%Media.txt

:: Next, list all the files and folders in the Backup-to-Disk directory.
FOR /r %%d in (%B2Dfolder%*.bkf) do ECHO %%~nd >>%B2Dfolder%Dir.txt
FOR /d %%d in (%B2Dfolder%*.) do ECHO %%~nd >>%B2Dfolder%Dir.txt

:: Next, find all lines it the list of files that are NOT (/v) in Backup Exec's
:: list of current media. This gives us a list of files to be deleted.
FINDSTR /v /g:%B2Dfolder%Media.txt %B2Dfolder%Dir.txt > %B2Dfolder%Del.txt

:: Finally, execute the required action against each item listed in our Del.txt file
:: from the previous step. Note again that unless you run this script with the /run
:: command-line parameter, it will not delete files but instead just list them.
CD /D %B2Dfolder%
FOR /F %%i in ('findstr /b IMG %B2Dfolder%Del.txt') do %ActionDir% /s/q %%i
FOR /F %%b in ('findstr /b B2D %B2Dfolder%Del.txt') do %Action% /f/q %%b.bkf

:CLEANUP
:: Clean up after ourselves, like good citizens!
:: NET START winmgmt
ENDLOCAL
IF EXIST %B2Dfolder%Media.txt DEL %B2Dfolder%Media.txt
IF EXIST %B2Dfolder%Media1.txt DEL %B2Dfolder%Media1.txt
IF EXIST %B2Dfolder%Media2.txt DEL %B2Dfolder%Media2.txt
IF EXIST %B2Dfolder%Dir.txt DEL %B2Dfolder%Dir.txt
IF EXIST %B2Dfolder%%Del%.txt DEL %B2Dfolder%Del.txt
POPD

:END

 

 

Message Edited by QuickComputerSvcs on 12-31-2008 02:06 PM
Message Edited by QuickComputerSvcs on 12-31-2008 02:08 PM

AdamBrown
Level 2
Hi all,

Sorry to resurect an old post, but I've got a problem with this script.

Ive edited the options to refect my setup, but I get this error.

imagebrowser imageAny Ideas?
The script doesn't appear to be creating Meida.txt.

Ken_Putnam
Level 6
Why worry about removing old IMG folders and data

by setting an OPP that meets your need, just let BackupExec reuse them after they are no longer needed?

AdamBrown
Level 2
You'll have to forgive me. How do i go about that?

Ken_Putnam
Level 6
edit the properties of the media set your are writing the backup to

If you need to keep the data on disk for two weeks, set the Overwrite Protection to 13 days, for example

But remember, if your job are Append rather than Overwrite, the OPP for all of the BKF files in an "append family" is reset each time a back closes, so NONE of them will ever expire

Lively
Level 5
Prior to 12 the IMG folders (from GRT) did not pay attention to a retention policy, but now that BE follows the retention policy you should not need the script.

AdamBrown
Level 2
Thanks guys, I will see if that works.

I've just started a new role, having never seen BE before, (fresh out of Universty)  Is there a book or some material that I can read to get me up to speed?

Lively
Level 5
Start off by downloading the admin guide and look at a lot of threads here.

The admin guide is around 1200 pages, but I took a couple of days to look through what pertained to my work and went from there.  Lurking here helps a lot as you can see a lot of different errors and the related solutions/attempts and solutions.

Carcharadon
Not applicable
I am running Backup Exec 12.5 and we are still having to delete the IMG files manually.  We will try the script and see how it goes.  It looks like it should do the trick.

johnsondata
Not applicable
Maybe I blinked, but I have never seen a version of Backup Exec 12.5 (SP2 now) which successfully deletes the img folders. It's good to see someone else with the same frustration....
I found this http://support.veritas.com/docs/317211

which reads

"The above mentioned issue is mainly seen in but may not be limited to Windows Small Business Server 2003.
Workarounds:

The expired IMG folder cannot be deleted unless the "WMIPRVSE.EXE" process is stopped. To delete the expired IMG media please follow the steps mentioned below:

Workaround 1
1. On the Backup Exec server, stop the Windows Management Instrumentation (WMI) service.
 
Note: There will be other services dependent on the WMI service, which also will be stopped.
 
2. Delete all the expired IMG folders that have been left behind and have only the ESE.DLL file in it.
 
3. Start the Windows Management Instrumentation (WMI) service.
 
Workaround 2
 
Leave the IMG folders on the server until the lock is released and then delete them (after planned reboots etc). This as minimal space is used for this and that it does not cause any issue with Backup Exec functionality."


I think the hint is SBS2003. I am using SBS2008 and it also fails.
Thanks for the input re batch files, I will implement them today. Can't wait for Symantec to fix it!!!!!

David

589705353
Level 2
I had to change it at the lines with net stop/start to include lines for Microsoft Exchange Management.

 NET STOP "Microsoft Exchange Management"
 NET STOP winmgmt


 NET START winmgmt
 NET START "Microsoft Exchange Management"

Thanks for the good batch file!
Bengt Nilsson, DATAFANT AB, Sweden

Lively
Level 5
As long as the overwrite is set correctly you should not have to delete IMG folders.

What will happen is the IMG files will fill up your storage, then start to reclaim space. 

If this script works for people, great!  You really should look at the overwrite setting though as 12.5 initial release handled GRT backups without issue.  The same remains true for it being fully patched 12.5

unimatter
Level 3
 I am using 12.5 fully patched on SBS 2003.  My overwrite period is 12 hours.  There are plenty of alerts that BE is reclaiming space from old IMG folders, and they are removed from the media list, but the folders remain in the file system with a single file, ese.dll.  As someone else pointed out, this link http://seer.entsupport.symantec.com/docs/317211.htm is clear confirmation from Symantec that it's a bug.

Colin_Weaver
Moderator
Moderator
Employee Accredited Certified
Document 317211 does not actually acknowledge it is a bug it actually states that another application on the server is responsible for locking a file or files in the folder stopping it from being removed.

The document is also discussing a cause for the folders being left behind - as far as I am aware the bulk of the data contained in the folder should still get removed when the recliam attempt occurs, it is usually just some relatively small files that are locked that causes the folder to be left behind.

Finally the document actually shows a way to detect what is locking the files (by using Process Explorer to check the locks on any files left behind. So if you can see statements in Backup Exec indicating the a reclaim has occured but the folder in the message is still on the system then you should consider using the same utility to identify the cause.

Andrew_McHale
Level 3
Hi all,

I've updated the script slightly as it wasn't quite working for me.

Unfortunately my updates were more dumb luck than skill so if you have a problem don't bother asking me.

Hope this helps someone

Andrew

P.S. I didn't bother updating the version info as the changes were so minor


@Echo Off
:: A script to delete BKF files and IMG folders no longer needed by Backup Exec.
::
:: Original by Armin Kerl, modifications by Matthew Miller.
::
:: If you have comments or questions, please join the forum and post on the thread at:
:: https://forums.symantec.com/syment/board/message?board.id=be12_exchange&thread.id=380
::
:: Note that this will run properly only on a machine running Windows 2003 or XP SP2 with
:: command extensions turned on (which is the default on those systems).
::
:: History
:: 2008-08-19 AK Original Version
:: 2008-12-31 MM Modified to English, added formatting & comments.
::               Changed to run test only unless /run parameter is specified.
::               Added recursion through B2D subdirectories (since Backup Exec
::               adds \Veritas\B2D to all removable B2D directories on our systems)

:CONFIGURE
 SETLOCAL
 PUSHD
::
:: Change the following 3 items below to match your installation.
::
:: * MediaSet - the Backup Exec Media Set Name you're using for backup-to-disk jobs
::   (It's best to make this a name without spaces)
:: * B2Dfolder - the full path to the backup-to-disk folder you're using for the job
:: * BEPath - the full path to the Backup Exec executables (specifically, bemcmd.exe).
::   (If you didn't change it, this is C:\Program Files\Symantec\Backup Exec\becmd.exe,
::   on US English systems)

 SET MediaSet=Default
 SET B2Dfolder=D:\Serv01\
 SET BEPath="C:\Program Files\Symantec\Backup Exec\bemcmd.exe"

 SET Action=ECHO
 SET ActionDir=ECHO
 IF /I "%1" EQU "/run" SET Action=DEL & SET ActionDir=RD
 IF /I "%1" EQU "-run" SET Action=DEL & SET ActionDir=RD


:PREPARE
:: First, some general cleanup to be sure we're starting fresh

 IF BEPath=="" Echo "Cannot find the path to BackupExec!  Please edit the command script." & goto End
 IF EXIST %B2Dfolder%Media.txt DEL %B2Dfolder%Media.txt
 IF EXIST %B2Dfolder%Media1.txt DEL %B2Dfolder%Media1.txt
 IF EXIST %B2Dfolder%Media2.txt DEL %B2Dfolder%Media2.txt
 IF EXIST %B2Dfolder%Dir.txt DEL %B2Dfolder%Dir.txt
 IF EXIST %B2Dfolder%%Del%.txt DEL %B2Dfolder%Del.txt

:: You may need to stop the winmgmt service, because at least in some environments, it keeps
:: handles open to files we may be planning to delete.  If necessary, uncomment the following
:: (remove the initial "::" from the line). 
:: **** Also uncomment it below (in the CLEANUP section) ***

:: NET STOP winmgmt

:MAIN
:: Now we're ready to delete old files (as long as /run was specified,
:: otherwise we'll just display a list)

:: First, dump a list of all the media labels Backup Exec is currently using.  If we can't get this,
:: quit with an error.
  %BEPath% -o132 -j%MediaSet% >%B2Dfolder%Media1.txt
  IF NOT Errorlevel=1 net send %computername% Error getting listing of Backup Exec B2D Media! & GOTO Cleanup

:: Next, extract all the lines showing an actual in-use media (these will be the backup-to-disk file names)
 FINDSTR /c:"LABEL: "  %B2Dfolder%Media1.txt > %B2Dfolder%Media2.txt
 FOR /f "tokens=3 delims= " %%m in (%B2Dfolder%Media2.txt) do ECHO %%m >>%B2Dfolder%%Media.txt

:: Next, list all the files and folders in the Backup-to-Disk directory.
 FOR %%d in (%B2Dfolder%*.bkf) do ECHO %%~nd >>%B2Dfolder%Dir.txt
 FOR /d %%d in (%B2Dfolder%*.) do ECHO %%~nd >>%B2Dfolder%Dir.txt

:: Next, find all lines it the list of files that are NOT (/v) in Backup Exec's
:: list of current media.  This gives us a list of files to be deleted.
 FINDSTR /v /g:%B2Dfolder%Media.txt %B2Dfolder%Dir.txt > %B2Dfolder%Del.txt

:: Finally, execute the required action against each item listed in our Del.txt file
:: from the previous step.  Note again that unless you run this script with the /run
:: command-line parameter, it will not delete files but instead just list them.
 CD /D %B2Dfolder%
 FOR /F %%i in ('findstr /b IMG %B2Dfolder%Del.txt') do %ActionDir% /s/q %%i
 FOR /F %%b in ('findstr /b B2D %B2Dfolder%Del.txt') do %Action% /f/q %%b.bkf

:CLEANUP
:: Clean up after ourselves, like good citizens!
 :: NET START winmgmt
 IF EXIST %B2Dfolder%Media.txt DEL %B2Dfolder%Media.txt
 IF EXIST %B2Dfolder%Media1.txt DEL %B2Dfolder%Media1.txt
 IF EXIST %B2Dfolder%Media2.txt DEL %B2Dfolder%Media2.txt
 IF EXIST %B2Dfolder%Dir.txt DEL %B2Dfolder%Dir.txt
 IF EXIST %B2Dfolder%Del.txt DEL %B2Dfolder%Del.txt
 ENDLOCAL
 POPD

:END