Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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 \ 
malachi@remote-host:~/backups/daily/sites

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

 
discard

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.