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 revisionLast revisionBoth sides next 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 [2020/01/08 19:47] – [Script startDatenBackup.sh] Maik Wodarz | ||
---|---|---|---|
Line 8: | Line 8: | ||
Using the app forseen for this button you can do some simple tasks like “copy all files from USB-Drive to a predefined destination folder” or “copy all files in predefined folder to USB drive. | Using the app forseen for this button you can do some simple tasks like “copy all files from USB-Drive to a predefined destination folder” or “copy all files in predefined folder to USB drive. | ||
- | When we talk about backups this is a quite poor solution. Wishable would be a trigger of a hyper backup job. Reason: hyperbackup does maintain a history of files. (like time capsule) and compresses. | + | When we talk about backups this is a quite poor solution. Wishable would be a trigger of a hyper backup job. Reason: hyperbackup does maintain a history of files. (like time capsule) and does compression. |
In addition the copy button action can only handle the front usb port of the Synology. | In addition the copy button action can only handle the front usb port of the Synology. | ||
- | 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 hyper backup app is installed | + | * Synology |
- | * Synlogy USB-Copy app is installed | + | * Synlogy |
- | * Hyper backup | + | * //Hyper backup// tasks using USB are configured |
====== Overview - general workflow ====== | ====== Overview - general workflow ====== | ||
* Create a cron job which checkt peridically a predefined file system location for existence of a flag file. (I’ll call it trigger file) | * Create a cron job which checkt peridically a predefined file system location for existence of a flag file. (I’ll call it trigger file) | ||
- | * 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) | ||
* Remember that a job is active => create the activity file (using touch) | * Remember that a job is active => create the activity file (using touch) | ||
Line 37: | Line 38: | ||
====== USB-Copy ====== | ====== USB-Copy ====== | ||
- | Originaly the USB-Copy app from Synology is intendet to do simple jobs like “copy file from USB drive to NAS” or “copy files from NAS to USB drive” when the copy button is pressed or a specific backup medium is detected. (UUID) It has to be installed by Synology package center. | + | Originaly the //USB-Copy// app from Synology is intendet to do simple jobs like “copy file from USB drive to NAS” or “copy files from NAS to USB drive” when the copy button is pressed or a specific backup medium is detected. (UUID) It has to be installed by Synology package center. |
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 fron USB port while USB detecting actions are working for the back site USB ports as well. | ||
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 beebs again twice. | ||
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.txt · Last modified: 2022/05/01 11:01 by Maik Wodarz