JUNOSe

Calling a Juniper JUNOSe Macro Script

In the post titled Juniper JUNOSe Macro Backup Script I detailed a method I used to backup the configuration of the broadband router. What I didn’t include was the command used to call the macro script; kind-of an important item to define.

host1(config)#macro run_backup_rtrname.mac

Juniper JUNOSe Macro Backup Script

For many years I maintained a Juniper ERX1410 running JUNOSe. Over time I created a backup script in 2007 that would allow me to initiate a backup of the broadband router and move on to another task while the backup processed.

An E Series router has an embedded macro language that enables you to define and run macros that can generate and execute CLI commands. Macro files—identified by the .mac extension—can be used to store more than one macro. Depending on your needs, you might want to store all of your macros in one file, group macros by function, or store only one macro per file.” – Juniper documentation

JUNOSe can provide two types of backup files; a human readable txt with an .SRC extension and the binary type is .CNF. It can move these files to a remote server using the FTP protocol.
The JUNOSe macro script can reside on the local router or it can reside on a remote FTP server. JUNOSe allows for the execution of the macro script from either a local filesystem or a remote system over the FTP protocol (Kind-a cool).

The CLI command sets used in the macro script are the following,

!
copy running-configuration backupfile.cnf
show running-configuration > backupfile.scr
!
copy backupfile.cnf ftp:backupfile.cnf
copy backupfile.scr ftp:backupfile.scr
!

In the above you will see the “…ftp:backupfile.cnf”; it should raise a question as to how the ERX knows what host to use since there is no DNS name or IP address defined. Before the above can be used, a static host entry needs to be created for the FTP destination. Here is an example of what that would look like,

!
host ftp 192.168.1.1 ftp user1 user1pass
!

(host <ID DESC> <IP ADD> <PROTOCOL> <USER> <PASS>)

Here’s the product reference

http://www.juniper.net/us/en/products-services/routing/e-series/

Here’s the documentation for the E-Series

http://www.juniper.net/techpubs/software/erx/

Here is the script I used running JUNOSe version 6.x on an ERX1410 platform.

<# start #>
<# setoutput console #>

***********************************************************************
 Name:          Configuration Backup Macro
 File Name:     run_backup_rtrname.mac
 Version:       0.1.0
 Created By:    Jeff Neuffer Jr
 Created On:    6/12/2007
 Last Modified: $Id$
 Description:   Used for backing up JUNOSe to .scr and .cnf and
                making a copy of the backup files by placing those
                files on a remote FTP server
***********************************************************************
<# endsetoutput #>

<# file_name := "rtrname" #>

<# setoutput console #>

Requesting .CNF file

<# endsetoutput #>

copy running-configuration <# file_name #>.cnf

<# setoutput console #>

Requesting .SRC file

<# endsetoutput #>

show configuration > <# file_name #>.scr

<# setoutput console #>

Sending both files to FTP Server

<#endsetoutput #>

copy <# file_name #>.cnf ftp:<# file_name #>.cnf
copy <# file_name #>.scr ftp:<# file_name #>.scr

<# setoutput console #>

Done with Sending both files to FTP Server.
Calling up local flash filesystem to see
that the file timestamps match today's time
of backup.

<#endsetoutput #>
show clock
terminal length 0
dir

<#endtmpl#>