I want to use rsync to backup some files over ssh which I have managed to get working fine using:

rsync --delete -avze ssh /home/malachi/www/site/ malachi@remote-host:~/backups/daily/sites/site/

How would I create the sites/site/ directory on the remote-host if it does not already exist?

Would it be best to put the below before running the above command?

ssh -l malachi remote-host mkdir -p ~/backups/daily/sites/site/

Or is there a better solution?

2 Answers 2


If it is just one level up, rsync will create the directory. Would your command work if you rsync'd the site folder rather than the contents? That is:

rsync --delete -avze ssh /home/malachi/www/site \ 

This way, rsync should create the sites folder on the remote host as it is just one level up from the site folder that you want to copy. Note that this requires the --recursive switch, which is implicit with -a in your command. See this SO post for details.

There are wonderfully complicated ways of doing this if you need to create multiple levels of parent directories.


I ended up going with the mkdir command and building a script to handle the backup process

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.