0

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?

3

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.

| improve this answer | |
1

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

| improve this answer | |

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.