User Tools

Site Tools


publications:synology_trigger_hyper_backup_on_usb_connect

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
publications:synology_trigger_hyper_backup_on_usb_connect [2020/01/08 18:52] – [Activity file (''/opt/bin/checkTrigger.sh'')] Maik Wodarzpublications: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 out of the box isn’t able to start an backup job automatically as reaction of USB hard drive connection.+The //Synology Diskstation (DS)// out of the box isn’t able to start an backup job automatically as reaction of USB hard drive connection.
  
 My DS-216 has a copy button. My DS-216 has a copy button.
  
-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 foreseen 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 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.+Talking about backupsthis isn'a solution. Desired would be a trigger for a hyper backup job. Reason: //hyper backup// 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 additionthe //Copy// button action can only handle the front USB port of the //Synology DS//.
  
-Sadly the solution of Bernd Distler [1] is not working anymore because I couldn’t get running the autorun functionality.+My solution is derived from Bernd Distler'[1] solution. Bernd Distler is using //autorun//, a 3th party package. 
 +I wanted to find a solution without third party software.
  
-The following article describes preconditions, the general workflow as well as the details how it is possible to trigger a hyper backup job start on USB connect event.+The following article describes preconditions, the general workflow as well as the details how it is possible to trigger a //hyper backup// job start on USB connect event.
  
 ====== 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 Hyper backup// app is installed 
-  * Synlogy USB-Copy app is installed +  * //Synlogy USB-Copy// app is installed 
-  * Hyper backup jobs using USB are configured.+  * //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 checks 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), 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 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.+Originally the //USB-Copy// app from Synology is intended 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 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 //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
   /volume1/Shared/USB_AUTO_BACKUP/TRIGGERS/DATEN/autobackup   /volume1/Shared/USB_AUTO_BACKUP/TRIGGERS/DATEN/autobackup
 The following screenshot is depicting it. The following screenshot is depicting it.
Line 55: Line 56:
   /volume1/Shared/USB_AUTO_BACKUP/TRIGGERS/MEDIA/autobackup    /volume1/Shared/USB_AUTO_BACKUP/TRIGGERS/MEDIA/autobackup 
      
-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 /opt/bin/checkTrigger.sh is called by cron every minute. The trigger checker script /opt/bin/checkTrigger.sh is called by cron every minute.
 {{:publications:2020-01-08_13_34_42-wodarz_burstnas_.png?600|}} {{:publications:2020-01-08_13_34_42-wodarz_burstnas_.png?600|}}
-First the script is checking if it is running already. (avoid duplicate run)+Firstthe script is checking if it is running already. (avoid duplicate run)
  
 In order to do so it checks if the activity file exists. (''/opt/var/dataBackupRunning'') In order to do so it checks if the activity file exists. (''/opt/var/dataBackupRunning'')
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 directory entries in:+Then it determines the trigger file counts. (count directory entries in:
  
   /volume1/Shared/USB_AUTO_BACKUP/TRIGGERS/DATEN/ and    /volume1/Shared/USB_AUTO_BACKUP/TRIGGERS/DATEN/ and 
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 143: Line 144:
  
 ====== Synousbcopy ====== ====== Synousbcopy ======
-''/usr/syno/bin/synousbcopy'' was a script until DSM5. So it was easier to manipulate it respective to replace it inside file system. Further, this script was containing the whole copy button handling. Since DSM6 the copy button acting was moved into an app called USB-Copy. Nowadays the script is still there but contains some helper functions probably used by the USB-Copy” app.+''/usr/syno/bin/synousbcopy'' was a script until DSM5. So it was easier to manipulate it respective to replace it inside file system. Further, this script was containing the whole copy button handling. Since DSM6 the copy button handlich was moved into an app called //USB-Copy//. Nowadays the script is still there but contains some helper functions probably used by the //USB-Copy// app.
  
-What can synousbcopy do for us? +What can ''synousbcopy'' do for us? 
   /usr/syno/bin/synousbcopy –h    /usr/syno/bin/synousbcopy –h 
 Shows the help. Shows the help.
Line 159: Line 160:
  
 ====== Script startDatenBackup.sh ====== ====== Script startDatenBackup.sh ======
-This script or the corresponding counterpart startMediaBackup.sh is the heart of the trigger process.+This script or the corresponding counterpart ''startMediaBackup.sh'' is the heart of the trigger process.
  
 It does the following: It does the following:
   * activate copy LED blinking   * activate copy LED blinking
-  * triggers hyper backup task+  * triggers //hyper backup// task
   * waits until the hyper backup task finishes.   * waits until the hyper backup task finishes.
   * Deactivates the copy LED   * Deactivates the copy LED
Line 204: Line 205:
 The scripts ''/opt/bin/checkTrigger.sh'', ''/opt/bin/startDatenBackup.sh'' and ''/opt/bin/startMediaBackup.sh'' are logging to ''/volume1/Shared/USB_AUTO_BACKUP/hyperBackupTrigger.log'' by redirecting ''stderr'' and ''stdout'' using pipe. The scripts ''/opt/bin/checkTrigger.sh'', ''/opt/bin/startDatenBackup.sh'' and ''/opt/bin/startMediaBackup.sh'' are logging to ''/volume1/Shared/USB_AUTO_BACKUP/hyperBackupTrigger.log'' by redirecting ''stderr'' and ''stdout'' using pipe.
  
-====== Refreneces ======+====== References ======
 [1] [[https://bernd.distler.ws/archives/1835-Synology-automatische-Datensicherung-mit-DSM6.html]] [1] [[https://bernd.distler.ws/archives/1835-Synology-automatische-Datensicherung-mit-DSM6.html]]
publications/synology_trigger_hyper_backup_on_usb_connect.1578509571.txt.gz · Last modified: 2020/01/08 18:52 by Maik Wodarz

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki