Jeremy Nelson
2005-Dec-01 03:35 UTC
[Samba] Replicating printers, drivers, and settings between machines
For backup and redundancy purposes, I've been needing to replicate CUPS printer queues between two Samba servers, and came up with the following shell script. We use a fairly sizable number of CUPS printer queues printing in RAW mode, and install the printer drivers from the Windows clients, so all clients actually download the printer driver from Samba at first use. WARNING: This script destroys your CUPS printer configuration (printers.conf), your Windows point and print drivers, and your Samba printer definitions and settings. It also copies the TDB files from a server WITHOUT stopping Samba, so it's possible you could get corruption. I don't recommend running this as a cron job. Any recommendations to improve this script would be much appreciated. Jeremy #!/bin/bash # Replicate Printer queues, drivers, and settings between machines # Script was written on a Gentoo server running 2.6.12 using standard ebuilds of Samba 3.0.14a-r2 and CUPS 1.1.23-r1 # Jeremy Nelson # Canterbury School # 30 Nov 2005 [ $# -ne 1 ] && echo "Server name required for $0" && exit 0 # Copy CUPS Printer definitions, then restart CUPS /usr/bin/scp root@$1:/etc/cups/printers.conf /etc/cups/ /usr/bin/killall -SIGHUP cupsd # Copy Point and Print Driver Database /usr/bin/rm -rf /var/lib/samba/printers /usr/bin/scp -p -r root@$1:/var/lib/samba/printers /var/lib/samba/ # Make backups of the TDBs for future use in case these get corrupted /usr/bin/ssh $1 -C "cd /var/cache/samba/;/usr/bin/tdbbackup *.tdb" /usr/bin/ssh $1 -C "cd /var/cache/samba/printing/;/usr/bin/tdbbackup *.tdb" # Stop Samba /etc/init.d/samba stop # Make sure it's REALLY dead /usr/bin/killall -9 smbd /usr/bin/killall -9 nmbd /etc/init.d/samba zap # Copy the TDBs for the printer definitions and the individual printers /usr/bin/rm /var/cache/samba/ntprinters.tdb /usr/bin/rm /var/cache/samba/printing/*.tdb /usr/bin/scp -p root@$1:/var/cache/samba/ntprinters.tdb /var/cache/samba/ /usr/bin/scp -p root@$1:/var/cache/samba/printing/*.tdb /var/cache/samba/printing # Restart Samba /etc/init.d/samba start