publications:synology_trigger_hyper_backup_on_usb_connect
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| publications:synology_trigger_hyper_backup_on_usb_connect [2020/01/08 18:41] – [Trigger check] Maik Wodarz | publications:synology_trigger_hyper_backup_on_usb_connect [2022/05/01 11:01] (current) – Maik Wodarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== About ====== | ====== About ====== | ||
| - | This article describes how can be configured an automatic USB hyperbackup, which is triggered by USB-connect. | + | This article describes how can be configured an automatic USB //hyper backup//, which is triggered by USB-connect. |
| ====== Introduction ====== | ====== Introduction ====== | ||
| - | The synology diskstation | + | The //Synology Diskstation (DS)// |
| My DS-216 has a copy button. | My DS-216 has a copy button. | ||
| - | Using the app forseen | + | Using the app foreseen |
| - | When we talk about backups this is a quite poor solution. | + | Talking |
| - | In addition the copy button action can only handle the front usb port of the Synology. | + | In addition, the // |
| - | Sadly the solution | + | My solution |
| + | I wanted to find a solution without third party software. | ||
| - | The following article describes preconditions, | + | The following article describes preconditions, |
| ====== Preconditions ====== | ====== Preconditions ====== | ||
| - | * ssh access to synology nas is enabled and the user is aware how to use it. | + | * SSH access to Synology NAS is enabled and the user is aware how to use it |
| - | * Basic knowledge about usage of bash and vi editor. | + | * Basic knowledge about usage of BASH and VI editor |
| - | * Synology | + | * //Synology |
| - | * Synlogy USB-Copy app is installed | + | * //Synlogy USB-Copy// app is installed |
| - | * Hyper backup | + | * //Hyper backup// tasks using USB are configured |
| ====== Overview - general workflow ====== | ====== Overview - general workflow ====== | ||
| - | * Create a cron job which checkt | + | * Create a cron job which checks |
| - | * Create an USB copy job using USB-Copy app from Synology, which copies a trigger file from a just connected USB drive to predefined location on NAS. | + | * Create an USB copy job using //USB-Copy// app from Synology, which copies a trigger file from a just connected USB drive to predefined location on NAS. |
| - | * When the cron job finds the trigger file and there is still no active job (activity file) | + | * When the cron job finds the trigger file and there is still no active job (activity file), then: |
| * Remember that a job is active => create the activity file (using touch) | * Remember that a job is active => create the activity file (using touch) | ||
| * Remove the trigger file | * Remove the trigger file | ||
| Line 37: | Line 38: | ||
| ====== USB-Copy ====== | ====== USB-Copy ====== | ||
| - | Originaly | + | Originally |
| - | Actions caused by copy button are affecting only the fron USB port while USB detecting actions are working for the back site USB ports as well. | + | Actions caused by copy button are affecting only the front USB port while USB detecting actions are working for the back site USB ports as well. |
| - | For my objective – triggering a hyper backup job – I simply copy a flag file from predefined location on USB drive to a predefined location on NAS. So after connecting the USB drive a file named autobackup is copied to | + | For my objective – triggering a // |
| / | / | ||
| The following screenshot is depicting it. | The following screenshot is depicting it. | ||
| Line 55: | Line 56: | ||
| / | / | ||
| | | ||
| - | The USB-Copy program lets beep the NAS after connecting twice. | + | The //USB-Copy// program lets beep the NAS after connecting twice. |
| - | After finishing the trigger file it beebs again twice. | + | After finishing the trigger file it beeps again twice. |
| ====== Trigger check ====== | ====== Trigger check ====== | ||
| The trigger checker script / | The trigger checker script / | ||
| {{: | {{: | ||
| - | First the script is checking if it is running already. (avoid duplicate run) | + | First, the script is checking if it is running already. (avoid duplicate run) |
| In order to do so it checks if the activity file exists. (''/ | In order to do so it checks if the activity file exists. (''/ | ||
| Line 68: | Line 69: | ||
| If the activity file exists, it terminates immediately. Otherwise it continues. | If the activity file exists, it terminates immediately. Otherwise it continues. | ||
| - | Then it determines the trigger file counts. (counts | + | Then it determines the trigger file counts. (count directory entries in: |
| / | / | ||
| Line 77: | Line 78: | ||
| So it is possible to connect the second backup drive a bit later or even in the same moment. The backups are handled serial. | So it is possible to connect the second backup drive a bit later or even in the same moment. The backups are handled serial. | ||
| - | What happens when a trigger counter is bigger than Zero?: | + | What happens when a trigger counter is bigger than zero?: |
| * Create activity file (using touch command) | * Create activity file (using touch command) | ||
| * Remove all entries in trigger folders: | * Remove all entries in trigger folders: | ||
| Line 131: | Line 132: | ||
| fi | fi | ||
| </ | </ | ||
| + | ====== Backup task id ====== | ||
| + | Hyper backup has a config file in ''/ | ||
| + | |||
| + | There all hyper backup tasks are configured. | ||
| + | |||
| + | We need to identify our task and derive the is from task phrase. (see middle line in the screenshot) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | You can determine the id by taking a look tot he number. Just cut of “task_”. So in our screenshot the task is is 4. | ||
| + | |||
| + | ====== Synousbcopy ====== | ||
| + | ''/ | ||
| + | |||
| + | What can '' | ||
| + | / | ||
| + | Shows the help. | ||
| + | |||
| + | I’ll use it in order to manipulate the copy LED state. In addition, it can be used for unmounting USB-drives. (eject) | ||
| + | |||
| + | ====== Synobackup ====== | ||
| + | ''/ | ||
| + | |||
| + | / | ||
| + | | ||
| + | When hyper backup is done it eject’s the corresponding USB drive. So we don’t need to care about ejecting. | ||
| + | |||
| + | ====== Script startDatenBackup.sh ====== | ||
| + | This script or the corresponding counterpart '' | ||
| + | |||
| + | It does the following: | ||
| + | * activate copy LED blinking | ||
| + | * triggers //hyper backup// task | ||
| + | * waits until the hyper backup task finishes. | ||
| + | * Deactivates the copy LED | ||
| + | |||
| + | '' | ||
| + | < | ||
| + | #!/bin/sh | ||
| + | LOGFILE="/ | ||
| + | |||
| + | / | ||
| + | ctime=`date -R` | ||
| + | echo "[I] $ctime starting daten backup" | ||
| + | / | ||
| + | sleep 60 | ||
| + | while [ " | ||
| + | do | ||
| + | | ||
| + | echo "[D] $ctime still running ..." >> $LOGFILE | ||
| + | sleep 60 | ||
| + | done | ||
| + | |||
| + | #/ | ||
| + | / | ||
| + | |||
| + | ctime=`date -R` | ||
| + | echo "[D] $ctime daten backup done." >> $LOGFILE | ||
| + | |||
| + | return 0 | ||
| + | </ | ||
| + | |||
| + | ====== Script startMediaBackup.sh ====== | ||
| + | Is the same as '' | ||
| + | The only difference ist he task id and some logging output. | ||
| + | '' | ||
| + | |||
| + | ====== Activity file (/ | ||
| + | ''/ | ||
| + | |||
| + | ====== Logging ====== | ||
| + | The scripts ''/ | ||
| + | |||
| + | ====== References ====== | ||
| + | [1] [[https:// | ||
publications/synology_trigger_hyper_backup_on_usb_connect.1578508892.txt.gz · Last modified: by Maik Wodarz
