How to force Samba to create directory
You can use the preexec
or root preexec
options for this. They specify a script that is run upon connection to a share. In case of preexec
the share is run as the connecting user, and as root with root preexec
.
In your share:
[BACKUP]
root preexec = /etc/samba/gendir.sh %u
where /etc/samba/gendir.sh
looks somewhat like this:
#!/bin/bash
DIRECTORY=/storage/BACKUP/$1
if [ ! -d "$DIRECTORY" ]; then
mkdir $DIRECTORY
fi
Depending on your requirements, add chown
and/or chmod
statements to the script.