Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #!/bin/bash
 - ## Created by Roger P, modified by knaackville
 - ## Updated: 5/18/2022
 - ## Created to backup my UDM backup files to Unraid NAS daily
 - ## See https://github.com/boostchicken/udm-utilities/wiki/Backup-Your-UDM-Backup-Files-to-Another-Server for additional information.
 - ########################
 - ##### Prerequisite #####
 - ########################
 - # Requires Unraid 6.9+ due to changes in SSH key storage. Works with 6.10
 - # Unraid Steps:
 - ## SSH Unraid and run the following commands
 - ## # ssh-keygen (enter to all options)
 - # Unraid Steps:
 - ## SSH the UDM Pro Once (Needed to save the host as known address on Unraid)
 - ## # ssh root@<UDMIP> (successfully connect once)
 - ## copy text from /root/.ssh/id_rsa.pub
 - ## 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
 - ## Also works with https://github.com/fire1ce/UDMP-Persistence-SSH-Keys which is probably the preferred method now.
 - #####################################
 - ##### User adjustable variables #####
 - #####################################
 - UDMServer="10.0.0.2"
 - toEmailAddress="[email protected]"
 - fromEmailAddress="[email protected]"
 - emailSubject="UDMPro Backup Error"
 - emailBody="Error backing up UDMPro configuration file for $UDMServer."
 - backUpPath="/mnt/user/appdata/UDMPro_backup"
 - backUpsToKeep=365
 - fixUnifi="-oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedAlgorithms=+ssh-rsa"
 - ##################
 - ##### Script #####
 - ##################
 - ## Check if backup directory exists, if it doesn't then create it
 - if [ ! -d $backUpPath ]
 - then
 - mkdir -p $backUpPath
 - fi
 - ## Get latest backup
 - scp $fixUnifi root@$UDMServer:/mnt/data/unifi-os/unifi/data/backup/autobackup/*.unf $backUpPath/ \
 - || {
 - echo To: $toEmailAddress
 - echo From: $fromEmailAddress
 - echo Subject: $emailSubject
 - echo "$emailBody"
 - } | ssmtp $toEmailAddress
 - ## Clean up old backups
 - if [ $(ls -t |tail -n +$(( $backUpsToKeep + 1 )) |wc -l) -gt 0 ]
 - then
 - rm $(ls -t $backUpPath |tail -n +$(( $backUpsToKeep + 1 )))
 - fi
 
                    Add Comment                
                
                        Please, Sign In to add comment