- Tested in CentOS 7 and on CRS354-48G-4S+2Q+RM
- Curl already installed or use install command
yum -y install curl - Snmpget and mibs-libary already installed or use install command
yum -y install net-snmp net-snmp-utils - Create folder for script, logs, tmp and backup files
mkdir /opt/swos_bkp - Switch system's name must not contain spaces and must be unique!
- Uses directory
/opt/swos_bkp/for all files - Creates directory for today backup files, for example
/opt/swos_bkp/bkp_files/16:00-30.12.2022 - Clears old tmp files '*.swb' in the
/opt/swos_bkp/tmp/ - Read 'hostsw' file with IPs line by line
- Makes a snmp-request to an IP from 'hostsw' to find out the platform
- Makes a snmp-request to find out the system name. System's name must be without backspaces
- Downloads config file by curl to
/opt/swos_bkp/tmpdirectory - Checks the downloaded configuration for errors (too small weight, less than 100b and 401 errors in the downloaded file)
- Moves checked the configuration file from
*/tmpto/opt/swos_bkp/bkp_files/$date/$filename, for example/opt/swos_bkp/bkp_files/16:00-30.12.2022/MikroTik-1.swb - Logs writes in the file
/opt/swos_bkp/log/swos_bkp.log - Deletes the old backup directory if found. Var
days_to_keepin begining of the script
yum -y install curlyum -y install net-snmp net-snmp-utilsmkdir /opt/swos_bkp- Copy or unzip this repository in the directory
/opt/swos_bkp/ - Write your SwOS IPs in the
/opt/swos_bkp/hostsw - Edit the vars
snmp_commname,user,passin the script fileswos_backup.sh chmod +x /opt/swos_bkp/swos_backup.sh- Use cron for run the script would you like. For example:
crontab -e- Write this command and save
00 16 * * * root /opt/swos_bkp/swos_backup.sh >> /var/log/messages 2>&1 - For more information google how to crontab works :) or click here.
- Rotate logs file would you like. For example rotateing once day a week:
touch /etc/logrotate.d/swos_bkpvi /etc/logrotate.d/swos_bkp- Write this and save in the file
/opt/swos_bkp/log/*.log { rotate 3 weekly compress missingok notifempty } - Enjoy