-
-
Save howellcc/70f5c45a9902f9a3fe4e566ceedf1bca to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| #https://gist.github.com/howellcc/70f5c45a9902f9a3fe4e566ceedf1bca | |
| #This is a backup script that I'm running on my Synology NAS to back up my Hubitat Elevation. | |
| he_login=[Hubitat Username] | |
| he_passwd=[Hubitat Password] | |
| he_ipaddr=[Hubitat IP Address] | |
| backupdir='[Backup Location]' #no trailing space | |
| hubname='Hubitat' #in case you have multiple hubs | |
| versionsToKeep=60 | |
| #fix a silly off by 1 error | |
| ((versionsToKeep=versionsToKeep+1)) | |
| cookiefilename='cookiefile.txt' | |
| cookiefile=$backupdir/$cookiefilename | |
| backupfilename=${hubname}_$(date +%Y-%m-%d-%H%M).lzf | |
| curl -k -c $cookiefile -d username=$he_login -d password=$he_passwd https://$he_ipaddr/login | |
| curl -k -sb $cookiefile https://$he_ipaddr/hub2/localBackups \ | |
| | jq '.[-1].path' \ | |
| | sed -e 's/.*dbBackup\///' -e s/\"// \ | |
| | xargs -I @ curl -k -sb $cookiefile https://$he_ipaddr/hub//backupDB?fileName=@ -o $backupdir/$backupfilename \ | |
| || exit 1 | |
| #for some reason these end up with 777 permissions | |
| chmod 440 $backupdir/$backupfilename | |
| #Delete all but the most recent X backups | |
| ls -tp $backupdir/*.lzf | grep -v '/$' | tail -n +$versionsToKeep | xargs -I {} rm -- {} | |
Thanks for the update! I haven’t had a reason to check my backup destination folder for a couple months so hadn’t even realized there was an issue!!
Yeah... my cron job started reporting errors when it ran out of backups to delete. Otherwise I may have never found out. If/When I get some time, there will likely be a future iteration that includes notification should backup retrieval fail. Though that may require re-writing it in python.
Thanks for the awesome script! I added -s to all three curl commands so the output doesn't have the screen output of the progress of the script in the automatic email confirming it ran on my Synology NAS. Thanks again!
Great script. Line 30 should be fixed to use the variable in line 9 though.
Great script. Line 30 should be fixed to use the variable in line 9 though.
you're right. This is what happens when I write it for myself, then try to make it generic to share.
Thanks for the update! I haven’t had a reason to check my backup destination folder for a couple months so hadn’t even realized there was an issue!!