Overview
Periodically backup the Lighthouse configuration in a local folder.
Products and Firmware*
List of products and firmware versions
Family | Product |
Article written using version |
Supported on firmware |
Lighthouse | Lighthouse | 23.04.0 | Any |
The configuration of Lighthouse can be backed up manually, this is documented in the following article of the online knowledge base.
This backup can be automated using the Command Line Interface (CLI).
All the operations are done using the superuser root. As an admin user, you can become root by running the command 'sudo -i' and providing your admin's password.
1. Making the script:
Create a script named “lighthouse-backup.sh” in the /etc/config/scripts/ folder. You May run the command below to automatically generate this script.
root@lighthouse:~#cat << 'EOF' > /etc/config/scripts/lighthouse-backup.sh
#!/bin/bash
var=$(date +"%F")
/etc/scripts/config_backup --filename=/mnt/nvram/backup/${var}-lh.backup
find /mnt/nvram/backup/ -name "*.backup" -mtime +365 -exec rm {} \;
EOF
This script must be set as executable.
root@lighthouse:~#chmod +x /etc/config/scripts/lighthouse-backup.sh
This backup file is going to be generated in the /mnt/nvram/backup folder and will have the following format:
<year>-<month>-<day>-lh.backup
To follow best practices, these backups should be exported to external storage.
2. Testing the Script
Manually launch the script and check that a backup file has been created
root@lighthouse:~# bash /etc/config/scripts/lighthouse-backup.sh
root@lighthouse:~#
root@lighthouse:~# ls -l /mnt/nvram/backup/
total 476
-rw-r----- 1 root root 487159 Jun 26 20:36 2023-06-26-lh.backup
root@lighthouse:~#
3. Schedule the Script
To launch this backup on a regular basis, a CRON job needs to be created to automate and schedule this task.
The format of a crontab file is very simple: each line contains six fields, separated by spaces.
The first field specifies the minute (0-59) when the job will be run, the second field specifies the hour (0-23), the third field specifies the day of the month (1-31), and so on.
<Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <command>
The following command allows the editing of the CRONTAB file.
# crontab -e
Once the CRONTAB is in edit mode, here are a few examples to schedule this automated task.
There is a protection to ensure you can not schedule multiple lines with the word backup.
#11 PM daily
crontab -l | grep -v backup ; echo '0 23 * * * bash /etc/config/scripts/lighthouse-backup.sh' | crontab -
#Every Sunday at 10 AM
crontab -l | grep -v backup ; echo '0 10 * * sun bash /etc/config/scripts/lighthouse-backup.sh' | crontab -
#Every 1st of the month (It will execute the task in the first minute of the month)
crontab -l | grep -v backup ; echo '@monthly bash /etc/config/scripts/lighthouse-backup.sh' | crontab -
All CRON jobs are listed using the following command.
# crontab -l
4. Example of Logs:
# tail -f /var/log/messages
<30>Dec 16 23:49:02 dhcpd: DHCPDISCOVER from 00:13:c6:08:57:26 via eth1
2023-06-26T20:52:01.192028+02:00 lighthouse crond[6097]: pam_unix(crond:session): session opened for user root by (uid=0)
2023-06-26T20:52:01.192518+02:00 lighthouse CROND[6098]: (root) CMD (bash /etc/scripts/lighthouse-backup.sh)
2023-06-26T20:52:01.205549+02:00 lighthouse BackupRestore: INFO: Creating configuration backup: /mnt/nvram/backup/2023-06-26-lh.backup
2023-06-26T20:52:01.210248+02:00 lighthouse BackupRestore: INFO: No user files
2023-06-26T20:52:01.718550+02:00 lighthouse BackupRestore: INFO: Unencrypted backup
2023-06-26T20:52:01.723756+02:00 lighthouse CROND[6097]: pam_unix(crond:session): session closed for user root
Comments
0 comments
Please sign in to leave a comment.