Disable/Enable Samba Share with cronjob

  • Hello everbody,


    I'm using openmediavault as a storage system for backups. I created multiple samba shares for the backups. Every computer has a own share. I want do disable/enable the shares at specific times with a cronjob. I'm able to disable/enable it manually with the control panel but don't found a solution to enable/disable it with a command. Is there anny command or plugin for this?


    Best regards
    NorthernRoot

    • Offizieller Beitrag

    One simple possibility could be to use cron to run a script that change the access rights for the shared folder. Using chmod and/or chown.


    However I think it would be better to share the rights of a subfolder one level down. So that the share is still fully functional, but it will look empty or be inaccessible. That way OMV will function as normal without errors.


    I haven't tested it, but perhaps something like this:


    /sharedfolders/backup_computer_a/storage_a/
    /sharedfolders/backup_computer_b/storage_b/


    The actual shares are backup_computer_a and backup_computer_b.


    To make the contents of the shares appear or disappear, change the access rights to storage_a or storage_b using chmod in a script. You will have to experiment to see if you also need to change ownership using chown. Possibly using the recursive switch?


    It is possible that shares are "cached" so that the changes don't appear at once. Then there may be errors until the share is refreshed. I'm not sure. You'll have to test it. One extreme option could be to reboot the OMV server. Especially if it is run as a VM.

  • Hello @Adoby and @subzero79,


    thank you both for the great ideas and the help. I found a solution and want to present it for everbody if they want to do it as well:


    ./smbtimer enable #Enables the share BackupTEST
    ./smbtimer disable #Disable the share BackupTEST


    The entries inside the crontab is self explaining.
    I used this post as a reference: Samba 'access based share enum' workaround for workgroups (Hide shares that users don't have access to)


    A small Note to the command 'service smbd restart': Windows reacts a bit wired when I disable the shared Folder. I'm still able to connect to it and use it but the share is not inside the /etc/samba/smb.conf. To make 100% shure the share is not available to the System anymore I restart the samba service. I was worried that current connections cut off during the restart of the service but it seems that they survive it. There is also a Killall command to tell Samba to reload the smb.conf file again but windows still was able to access the shared folder.

  • Last information! I tested the code again. I done a backup of a PC and turned off a different share with the shell script. The backup stopped because it couldn't read the backup file. A restart of the smbd service could cause trouble with reading/writing on a different share.

  • Newest Openmediavault Version needs some Update to the code:



    omv-mkconf samba does not longer exists. Now we have to use

    Code
    omv-salt deploy run samba

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!