1
Tutorials and FAQs / Re: Automatic config backups using os-api-backup
« on: March 18, 2024, 05:21:38 pm »
Mine is slightly different but here's an updated script for those of you who are maybe less technically inclined. Just update the 5 variables at the top to match your configuration and you should be good to go. You'll just need to setup a cron job to run this nightly - the script below will also work run directly from a synology system.
Code: [Select]
#!/usr/bin/bash
# Change API key and secret, number of days to keep backups, the path to your backups and the hostname for your firewall
key=YOURKEY
secret=YOURSECRET
daystokeep=30
destination="/PATH/TO/SAVE/BACKUPS/TO"
fwhost="IP_ADDRESS_OF_FIREWALL-192.168.1.1"
date=$(date +%Y-%m-%d)
result=$(/usr/bin/curl -I -s -k -u "$key":"$secret" https://$fwhost/api/core/backup/download/this | head -1)
if [[ $result != *"200"* ]]; then
echo "Result of the HTTP request is $result"
exit 1
fi
/usr/bin/curl -s -k -u "$key":"$secret" https://$fwhost/api/core/backup/download/this > $date.xml
error=$?
if [ $error -gt 0 ]; then
echo "Curl returned error number $error"
exit 1
fi
/usr/bin/gzip $date.xml
mv $date.xml.gz $destination
/usr/bin/find $destination/* -mtime +$daystokeep -exec rm {} \;