Если различия есть - делается бинарный .backup и файл diff с различиями с предыдущим .rsc
Оригинал скрипта:
https://настройка-микротик.рф/backup-ssh-diff/
Ставим пакет:
Код: Выделить всё
apt-get install sshpass
Код: Выделить всё
mkdir -p /backup/scripts/
nano /backup/scripts/RouterOS.sh
Код: Выделить всё
#!/bin/sh
routername=$1
sshhost=$2
sshport=$3
sshuser="backup"
sshpassword="dsfr4wdfglhiklhiluawhfroiy8loasr5dgr6"
localpath="/backup/RouterOS"/$sshhost/$routername
mkdir $localpath
precedent_export_name="$routername-config-export-precedent.rsc"
current_export_name="$routername-config-export-current.rsc"
current_backup_name="$routername-config-backup-current.backup"
diff_export_name="$routername-config-export-diff.rsc"
current_export_name_history="$routername-$(date +%Y-%m-%d-%H-%M)-config-export-current.rsc"
current_backup_name_history="$routername-$(date +%Y-%m-%d-%H-%M)-config-backup-current.backup"
diff_export_name_history="$routername-$(date +%Y-%m-%d-%H-%M)-config-export-diff.rsc"
mkdir -p $localpath/history
cd $localpath
sshpass -p $sshpassword ssh -o StrictHostKeyChecking=no $sshuser@$sshhost -p $sshport export >$current_export_name
diff -I "RouterOS" $current_export_name $localpath/$precedent_export_name >$diff_export_name
if [ "$?" -ne "0" ]; then
sshpass -p $sshpassword ssh -o StrictHostKeyChecking=no $sshuser@$sshhost -p $sshport export file=$current_export_name
sshpass -p $sshpassword ssh -o StrictHostKeyChecking=no $sshuser@$sshhost -p $sshport system backup save name=$current_backup_name
sshpass -p $sshpassword sftp -o StrictHostKeyChecking=no -oPort=$sshport $sshuser@$sshhost:$current_backup_name
rm -f $precedent_export_name
cp $current_export_name $localpath/history/$current_export_name_history
cp $current_backup_name $localpath/history/$current_backup_name_history
mv $diff_export_name $localpath/history/$diff_export_name_history
mv -f $current_export_name $precedent_export_name
rm -f $diff_export_name
exit 1
fi
mv -f $current_export_name $precedent_export_name
rm -f $diff_export_name
exit 0
Код: Выделить всё
chmod +x /backup/scripts/RouterOS.sh
Код: Выделить всё
/backup/scripts/RouterOS.sh Название IP Порт