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 ftp user1 user1pass


Here’s the product reference

Here’s the documentation for the E-Series

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

[sourcecode language=”bash”]
<# 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


  1. Hi. Thank you for the valuable information.
    Please let me know if it is possible to copy the running-configuration as .scr file to local storage.
    Kindly share your thoughts.

    1. Hi Jayashree,

      Thank you for posting the question. When discussing local storage there are two contextual perspectives that come to mind when using the CLI.
      1) Local storage on the ERX
      2) Local storage in relation to the management terminal session

      A configuration .src file can be saved to the ERX’s local file system as seen in the above macro script (#1 above).

      Configuration files can also be directly saved to a remote system via two transfer protocols (FTP and TFTP) from version 6.x. Presuming the management terminal session is also providing FTP/TFTP services, and then it is possible to save the .scr configuration directly (#2 above).

      In the past though, I personally saved the configurations to a purposed platform for archiving. It was from archive system that I would then transfer a configuration to my local workstation for any kind of work.

      SFTP can be used to copy files too, however it does have limited functionality.

      JUNOSe also supports the role of an NFS client, however this functionality is not implemented in a manner that provides mounting/un-mounting of files via the CLI.

      Here is a reference to specifics of what is mentioned above; chapter “Managing the System” in the “JunosE 14.3.x System Basics Configuration Guide”.

    1. Uniqueness is paramount in the context of backups, so yes I did use a variable which was equal to the date with time stamp. This was performed by the calling method (script) of the macro. If you mean to ask if I used an [ARG] value to the script, no.

Leave a Reply