Router Configuration Backup Utility  (copy_to_tftp)

Top  Previous  Next

This script backs up the router configuration files to a TFTP server.  It cycles through a list of routers performing a “copy running-config tftp:”. 

 

Program Name: copy_to_tftp

 

Script Argument

Description

-rf <filename>

List of routers or IP Address to run script against (REQUIRED)

-ipaddr <ip addr>

IP Address of TFTP Server.  This does not have to be the same IP Address as the system that the script is being run from.  The script can run from a Sun Solaris system but the TFTP server IP Address can be a PC.  (REQUIRED)

-tftproot <tftp root directory>

This option will enable the script to “touch” the configuration filename on a UNIX TFTP server before backing up each router config.  If used in combination with the subdir option, the script will also create the directory under the ROOT TFTP directory.  In order for the script to perform these operations, the script needs to know the TFTP Root directory. In addition, for this option to apply, the TFTP server ip address must be the same as the system that the script is being run from.    

-subdir <directory name>

A sub-directory under the main TFTP directory that the configuration files should be written to.  This is a relative path name NOT and absolute path name (OPTIONAL)

-autodir <date | time>

Automatically create unique directory  name to save configuration files to.  The choices are date or time.   The date option will create a new directory consisting  of just the date

e.g. 08012010 for Aug 1st 2010. 

 

The time option will append the time to the date:

e.g. 08012010_12h36m15s

 

The -tftproot option must be specified when using  this option.  The -subdir may also be used with this option if desired."

 

The purpose of this new option is to make nightly backups of router configurations even easier.  Previously, it was up to the end-user to create a unique name using only the -subdir option.  If doing automated nightly backups, this required a little shell scripting (Linux/Unix) or Windows shell programming to create a unique directory name that was passed to the -subdir option.  This is no longer necessary.

See example below.

-wm

Saves configuration file to NVRAM after copying file to TFTP server.  If tftp backup failed, the write mem will not be performed.  This option performs a “write memory” on the router.  (OPTIONAL)

-nokey

Dont prompt user for encryption key when using encrypted password file.  (OPTIONAL)

-urfn

Use Route File Name.  Use ip address/name in route file for config file name instead of router hostname.

-ssh

Use Secure Shell when accessing routers.  Do NOT use with -pw option. (OPTIONAL)

-pw <filename>

Login/Password File.  (OPTIONAL)

-log <filename>

Save detailed trace file to a name other than the default file name.  (OPTIONAL)

-ulog

Unique Log file.  Save detailed trace log file to a Unique filename automatically created by script. Filename will be in format of scriptname_timestamp.log. (OPTIONAL)

 

The configuration filename that is saved to the TFTP server is <routername-confg>.  This is the default file name that the router chooses.  There is also an option to have the configuration filename be the name/ip_address that is specified in the router file (i.e. rf <filename>).  This is done using the urfn option.   For example, if one of the lines in the router file is 10.10.1.1, then the config file name would be 10.10.1.1-confg.  The directory that the configuration files are saved to, can also be changed using the “-subdir” option.  By default the script will attempt to save the configuration file to the root TFTP directory.  By using the subdir option, you can have multiple configuration files for the same router saved under different directories.  Multiple levels below the root tftp directory can be specified (See the 2nd example below)

 

Also when using a UNIX TFTP server, the file name for the router configuration files must be created before the script runs.  This is typical behavior for UNIX TFTP servers.  By using the tftproot option the script will create (i.e. UNIX touch command) the configuration files on the TFTP server for you so you dont have to do it manually.  Using the subdir and tftproot options together enables the script to create a new directory, under the tftp root directory, and “touch” the config files in that directory.  When using the tftproot option, the TFTP server ip address must be the same as the system that the script is being run from. (Note, A TFTP sub-directory created by the script (-subdir) will create the directory with the permissions of “read-write-execute” for “user-group-other” respectively [or 777].  Router configuration files that are touched by the script, will be created with “read-write” permissions for “user-group-other” respectively [or 666]).

 

For TFTP Server applications on Microsoft Windows Platforms, the filename usually does not need to pre-exist on the TFTP Server before the router attempts to write its configuration file to the TFTP Server.   

 

Sample Command: The following command will backup the configuration files for the routers listed in the file rtrs.rt.  The files will be backed up to the 10.10.1.20 TFTP Server.  The configs will be stored in a sub-directory under the root TFTP directory named 02-25-03_configs.  The config files will automatically be touched on the TFTP server.  The tftproot option also causes the script to automatically create the directory specified in the subdir option.  The script WILL prompt the user for passwords because the -pw option is not being used.

 

copy_to_tftp rf rtrs.rt ipaddr 10.10.1.20 subdir 02-25-03_configs tftproot /tftpboot

 

Sample Command: This example emphasizes that the script can create multilevel directories under the root tftp directory.  The following command will backup the configuration files for the routers listed in the file rtrs.rt.  The files will be backed up to the 10.10.1.20 TFTP Server.  The configs will be stored in a sub-directory under the root TFTP directory named abc/02-25-03_configs.  The config files will automatically be touched on the TFTP server.  The tftproot option also causes the script to automatically create both directories specified in the subdir option.  The script WILL prompt the user for passwords because the -pw option is not being used.

 

copy_to_tftp rf rtrs.rt ipaddr 10.10.1.20 subdir abc/02-25-03_configs tftproot /tftpboot

 

Sample Command: This example shows the use of the autodir option.  The following command will backup the configuration files for the routers listed in the file rtrs.rt.  The files will be backed up to the 10.10.1.20 TFTP Server.  Assuming the date is August 5th 2010, the configs will be stored in /tftpboot/rtr_configs/08052010.   Note, the rtr_configs directory does not have to exist before the script is run.  The script  will not prompt the user for passwords or a password encryption key because the -pw option is used with an unencrypted password file.  The -ulog opition will automatically create a unique detailed trace log file.

 

copy_to_tftp -ulog -pw logins.txt rf rtrs.rt ipaddr 10.10.1.20 tftproot /tftpboot subdir rtr_configs -autodir date

 

Sample Command: Same example as above but password file is encrypted.  Here, the user will not be prompted for a password encryption key because the  -nokey option is specified.  This command line is a good example of all that would be need to put into a Unix/Linux shell file or a windows batch file.  The shell file or batch file could then easily be called to run through cron or windows scheduler.

 

copy_to_tftp -ulog -nokey -pw logins_encr.txt rf rtrs.rt ipaddr 10.10.1.20 tftproot /tftpboot subdir rtr_configs -autodir date