knaackville

UDM backup to Unraid 6.9+

Mar 14th, 2021 (edited)
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## Created by Roger P, modified by knaackville
  4. ## Updated: 5/18/2022
  5. ## Created to backup my UDM backup files to Unraid NAS daily
  6. ## See https://github.com/boostchicken/udm-utilities/wiki/Backup-Your-UDM-Backup-Files-to-Another-Server for additional information.
  7.  
  8. ########################
  9. ##### Prerequisite #####
  10. ########################
  11.  
  12. # Requires Unraid 6.9+ due to changes in SSH key storage.  Works with 6.10
  13.  
  14. # Unraid Steps:
  15. ## SSH Unraid and run the following commands
  16. ## # ssh-keygen (enter to all options)
  17.  
  18. # Unraid Steps:
  19. ## SSH the UDM Pro Once (Needed to save the host as known address on Unraid)
  20. ## # ssh root@<UDMIP> (successfully connect once)
  21.  
  22. ## copy text from /root/.ssh/id_rsa.pub
  23. ## Add persistent SSH key to reboot of server https://github.com/boostchicken/udm-utilities/blob/master/on-boot-script/examples/udm-files/on_boot.d/15-add-root-ssh-keys.sh
  24. ## Also works with https://github.com/fire1ce/UDMP-Persistence-SSH-Keys  which is probably the preferred method now.
  25.  
  26. #####################################
  27. ##### User adjustable variables #####
  28. #####################################
  29.  
  30. UDMServer="10.0.0.2"
  31. toEmailAddress="[email protected]"
  32. fromEmailAddress="[email protected]"
  33. emailSubject="UDMPro Backup Error"
  34. emailBody="Error backing up UDMPro configuration file for $UDMServer."
  35. backUpPath="/mnt/user/appdata/UDMPro_backup"
  36. backUpsToKeep=365
  37. fixUnifi="-oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedAlgorithms=+ssh-rsa"
  38.  
  39. ##################
  40. ##### Script #####
  41. ##################
  42.  
  43. ## Check if backup directory exists, if it doesn't then create it
  44. if [ ! -d $backUpPath ]
  45. then
  46.   mkdir -p $backUpPath
  47. fi
  48.  
  49. ## Get latest backup
  50. scp $fixUnifi root@$UDMServer:/mnt/data/unifi-os/unifi/data/backup/autobackup/*.unf $backUpPath/ \
  51. ||  {
  52.      echo To: $toEmailAddress
  53.      echo From: $fromEmailAddress
  54.      echo Subject: $emailSubject
  55.      echo "$emailBody"
  56. } | ssmtp $toEmailAddress
  57.  
  58. ## Clean up old backups
  59. if [ $(ls -t |tail -n +$(( $backUpsToKeep + 1 )) |wc -l) -gt 0 ]
  60. then
  61.   rm $(ls -t $backUpPath |tail -n +$(( $backUpsToKeep + 1 )))
  62.  fi
Add Comment
Please, Sign In to add comment