Backup Ubiquiti Device Configuration (UBNT)

Somehow, our Ubiquiti (UBNT) antennas beat thunderstorms, which then had to be repaired, changed and naturally tuned again. Therefore, I decided to make an automatic copy of the configuration.

First, install the utility which will then help in the script to enter the password:

sudo apt install sshpass

Well, an example of my script:

# Create a directory with the current date and go to it
mkdir /home/backups/devices/ubnt/`date +%Y-%m-%d`
cd /home/backups/devices/ubnt/`date +%Y-%m-%d`
# Set password
# Make a copy of the configuration file in this directory.
sudo sshpass -p $PASS scp -oStrictHostKeyChecking=no -oConnectTimeout=3 ixnfo@ /home/backups/devices/ubnt/`date +%Y-%m-%d`/20_system.cfg
sudo sshpass -p $PASS scp -oStrictHostKeyChecking=no -oConnectTimeout=3 ixnfo@ /home/backups/devices/ubnt/`date +%Y-%m-%d`/21_system.cfg
# and so on for other antennas

Place the contents of the above script into an empty file, call it conveniently and add a link to the /etc/crontab scheduler, which will execute it every day, for example, at 4 am:

0 4 * * * root /home/backups/ > /dev/null 2>&1

As a result, a directory with a date (YEAR-MONTH-DAY) will be created every day and there will be backup copies of the configuration files for that day.

If the device is replaced by another one and has the same IP, you need to delete the old key with the command (can be added to the script for each device):

ssh-keygen -f "/root/.ssh/known_hosts" -R

You can also execute the command to send the configuration to the TFTP server on the device and, based on this, create a script, it’s a pity that I did not find the SNMP OID for this command, for example:

tftp -p -l /tmp/system.cfg -r test.cfg

Join the Conversation

1 Comment

Leave a Reply

  1. Hola, tengo como 100 dispositivos UBNT, me gustaría hacer a todos con un solo es scripts cual seria el guion? mil gracias por sus aportes.