Print servers need to backed up. This is because of two main reasons. One is that users heavily depend on printers and a not properly working print server will cause imediate helpdesk tickets and unhappy users. The other one is that installing a new driver, might it be a new version, a new model or even an additional manufacturer, can cause other print drivers to act up or even stop working – many administrators know and fear that.
Windows server actually allows you to backup the current print drivers, installed printers and their configuration. You can use this to migrate your printers or to back them up. Of course, you can simply depend on e.g. VMware snapshots, storage level snapshots or other backups of your server. But you also could just export the whole print server configuration while using the scripts below. Those will actually call the Windows API to back up the printers and store it all in a file that you can keep centrally. You don’t just rely on snapshots or a full server backup for e.g. your SQL databases as well, do you?
The script uses a .CMD file that will execute the actual backup and send a email report, while using the SMTPSEND program from Michael Kocum (https://www.dataenter.com/download.asp) for this since I already ad it flying around – you could replace the mail send option with another prepared SMTPSEND client, a VBS script or just remove it completely. Additionally there is a .VBS script that will do a clean up of the target backup files depending on the age of the files in the specified directory.
All the parameters are explained and set in the top part of the .CMD file – I therefor will not explain them here again – you should not need to modify the scripts by default – but feel free to do so. Of course, you should create a scheduled task and execute the .CMD periodically. This can save you time and headache in case you have a malfunctioning print server system. The restore can be easily done through the Print Management MMC that Windows provides you, cause the actual backup files are createed using the same Windows APIs. Your end users will be happy that their printers got back to work in no time, hopefully.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | @ECHO OFF SETLOCAL REM Printer Backup Script REM This script creates a Printer Backup on a Windows 2008 or newer Server System REM (might work as well on Windows Vista or newer) REM The Script uses Standard Windows Procedures to create a Standard Windows Printer Backup File REM The Backup will include Printer Settings and Drivers REM Use "Print Management" to restore the backup REM REM WARNING REM ------- REM The Script will automatically search and delete all Files older than intAge in the destination Folder! REM Always set a destination Folder just for the System you are going to Backup. REM SubFolders will be ignored. REM REM CONFIG Values REM ------------- REM strPrintServer = string value / PrintServer to backup - localhost or hostname REM intAge = integer value / max Age in Days for the Backup Files, the script will automatically delete older Backup Files REM strPath = string value / SMB or UNC Path to the Backup-Folder, the executing User needs Read/Write access to this path REM strMailServer = string value / SMTP Server REM intMailServerPort = integer value / SMTP Server Port REM strMailFrom = string value / from address, must be able to send Mail over the SMTP REM strMailTo = string value / mail recipient REM strMailSuject = string value / mail subject line REM CONFIG Values REM ============================================================================================= SET strPrintServer=server.domain.local SET intAge=3 SET strPath=\\server.domain.local\backup$\Printer\SERVER SET strMailServer=smtp.domain.com SET intMailServerPort=25 SET strMailFrom=admin@domain.local SET strMailTo=admin@domain.local SET strMailSubject=Printer Backup - SERVERNAME REM ============================================================================================= REM End CONFIG Values REM Script-System-Variables, do not change from here on! SET ScriptLog=%~dp0\Printer_Backup_Log.txt DEL %ScriptLog% ECHO Script-Log Start Date/Time: %Date% / Time: %Time% >> %ScriptLog% ECHO Script-Parameter: >> %ScriptLog% ECHO =========================================================================== >> %ScriptLog% ECHO strPrintServer: %strPrintServer% >> %ScriptLog% ECHO intAge: %intAge% >> %ScriptLog% ECHO strPath: %strPath% >> %ScriptLog% ECHO strMailServer: %strMailServer% >> %ScriptLog% ECHO intMailServerPort: %intMailServerPort% >> %ScriptLog% ECHO strMailFrom: %strMailFrom% >> %ScriptLog% ECHO strMailTo: %strMailTo% >> %ScriptLog% ECHO strMailSubject: %strMailSubject% >> %ScriptLog% ECHO =========================================================================== >> %ScriptLog% ECHO Get date in format YYYY-MM-DD (assumes the locale is the United States) >> %ScriptLog% FOR /F "tokens=1,2,3,4 delims=/ " %%A IN ('Date /T') DO SET NowDate=%%D%%C%%B>> %ScriptLog% FOR /F "tokens=1,2 delims=: " %%A IN ('Time /T') DO SET NowDate=%NowDate%_%%A%%B>> %ScriptLog% ECHO =========================================================================== >> %ScriptLog% ECHO Starting Printer Backup: >> %ScriptLog% %windir%\System32\Spool\Tools\PrintBRM.EXE -B -S %strPrintServer% -F %strPath%\%NowDate%_%strPrintServer%.bak >>"%ScriptLog%" ECHO =========================================================================== >> %ScriptLog% ECHO Backup CleanUp >> %ScriptLog% CSCRIPT %~dp0\Printer_Backup_CleanUp.vbs %intAge% "%strPath%" >> %ScriptLog% ECHO Backup CleanUp finished >>%ScriptLog% ECHO =========================================================================== >> %ScriptLog% ECHO Current Files in Backup Path: >>%ScriptLog% DIR %strPath% >>%ScriptLog% ECHO =========================================================================== >> %ScriptLog% ECHO Script-Log End Date/Time: %Date% / Time: %Time% >> %ScriptLog% ECHO Sending Info Mail >> %ScriptLog% %~dp0\SMTPSEND.EXE -f%strMailFrom% -t%strMailTo% -h%strMailServer% -p%intMailServerPort% -s%strMailSubject% -i%ScriptLog% >> %ScriptLog% ECHO =========================================================================== >> %ScriptLog% ENDLOCAL |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | Set objArgs = WScript.Arguments If objArgs.Count > 0 Then Dim strPath Dim intAge intAge = objArgs(0) strPath = objArgs(1) Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder(strPath) For Each objFile in objFolder.Files If DateDiff("d", objFile.DateLastModified, Now()) > Cint(intAge) Then On Error Resume Next objFile.Delete On Error Goto 0 End If Next End If |