Tuesday, June 9, 2015

NQBackup

UPDATE 6/9/2015: Version 1.7 now released. This update adds standalone support. Since CA is including newer versions of MySQL in their products, DBToolv3 is no longer going to work. This change allows you to specify to use MySQLDump instead of DBToolv3. Essentially, you unremark line 15 and remove/remark line 14. If I get enthusiastic about it, I may update the script to allow a switch from the command line to specify which method to use. I'm just not there yet.
UPDATE 2/10/15: Version 1.6 now released. This update changes the way harvesters and DSAs are backed up, by only backing up the ReaperArchive, ReaperArchive15, and HarvesterArchive directories to a single directory (no redundant rolling backups). It only backs up files that have the archive bit set, so before running it the first time, set the archive bit for all the files in those directories. I also fixed the date naming method so it's YYYYMMDD instead of YYYYDDMM. I also added timestamping to the log so you know how long it takes to perform the file backups vs. the database backups.
UPDATE 2/27/14: Version 1.5 now released. This version doesn't have too many changes. I just added the lines below that allow the NFA mess of data files to be backed up along with everything else. This one script can still be used on any product. However, when running on a Harvester or DSA, extra commands backup the data files.
The syntax for running the tool hasn't changed since 1.4 (but 1.4 introduces some major changes), so you should be able to drop the script in place without changing any scheduled tasks.

nqbackup.bat <dbname> <num_backups_to_keep>

Remember, if you need a reminder how to run the tool, just run it without any arguments (or just double click it from Windows Explorer).


UPDATE: Version 1.4 is now out. Instead of having to create three scheduled tasks, the script now allows you to create one scheduled task that can be run as often as you want. Now instead of deleting the prior backup in the backup location, it moves that backup to a new folder and stores the backup in the original destination. There's also logic in the script that grooms the backups, keeping as many as you prefer. Now, to run the backup, do it like this:

nqbackup.bat <dbname> <num_backups_to_keep>

Where <dbname> is the name of the database to backup and <num_backups_to_keep> is the number to keep.
If you're running NFA (2 or 3 tier) you'll also want to backup your historical data.  That data is contained in various folders that can be easily copied using xcopy.  To find out which folders to backup, see this documentation.

So, to backup a 2-tier harvester completely (install path being C:\CA\NFA\), I'd need to add the following lines to nqbackup after the call to DBtoolv3.exe:

IF "%1"=="harvester" xcopy C:\CA\NFA\Netflow\datafiles\ReaperArchive15 D:\backup\%1\1 /S /E /C /Q /Y /I
IF "%1"=="harvester" xcopy C:\CA\NFA\Netflow\datafiles\HarvesterArchive D:\backup\%1\1 /S /E /C /Q /Y /I
IF "%1"=="harvester" xcopy C:\CA\NFA\Netflow\datafiles\ReaperArchive D:\backup\%1\1 /S /E /C /Q /Y /I


The IF statement allows these lines only to execute when the script is backing up the harvester.  If you're running a 3 tier architecture, you'd need something like this:
IF "%1"=="nqrptr" xcopy C:\CA\NFA\Netflow\datafiles\ReaperArchive15 D:\backup\%1\1 /S /E /C /Q /Y /I


I got tired of recreating and always updating the CAIM Community with my current backup script, so I decided to host it here.  The script itself isn't too complicated; the bulk of the script is documentation on how to use it.

Usage: nqbackup.bat

This is the script that actually runs the backup.  The main reason for this script (instead of calling the tool directly) is that this script removes the previous backup before starting the new backup.  The script can be setup in multiple scheduled tasks to create a daily rolling backup or weekly backups as needed.
>nqbackup [dbname] [destination]
dbname        the name of the database to backup
destination   the folder under D:\backup\ to contain the backup (the tool will
              automatically place the backup in a folder with the name of the 
              database).
These arguments are not optional.
Example:
>nqbackup nms2 mwf
This will create a backup of the nms2 database in D:\backup\mwf\nms2\.

Usage: setnqbackup.bat

This script sets up a rolling backup by using schtasks to remotely setup three scheduled tasks to run on MWF, TTS, and SUN.  The credentials used to run this batch file must have administrative rights on the target machine.  The easiest way to do this is to run it from one NQ server for deployment on the rest of the NQ servers (assuming you've left the default user accounts intact).
>setnqbackup [dbname] [starttime] [server]
dbname      the name of the database to backup (i.e. nms2)
starttime   the time the task should be scheduled in 24 hour format (i.e. 00:30)
server      this is the name or IP address of the target server (i.e. 192.168.1.99)

Usage: updatenqbackup.bat

This script updates the three scheduled tasks previously setup using setnqbackup.bat.  The only change is to update the start time.  This can be handy if you've already deployed the scheduled tasks but put in the wrong start time.
>updatenqbackup [server] [starttime]
server      this is the name or IP address of the target server (i.e. 192.168.1.99)
starttime   the time the task should be scheduled in 24 hour format (i.e. 00:30 
            for 12:30AM time local to the server)
These scripts are currently in version 1.2.  Any updates will replace this version and I'll usually post a comment on this blog post.  Run any of the scripts without any parameters or with /? to get more help.

1 comment:

  1. Hi Stuart,
    Appreciate you publishing your nqbackup script. I realise some time has passed since then, and things have changed from NetQos to NFA - e.g. the names of the mysql databases to back up are now fixed, and there is more than one to be mysqldumped e.g. for a harvester box, both 'harvester' and 'data_retention'. But very helpful as a basis for me to start from!
    All Best, Dan.

    ReplyDelete