Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
up vote 1 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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