Automatic Remove Disk/Device after Backup is done?

  • hello,


    i'm looking for a solution to automatically remove the sata disk/device when a backup to an external HD is finished.


    background: i set the external backup to auto-backup and as soon as the external HD gets power (via my homeserver running in the EIB homeautomation installation).
    i set the syslog to send all syslogs via udp to my homeserver which decodes the backup complete message and turns off the power 30 seconds after the backup finished.


    i haven't a good feeling when switching the power off without removing the disk via the button in the admin interface to finish all chached files etc.


    so i wish i had an additional checkbox in the "external storage admin page" to say "remove disk after backup is done".


    of course a patch in any script would also be fine. but i have absolutly no idea where to search. it would be great if anybody could point me into the right direction.


    thanks in advance
    tilo

  • Hi tilo,


    you do not really need an Automatic Remove Disk function after the backup is done, because if you plug out the external harddrive the "Linux" fstab / autofs do this job (mount / umount).


    I think you mean the a spindown function for the external drive(s) after the backup is done?
    Normally it's an feature from the external controller from the external HDD Case.
    You can try a manual spindown with hdparm. It's an 50:50 Chance that hdparm works with the external USB Controller.


    1) Login via SSH to your NAS
    2) Then execute:

    Code
    fdisk -l


    3) In the result you see a list with your HDD's. The First HDD's are: sda, sdb, ... Then there is a alphabetical range (example from sdd to sdi) - sdi are in the example the external HDD.
    4) Now execute:

    Code
    hdparm -y /dev/sdi

    (replace sdi by your external HDD)
    if hdparm -y not working try it with:

    Code
    hdparm -S 0 /dev/sdi


    If this spindown your external HDD then we can write an cron script for it otherwise you must change the HDD case for a spindown.


    Greets, David

  • hi david,


    thx for the quick response. i tried what you suggested. hdparm -y is seems to run.


    Code
    [~] # hdparm -y /dev/sdz1
    /dev/sdz1:
     issuing standby command


    but now the question. how do i advise the qnap backup that this command is called automatically after finishing the backup?


    cheers
    tilo

  • Hi tilo,


    you do not need to declare the partition. You can use command without it.
    Example usage:

    Code
    hdparm -y /dev/sdz


    We can not integrate this in the webgui, but we can write our own cron backup script for it.


    Let us call the script:

    Code
    rsync_backup.sh


    (you can rename it) but it's an example. ;)


    In this example script we write a log to see it in the information in the admincp - (WebGUI) from the nas.


    1) First of all let us see where the external disk /dev/sdz is mounted.
    execute:

    Code
    mount


    In the result you have a line with your sdz drive. Now we need the /mnt/... path from it.


    2) Now let us create a folder for our scripts. in this example i use the Public directrory for it. And let us create the rsync_backup.sh and make them executable.

    Code
    mkdir /share/Public/scripts


    Code
    touch /share/Public/scripts/rsync_backup.sh


    Code
    chmod +x /share/Public/scripts/rsync_backup.sh


    3) Edit the script with the vi.

    Code
    vi /share/Public/scripts/rsync_backup.sh


    This is the example script content. You can use it by replacing the line:

    Code
    rsync -avz /share/MD0_DATA/Qmultimedia /mnt/PATHEXTERNALHDD


    Qmultimedia is the share source directory (this you can replace to your share) - and replace the /mnt/PATHEXTERNALHDD with your mountpoint from the mount command (Step 1).


    note: you can specify more than one share. Just copy the rsync line and paste a new under it. ;)
    Note: MD0_DATA == for RAID NAS and HDA_DATA for single drive NAS.


    Bash
    #!/bin/shlog_tool -a "STARTING RSYNC BACKUP JOB" --type 0rsync -avz /share/MD0_DATA/Qmultimedia /mnt/PATHEXTERNALHDDhdparm -y /dev/sdzlog_tool -a "ALL RSYNC BACKUP JOBS DONE" --type 0


    4) That's it. This script make backups from your shares and spindown the external hdd.
    But for example we would like to execute this script daily @ 3 AM.
    Then execute:

    Code
    0 3 * * * /share/Public/scripts/rsync_backup.sh


    Now the script are executed daily @ 3AM and you can check them in the AdminCP (log).


    Greetings, David

  • thx for the detailed description. i will try that later this week (have do do some serious work before:)


    one additional thing. right now my backup is triggered when the external HD is powered on. do you have an idea how to do that? i would like to keep that behaviour since the HD power is driven by my automated home installation (eib). i catch the logs and route them via udp to my homeserver which switches the power off as soon as the backup finished.


    thx alot
    tilo