Eject USB Disk After Backup

If your question pertains to using an external HDDs or even the USB Copy feature, post it here.
Forum rules
1) This is a user forum for Synology users to share experience/help out each other: if you need direct assistance from the Synology technical support team, please use the following form:

https://account.synology.com/support/su ... p?lang=enu



2) To avoid putting users' DiskStation at risk, please don't paste links to any patches provided by our Support team as we will systematically remove them. Our Support team will provide the correct patch for your DiskStation model.
ta_jb
I'm New!
I'm New!
Posts: 1
Joined: Tue Jul 09, 2013 9:30 am

Re: Eject USB Disk After Backup

Unread post by ta_jb » Tue Jul 09, 2013 9:59 am

AlanF wrote:Hi we are a Backup Company with hundreds of Synology NAS units, we use the USB share for off site copies. We rotate these weekly. [....]

Remember to set R/W access (permissions) to the USB share or you will definitely have problems with local backups failing (big files)or when using more than one USB HDD. The Local backup HDD grows dramatically in size if you used DR3 Restore Points as the Symbolic links can't be supported on a different volume.
Hi Alan,

can you please clarify the settings you made to get this backups work?
We've exactly this problem with large files on multiple systems. In one case the first USB Disk works, the other doesn't.
Last year we contacted the Syno Support to fix this issue on some of our DiskStations, but they did not tell us how to fix it by ourselves.

Regards,
Jens

ste8604
Experienced
Experienced
Posts: 112
Joined: Mon Mar 18, 2013 2:04 pm

Re: Eject USB Disk After Backup

Unread post by ste8604 » Wed Apr 23, 2014 9:53 pm

with DSM 5 is possibile create a script to eject usb? tks
DS216+II - DSM 6.1

Schmill
Novice
Novice
Posts: 44
Joined: Wed Nov 27, 2013 11:19 pm

Re: Eject USB Disk After Backup

Unread post by Schmill » Fri Apr 25, 2014 5:41 pm

I had been using the following script:

sync; /usr/syno/bin/synousbdisk -umount sdu1; >/tmp/usbtab

However in DSM 5 I get the following log entries:

Information - SYSTEM: External disk [USB Disk -1] is ejected.
Warning - SYSTEM: The external device [USB Disk ] was not ejected properly. You should eject the device before unplugging it or turning it off.

I not sure why this is, it used to work fine prior to DSM 5
DSM 5.2 build 5592 update 4

ste8604
Experienced
Experienced
Posts: 112
Joined: Mon Mar 18, 2013 2:04 pm

Re: Eject USB Disk After Backup

Unread post by ste8604 » Tue May 06, 2014 8:19 pm

this is the response from online support:
Unfortunately, if you need to eject the disk at specified time, it is not supported at the moment. Writing scripts for unsupported operation is not covered by our support service as well. We apologize for your inconvenience.


:( uff!
DS216+II - DSM 6.1

Schmill
Novice
Novice
Posts: 44
Joined: Wed Nov 27, 2013 11:19 pm

Re: Eject USB Disk After Backup

Unread post by Schmill » Tue May 06, 2014 10:51 pm

:(

Thanks for the update though :)
DSM 5.2 build 5592 update 4

gokky
Sharp
Sharp
Posts: 181
Joined: Fri Sep 13, 2013 9:34 pm

Re: Eject USB Disk After Backup

Unread post by gokky » Fri Dec 19, 2014 5:20 pm

Schmill wrote:I had been using the following script:

sync; /usr/syno/bin/synousbdisk -umount sdu1; >/tmp/usbtab

However in DSM 5 I get the following log entries:

Information - SYSTEM: External disk [USB Disk -1] is ejected.
Warning - SYSTEM: The external device [USB Disk ] was not ejected properly. You should eject the device before unplugging it or turning it off.

I not sure why this is, it used to work fine prior to DSM 5
I use

Code: Select all

sync; /usr/syno/bin/synousbdisk -umount sdu1; >/tmp/usbtab
umount /volumeUSB1/usbshare
and so far I didn't get the message above. If I just switch-off the USB drive, then a warning is being written into log and the sharename is being reset back to usbshare1(*).

Te command unmount may return an error, if share is being in use, either via CIFS or File station or (potentially) other issues.

Code: Select all

server> umount /volumeUSB1/usbshare
umount: can't umount /volumeUSB1/usbshare: Device or resource busy
As I'm writing the device name (sdu1) and mountpoint name (/volumeUSB1/usbshare) are hardcoded. There is certainly the next task to define, how these names are interconnected on shell level.

Within /tmp/usbtab there is sds="/proc/bus/usb/005/009" line and within the volumes, the same is noted as /volumeUSB1/usbshare. Additionally, in my instalation, the share is named as e.g. "usbstation" instead of classic "usbshare1".

Do any of you have a clue, how to interconnect the information on different levels mentioned above?

lpG

(*) Permisions remains, but sharename is unintentionally changed. I set sharename under the Control panel / Shares.

gokky
Sharp
Sharp
Posts: 181
Joined: Fri Sep 13, 2013 9:34 pm

Re: Eject USB Disk After Backup

Unread post by gokky » Sun Dec 21, 2014 7:17 pm

Schmill wrote:...
sync; /usr/syno/bin/synousbdisk -umount sdu1; >/tmp/usbtab
...
Due to varuious checks to be done I've put some of them into a shell script in order to assure some checks I've noticed to be checked. Put the following code within a script, use chmod to allow its execution.

Code: Select all

#!/bin/sh
#
# Ejecting USB disk on Synology - (CC) 2014 Gokky
# Tested on: DSM 5.1 (single USB disk only)
#
# Usage: command mountpoint short_device
# Example: ./doeject.sh /volumeUSB1/usbshare sdu1
#

# Make commands flexible through the script and
# not connected to the path
sync=/bin/sync
mount=/bin/mount
umount="/bin/umount "
synousbdisk=/usr/syno/bin/synousbdisk
sleep=/bin/sleep
grep=/bin/grep

# Make default values available
usbtab=/tmp/usbtab
sync_sleep=1500

# Check whether required number of parameters is available
if [ $# -ne 2 ]; then
        echo "Usage: $0 mountpoint device"
        exit 1
fi

# Check whether parameters corresponds to what we expected
# Check whether $2 corresponds to a block device
if [[ ! -b "/dev/$2" ]]; then
        echo "Parameter 2 inccorect: Not a block device /dev/$2"
        exit 4
fi

# Check whether $1 corresponds to a mountpoint and this mountpoint to
# short_device
res=`${mount} | ${grep} "$2 " | ${grep} "$1 "`
if [ "$?" != "0" ]; then
        echo "Parameter 1 incorrect or not aligned: $1"
        exit 5
fi

# echo "Checks finished"

# First we try with unmount as this is a potential failing point
msg=`${umount} $1 2>&1`
if [ "$?" = "0" ]; then
        # when umount has been successful
        # - sync data buffered within memory to disk
        ${sync}
        # - some man pages suggest some time to stabilize
        # ${sleep} ${sync_sleep}
        # - unmount disk via synousbdisk
        ${synousbdisk} -umount $2
        if [ "$?" = "0" ]; then
                # WARNING: I am not sure whether this is the right way
                #  when more USB devices are connected
                >${usbtab}
        else
                echo "synousbdisk not sucessful"
                exit 3
        fi
else
        echo "umount not sucessful | ${msg}"
        exit 2
fi
Warning: Script needs to be run twice/more times if the USB disk has more partitions. For example:

Code: Select all

xxstorage> ./doeject.sh /volumeUSB1/usbshare1-1 sdq1
Unmount USB device sdq1 succeeded.
xxstorage> ./doeject.sh /volumeUSB1/usbshare1-2 sdq2
Unmount USB device sdq2 succeeded.

Post Reply

Return to “External Harddrives & USB Flash Drives”