Batch Script runs with errors PrintBRM

Posted on 2011-10-20
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
    LVL 43

    Expert Comment

    by:Steve Knight
    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 51

    Expert Comment

    by:Bill Prew
    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

    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 51

    Accepted Solution

    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

    Thanks for the code - this should do the trick.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now