How do I set up a savepnpc script?

From Backup Central


A. Rodney Rutherford wrote (16 May 2000): (Solaris server/client example with the groupname TEST) Client has savepnpc specified in the "Backup command:" field on server /nsr/res/TEST.res file on client contains:

type: savepnpc;
 precmd: /nsr/bin/precmd.sh;
 pstcmd: /nsr/bin/pstcmd.sh;
 timeout: "11:00pm";

When a savegroup starts the following happens (example using the group TEST):


  1. The server starts the group.
  2. The server sees the client has savepnpc specified as the backup command.
  3. The server contacts the client and checks for a /nsr/res/TEST.res file. (If there is not one, a dummy res file will be created.)
  4. The client executes the pre command/script specified in the file (precmd: /nsr/bin/precmd.sh;). It creates a tmp file indicating that savepnpc is running, /nsr/tmp/TEST.tmp
  5. It also executes a process that monitors the status of the saves waiting for completion and/or the timeout value specified in /nsr/res/TEST.res. (timeout: "11:00pm";)
  6. After the pre script successfully completes, the server then initiates the filesystem saves.
  7. During this time the client is constantly checking the server to see if the saves are completed. As soon as they have completed (or the timeout value has been reached), the client executes the post script specified in the /nsr/res/TEST.res file. (pstcmd: /nsr/bin/pstcmd.sh) It then removes the /nsr/tmp/TEST.tmp file.

NOTES:

  1. The pre/post scripts need to have the necessary environment setup in them, as savepnpc does not pass any kind of environment to the scripts.
  2. The start/stop of the pre and post commands are recorded in /nsr/logs/savepnpc.log
  3. If the pre command fails (exit status non-zero), the saves for that client will abort and not be run. It will also not start the post command process, so the post script will never run and the /nsr/tmp/TEST.tmp file will be left. You will need to remove this by hand.
  4. If a savegroup session is manually aborted or stopped on the server, the /nsr/tmp/TEST.tmp file is left. (This is because the server allows you to restart it later.) Also, because an abort does not clear up the work list for the client,the client still thinks there are saves to be completed and the post script will not run.
  5. If a new savegroup session is started and there is an existing /nsr/tmp/TEST.tmp file, it will skip the pre/post commands; however it will run the filesystem save sessions.


About a month later, Rodney Wines & W. Curtis Preston discussed savepnpc (15 June 2000). Their discussion is what resulted in the summary below. There are contributions from both Rodney and Curtis. Most of the documentation on how to use savepnpc is lacking. What follows is a summary of the 'gotchas' for this little feature. The information below applies to both NT and UNIX clients.

  1. Specify savepncp as the backup command in the client config.
  2. Put the /nsr/res/<groupname>.res file on the client, not the server. If you're not sure where it goes, run a group backup and it will create an example file for you. Check /nsr/res or <nsrroot>\nsr\res.
  3. There is a limited path environment with savepnpc. Therefore, you must use full path names for any commands.
  4. You must escape any '\' characters in the <groupname>.res file by using an extra '\' before them. (e.g. c:\dir\command.exe -> c:\\dir\\command.exe) You DON'T need to dothis in the shell script or batch file that you may be running, just in the <groupname>.res file.
  5. Savepnpc also doesn't pass arguments well to commands. (Some have apparently done it, but it doesn't always work.)
  6. The best way around the path and arguments problems is to put all your commands in a script and put that script's full pathname on the precmd or postcmd line. In this script, you can define any environment variables you need (including PATH) on NT, and source any login scripts on Unix that you want to.
  7. Do not use savepnpc with groups that have a space in their name.
  8. If savepnpc has been running successfully for a while, then the backup starts behaving like a normal backup, look for an /nsr/tmp/<groupname>.tmp. This is a lock file that is created the first time a savepnpc is run during a backup session, and is normally removed when all savesets for a system have completed. However, if a backup for a client is aborted or the client crashes, the ".../<groupname>.tmp" file can be left around. The next time savepnpc runs, it will assume that the preprocessing commands have already run and will skip them, and the postprocessing commands will be skipped as well.
  9. On NT, don't use '@ECHO OFF' in the <groupname>.res file.
  10. The scripts/batch files that you do create do NOT have to be in /nsr/bin, but you do have to put their full path in the <groupname>.res file.
  11. Anything written to standard output by the preprocessing commands will appear in the savegroup completion notice. If this output is verbose, it'll be a nuisance. You might prefer to direct the output from the commands in your script to a log file for later examination.
  12. You won't see the output from the postprocessing commands, because the connection to the server has already dropped when these commands are run. I'd recommend redirecting their output to a log file so you can examine the result if something failed to restart. I have seen postprocessing commands fail when they didn't have someplace to write their standard output, so I recommend always redirecting them to a log.
  13. The preprocessing commands MUST return "success" (at least on Unix). If they return a failure code, each saveset backup will be skipped, and you'll get a message like "...! no output" in the completion notice for each saveset on the client.

The problem with the <GROUP>.tmp mentioned in this section is potentially quite serious. The symptom is that pre and post processing will fail silently, and the chances are that this will cause useless backups, e.g. of databases that are running and cannot be recovered. The savefixpnpc script solves this. This script was written in 1998 and has recently been updated to work with 6.1.1 and 6.1.2 on Solaris and HP-UX.

Here is the latest savefixpnpc:

 #!/bin/ksh
 # savefixpnpc V6.1.1, workaround for Legato bug LGTpa06002.
 # Author Dave Driver, Legato Systems, 1999.
 # This script is used on the client as the backup command.
 # Place this script in the same directory as the save command.
 # Configure the "backup command" field in the client to be savefixpnpc.
 # This script is totally unsupported, and is used at the user's own risk.
 # Legato Support provides no support for this script.
 # Originally written for NW 5.5.x on Solaris.
 # Updated November 2002 by Dave Driver, http://www.DriveConsultants.com/
 # to allow new command line options for the save command, and for HP-UX.
 # Now validated for all NetWorker versions up to 6.1.1.
 # Not tested on other Unix platforms or NetWorker versions higher than 6.1.1.
 export PATH=/bin:/usr/bin:/usr/sbin:/opt/networker/bin
 SAVEPARMS=
 while getopts s:c:N:e:f:b:F:I:g:l:t:m:w:y:W:BEiLnquSVvx OPT
         do
         case $OPT in
                 g) SAVEPARMS="$SAVEPARMS -$OPT $OPTARG"; GROUP=$OPTARG ;;
                 *) SAVEPARMS="$SAVEPARMS -$OPT $OPTARG" ;;
             esac
         done
 shift $(($OPTIND - 1))
 SS=$@
 SPNPCTMP=/nsr/tmp/$GROUP.tmp
 # Find out if group is already running
 ps -ef | egrep "preclntsave|pstclntsave" | grep "\-g $GROUP" \
         | tail -1 | read undef PCLNTSAVEPID undef
 # If the process is not present we want to be sure that the tmp
 # file does not exist. This could happen if a previous group
 # had terminated abnormally.
 if [ -z "$PCLNTSAVEPID" ] && [ -f $SPNPCTMP ]; then
         # tmp file exists, and we think it is redundant, but double check
         sleep $(($RANDOM/3276+10))
         ps -ef | egrep "preclntsave|pstclntsave" | grep "\-g $GROUP" \
                 | tail -1 | read undef PCLNTSAVEPID undef
         if [ -z "$PCLNTSAVEPID" ] && [ -f $SPNPCTMP ]; then
                 rm -f $SPNPCTMP
                 # Now wait a while so we don't recreate it too soon
                 sleep 3
         fi
 fi
 exec savepnpc $SAVEPARMS $SS 2>&1