Tracker Posted December 12, 2022 Share Posted December 12, 2022 Hi everyone, I am searching for a backup solution, which starts autmatically the backup process on a attached external device and detache the device when backup is completed. Additionally a short notification e.g. via mail would be helpfull. Is their a kind of solution? I had this concept before with my old synology, to have manual backup. It was a additional fall back solution in the case of ransomware attack or fire/water damage. BR, Tracker Quote Link to comment
Kilrah Posted December 12, 2022 Share Posted December 12, 2022 That's an example in the first post of the unassigned devices plugin: Quote Link to comment
Hoopster Posted December 12, 2022 Share Posted December 12, 2022 (edited) 36 minutes ago, Tracker said: I am searching for a backup solution, which starts autmatically the backup process on a attached external device and detache the device when backup is completed. Additionally a short notification e.g. via mail would be helpfull AS Kilrah noted, check out the backup script example in the UD plugin thread. I modified the script to backup four of my shares (instead of just Photos in the example). As soon as I plug in the external USB backup drive: The drive mounts automatically via UD The backup script runs automatically, with a GUI and email notification it is running, until complete. The script backs up new/modified files only which makes it faster after the initial backup of everything There is a beep when it completes and you are notified in the unRAID GUI and via email The USB drive is unmounted in UD Edited December 12, 2022 by Hoopster 1 Quote Link to comment
Tracker Posted December 13, 2022 Author Share Posted December 13, 2022 @Hoopster do you have an example code for me, where I can see how the mail notification works and the copy implementation of some shares is shown? Quote Link to comment
Solution Hoopster Posted December 13, 2022 Solution Share Posted December 13, 2022 41 minutes ago, Tracker said: do you have an example code for me Here is the script with my modifications for backing up four shares: #!/bin/bash PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin ## Available variables: # AVAIL : available space # USED : used space # SIZE : partition size # SERIAL : disk serial number # ACTION : if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT # MOUNTPOINT : where the partition is mounted # FSTYPE : partition filesystem # LABEL : partition label # DEVICE : partition device, e.g /dev/sda1 # OWNER : "udev" if executed by UDEV, otherwise "user" # PROG_NAME : program name of this script # LOGFILE : log file for this script case $ACTION in 'ADD' ) # # Beep that the device is plugged in. # beep -l 200 -f 600 -n -l 200 -f 800 sleep 2 if [ -d $MOUNTPOINT ] then if [ $OWNER = "udev" ] then beep -l 100 -f 2000 -n -l 150 -f 3000 beep -l 100 -f 2000 -n -l 150 -f 3000 logger Started -t$PROG_NAME echo "Started: `date`" > $LOGFILE logger Pictures share -t$PROG_NAME rsync -a -v /mnt/user/Pictures $MOUNTPOINT/ 2>&1 >> $LOGFILE logger Videos share -t$PROG_NAME rsync -a -v /mnt/user/Videos $MOUNTPOINT/ 2>&1 >> $LOGFILE logger Movies share -t$PROG_NAME rsync -a -v /mnt/user/Movies $MOUNTPOINT/ 2>&1 >> $LOGFILE logger Family Videos share -t$PROG_NAME rsync -a -v /mnt/user/FamVideos $MOUNTPOINT/ 2>&1 >> $LOGFILE logger Syncing -t$PROG_NAME sync beep -l 100 -f 2000 -n -l 150 -f 3000 beep -l 100 -f 2000 -n -l 150 -f 3000 beep -r 5 -l 100 -f 2000 logger Unmounting Backup -t$PROG_NAME /usr/local/sbin/rc.unassigned umount $DEVICE echo "Completed: `date`" >> $LOGFILE logger Backup drive can be removed -t$PROG_NAME /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Backup completed" -i "normal" fi else logger Backup Drive Not Mounted -t$PROG_NAME fi ;; 'REMOVE' ) # # Beep that the device is unmounted. # beep -l 200 -f 800 -n -l 200 -f 600 ;; 'ERROR_MOUNT' ) /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Could not mount Backup" -i "normal" ;; 'ERROR_UNMOUNT' ) /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Could not unmount Backup" -i "normal" ;; esac I just added these lines for each share I wanted to backup to the Unassigned Devices USB drive: logger {name of share} share -t$PROG_NAME rsync -a -v /mnt/user/{name of share} $MOUNTPOINT/ 2>&1 >> $LOGFILE You just make the script the device script that is run when the USB drive is connected and mounted by Unassigned Devices. 47 minutes ago, Tracker said: where I can see how the mail notification works Email notifications are not controlled by the script. This is just part of the Settings-->Notification Settings configuration in the GUI. Here are my email settings to get unRAID to email notifications to me for the events selected in the Notification Setting section: 2 1 Quote Link to comment
Tracker Posted December 13, 2022 Author Share Posted December 13, 2022 Curently working on the script. Will post my work in a view days, when i have it optimized. Quote Link to comment
Tracker Posted December 21, 2022 Author Share Posted December 21, 2022 Following script iterates over the array entries, which contains the shares that needs to be backuped: #!/bin/bash PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin ## Available variables: # ACTION - if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT # DEVICE - partition device, e.g. /dev/sda1 # UD_DEVICE - unassigned devX designation # SERIAL - disk serial number # LABEL - partition label # LUKS - if the device is encrypted, this is the partition device, e.g. /dev/sda1 # FSTYPE - partition filesystem # MOUNTPOINT - where the partition is mounted # OWNER - "udev" if executed by UDEV, otherwise "user" # PROG_NAME - program name of this script # LOGFILE - log file for this script directorys=( "/mnt/user/folder1" "/mnt/user/folder2" "/mnt/user/folder3" "/boot/config/plugins/unassigned.devices") notify_event="<Name of NAS>" notify_subject="backup ext. disk" notify_message="Follwoing shares were synced:"$'\n' case $ACTION in 'ADD' ) # # Beep that the device is plugged in. # beep -l 200 -f 600 -n -l 200 -f 800 sleep 2 if mountpoint -q $MOUNTPOINT; then if [ $OWNER = "udev" ] then beep -l 100 -f 2000 -n -l 150 -f 3000 beep -l 100 -f 2000 -n -l 150 -f 3000 logger Started -t $PROG_NAME echo "Started: `date`" > $LOGFILE for dir in "${directorys[@]}"; do echo "#### Start: [`date`] ####" >> $LOGFILE echo "# sync of share: ${dir} #" >> $LOGFILE rsync -a -v "$dir" $MOUNTPOINT/ 2>&1 >> $LOGFILE echo "## End: [`date`] ##" >> $LOGFILE notify_message+="$dir"$'\n' done logger Syncing -t$PROG_NAME sync -f $MOUNTPOINT beep -l 100 -f 2000 -n -l 150 -f 3000 beep -l 100 -f 2000 -n -l 150 -f 3000 beep -r 5 -l 100 -f 2000 logger Unmounting Ext. HDDBackup Backup -t $PROG_NAME /usr/local/sbin/rc.unassigned umount $DEVICE echo "Completed: `date`" >> $LOGFILE logger Backup drive can be removed -t$PROG_NAME /usr/local/emhttp/webGui/scripts/notify -e "$notify_event" -s "$notify_subject" -d "Backup completed" -i "alert" -m "$notify_message" fi else logger Backup drive not mounted -t$PROG_NAME fi ;; 'REMOVE' ) # # Beep that the device is unmounted. # beep -l 200 -f 800 -n -l 200 -f 600 ;; 'ERROR_MOUNT' ) /usr/local/emhttp/webGui/scripts/notify -e "$notify_event" -s "$notify_subject" -d "Could not mount disk!" -i "alert" ;; 'ERROR_UNMOUNT' ) /usr/local/emhttp/webGui/scripts/notify -e "$notify_event" -s "$notify_subject" -d "Could not unmount disk!" -i "alert" ;; The mail notifcation works via "alert"-state for the notification method -> 'ERROR_MOUNT'/'ERROR_UNMOUNT' -> In the system settings of the NAS, under the notification conriguration, I configuered that system notification with alert state will send as mail to. 2 Quote Link to comment
Kosti Posted May 14, 2023 Share Posted May 14, 2023 (edited) Hey All, I know this is an old thread, however I want to back up the entire share content of my unraid server to a USB disk. Can I use copy and paste to use this script by @Tracker and just modify the directory's folder names right, do I need to name my unassigned drive to HDDBackup Backup to match this line in the above script logger Unmounting Ext. HDDBackup Backup -t $PROG_NAME Let me know PEACE Kosti Edited May 14, 2023 by Kosti Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.