Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #!/bin/bash
 - ## Created by Roger P
 - ## Updated: 7.20.2020
 - ## Created to backup my UDM backup files to Unraid NAS daily
 - ########################
 - ##### Prerequisite #####
 - ########################
 - # Unraid Steps:
 - ## Install Nerd Pack
 - ### Install expect package
 - # 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)
 - # Unraid Steps:
 - ## Backup the Keys so when Unraid is rebooted we ratain a copy
 - ## # cp /root/.ssh/id_rsa /boot/config/ssh
 - ## # cp /root/.ssh/id_rsa.pub /boot/config/ssh
 - ## # cp /root/.ssh/known_hosts /boot/config/ssh
 - # Unraid Steps:
 - ## Create a script with the UDM password
 - ## # touch /mnt/user/appdata/login.expect
 - ## # chmod +x /mnt/user/appdata/login.expect
 - ## edit the file and add the following (Change <UDM SSH Password>) (Don't add COMMENT1)
 - <<COMMENT1
 - #!/usr/bin/expect -f
 - spawn ssh-copy-id $argv
 - expect "password:"
 - send "<UDM_SSH_Password>\n"
 - expect eof
 - COMMENT1
 - #####################################
 - ##### User adjustable variables #####
 - #####################################
 - userName=root
 - 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
 - ##################
 - ##### Script #####
 - ##################
 - ## Move ssh files back to .ssh. This is needed after reboots
 - cp /boot/config/ssh/id_rsa /root/.ssh/
 - cp /boot/config/ssh/known_hosts /root/.ssh/
 - cp /boot/config/ssh/id_rsa.pub /root/.ssh/
 - ## Run This to ensure ssh keys are re-added to UDM upon reboot
 - cd /mnt/user/appdata/
 - ./login.expect $userName@$UDMServer
 - ## Check if backup directory exists, if it doesn't then create it
 - if [ ! -d $backUpPath ]
 - then
 - mkdir -p $backUpPath
 - fi
 - ## Get latest backup
 - scp $userName@$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