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:
#!/bin/bash # 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 PASS=text # Make a copy of the configuration file in this directory. sudo sshpass -p $PASS scp -oStrictHostKeyChecking=no firstname.lastname@example.org:/tmp/system.cfg /home/backups/devices/ubnt/`date +%Y-%m-%d`/20_system.cfg sudo sshpass -p $PASS scp -oStrictHostKeyChecking=no email@example.com:/tmp/system.cfg /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/backups_cfg.sh > /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 192.168.1.20
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 192.168.2.2