Wednesday, October 3, 2012

NQSync

Here's another one of my tools.  I found myself constantly needing to make sure the supportcig.exe is up to date on all my servers.  I also spend a lot of time tweaking my nqbackup.bat script, and every time there's a change, I need to copy it out to all my servers.  I also ended up trying to organize the mess that is the huge quantity of supportcig files distributed across all my servers.  So, of course, I scripted it.



NQSync.bat does several things I'm proud of.  First of all, it finds two unused drive letters on the system on which it's being run, starting with Z.  It does this so that the script can temporarily map network drives out to all the target systems and to the master system.  I should explain: the script can be run from anywhere as long as the credentials used to run the script have admin rights to all the servers.  First it maps a drive to the master server's D: drive.  Then it maps another network drive out to each of the target servers in turn (this is why we need two unused drive letters).  Then, depending on the options will do three actions:

  • Update the supportCIG.exe file on the remote server - the script will copy the supportCIG.exe file from the master's D:\SupportCIG\ directory to the target server(s) D:\SupportCIG\ directory.
    To enable this option, include the switch /u anywhere on the line when calling the script.
  • Gather the supportCIG output files onto the master server - the script will copy any zip files found in D:\SupportCIG\ to the master server into the D:\SupportCIG\[Server]\ directory, where [Server] is the server's name or IP address.
    To enable this option, include the switch /g anywhere on the line when calling the script.
  • Synchronize tools to the remote server - the script will the entire contents of the D:\DBTools3 and D:\SupportTools6 directories out to the remote server in the same location.  This is how I get a copy of my updated nqbackup.bat file out to all the servers.
    To enable this option, include the witch /s anywhere on the line when calling the script.
The script itself will need to be modified to identify the master server.  Just go to line 2 and put the name or IP address of the master server.  Also, you'll need to provide a text file containing the name or IP address of each target server (one per line).  Obviously, it doesn't need to contain the master server's IP address.  Make the path to this text file one of the arguments.  For example:

nqsync.bat /u /g D:\lists\allservers.txt

This would update the CIG and gather all the outputs for all the servers in the text file.  Obviously, if the text file is in the same directory as nqsync.bat, you can exclude the full path and just put the name of the file.

NQSync.bat uses some fun code to find the first and second available drive letters.  I've tested this by using this script.  It identifies which drive letters are in use and which are available.

No comments:

Post a Comment