Batch Script runs with errors PrintBRM

Posted on 2011-10-20
Medium Priority
Last Modified: 2012-05-12

I am currently running this scheduled Batch file command to backup Printer Confgiuration :

del c:\temp\printersbackupconfig\*.* /S/Q

%windir%\System32\Spool\Tools\PrintBRM -s \\printserver1 -b -f c:\temp\printersbackupconfig\printserver1.printerExport  -O FORCE

The script runs with no issues as a scedule task every week but what I was hoping to do is alter the script so it does not delete the folder items (time consuming many print server configs) and can backup the latest printer settings sucesssfully.

If I do not use del c:\temp\printersbackupconfig\*.* /S/Q then the script comes up with error messages in msdos:

Operation mode: backup
Target server: \\printserver1
Target file path: c:\temp\printersbackupconfig\printserver1.printerExport.
Queue publish mode: none
Overwrite mode: force new settings

The following error occurred: 0x80070050.
The file exists.

Is there any way of not using the del c:\temp\printersbackupconfig\*.* /S/Q and overwite what currently in the location without error "The File exists"


Question by:maxwsp
  • 2
  • 2
LVL 43

Expert Comment

by:Steve Knight
ID: 37001296
Could you not just remove the specific file:


or export it into a temporary directory then move / copy it to the one you want.


rd C:\temp\tempexport /s/q
md c:\temp\tempexport
%windir%\System32\Spool\Tools\PrintBRM -s \\printserver1 -b -f c:\temp\tempexport\printserver1.printerExport  -O FORCE
move c:\temp\tempexport\printserver1.printerExport   c:\temp\printersbackupconfig\printserver1.printerExport

or something like that!

LVL 59

Expert Comment

by:Bill Prew
ID: 37002380
I was already to suggest just deleting the single file, and refreshed and viola, Steve was there with it.  So I would recommend that as the first and simplest approach to consider as well.


Author Comment

ID: 37005205
Thanks for comments - the idea behind not deleting the file before another fresh backup runs is the fact that the script runs weekly and if say there is an issue with the backup then not only the previous backup is deleted but no backup as well.  I was just wondeing whether I could overwrite the file(s) rather than moving or deleting the file as space is also an issue in our environment.  Also it's not just a single file but the batch file actually is used to backup over 20 print servers ad size of these do grow - so do not want to move files to a temporary location and rather have an option to overwrite current files.

LVL 59

Accepted Solution

Bill Prew earned 1000 total points
ID: 37008351
How about something like this.  Since you have to do a number of servers I used a small subroutine for the actual logic for each server.  Tat logic will rename the existing printerExport file for that server to a bak file files.  Then run the PrintBRM utility.  Then, if errors occurred running the utility, it will rename the bak file back to printerExport.  If no errors occurred it will remove the bak file for that server.

So, you only have a second copy of the file for the short period of time that the utility is running.  After that it removes it if all went well.  Let me know if this doesn't make sense.

@echo off
set BkupDir=c:\temp\printersbackupconfig
set PrintBRM=%windir%\System32\Spool\Tools\PrintBRM

call :DoBackup printserver1
call :DoBackup printserver2
call :DoBackup printserver3
goto :EOF

:DoBackup [printservername]
  if exist "%BkupDir%\%~1.printerExport" ren "%BkupDir%\%~1.printerExport" "*.bak"
  "%PrintBRM%" -s \\%~1 -b -f "%BkupDir%\%~1.printerExport" -O FORCE && (
    if exist "%BkupDir%\%~1.bak" del "%BkupDir%\%~1.bak" 
  ) || (
    if exist "%BkupDir%\%~1.bak" ren "%BkupDir%\%~1.bak" "*.printerExport"
  goto :EOF

Open in new window


Author Closing Comment

ID: 37043780
Thanks for the code - this should do the trick.

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question