Juniper MX configuration backup

In this article, I will write an example script that will connect to the Juniper MX204 from Linux and copy the configuration to the TFTP server, and also give an example of commands that activate automatic copying of the configuration to the server via SSH.

JunOS has a built-in TFTP client that can be used by going to the shell. I will give an example of a simple script that will connect to Juniper via telnet and execute the commands: launching a shell, connecting to a TFTP server, copying the configuration and disconnecting from Juniper:

sleep 5
echo "admin"
sleep 5
echo "password"
sleep 5
echo "start shell"
sleep 2
echo "cd /config"
sleep 1
echo "tftp"
sleep 1
echo "connect"
sleep 1
echo "put juniper.conf.gz"
sleep 15
echo "quit"
sleep 2
echo "exit"
) | telnet
mv /srv/tftp/juniper.conf.gz /root/devices/juniper/`date +%Y-%m-%d`_juniper.conf.gz

In a similar way, you can write a script that will download the configuration for example via SSH (CSP), examples can be found in my other articles.
To automatically execute the script, you can add it to /etc/crontab:

0 1 * * * root /root/scripts/ >/dev/null 2>&1

JunOS is also able to independently make backups to FTP and SCP, on a schedule or at each commit, I will give an example of setting:

set system archival configuration transfer-interval (15-2880 minutes) archive-sites "scp:// password test"
set system archival configuration transfer-on-commit archive-sites "scp:// password test"

See also my articles:
Connecting via SSH key to Juniper
Juniper MX204 setup
Using and configuring CRON
Backup Ubiquiti Device Configuration (UBNT)

Leave a comment

Leave a Reply