In case of not being able to connect via SSH to external storage device, things can be done
with sftp. SFTP is not able to recursively create remote directories (e.g. „/user/backup/data“).
The following script will do that for you:
TR=/usr/bin/tr
SFTP=/usr/bin/sftp
NAME=user.name
rmkdir ()
{
REMOTEPATH=$1
DIRS=$2
for d in $(echo $DIRS | $TR "/" "n")
do
rmkdirHelper ${REMOTEPATH}/${d}
REMOTEPATH="${REMOTEPATH}/${d}"
done
}
rmkdirHelper ()
{
$SFTP ${NAME}@${HOST} <<-EOT
mkdir $1
EOT
}
Now you can call the function from your backup script like this:
rmkdir $LPATH $i
Where $LPATH is the remote basepath and $i is the (recursive) directory that should
be created on remote host. (SSH Public Key recommended)