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 am looking for a rsync script that will backup specific directories from my home machine to a remote server nightly. So say: /home/me/Pictures to ssh -p 6587 It would be nice if it can look for changes but im not worried so much about the changes aspect is having a script that runs at a certain time of night with cron or however. I have googled and found scripts but those scripts were specific to the operations of those creators. Any help would be happily accepted as the scripted part really throws me off. Thank you, Janice

share|improve this question

It's really simple to create basic scripts. You use a text-editor (gedit, nano, or the more powerful and complex emacs, vim, ...) to edit a file. You put in the commands which you'd run at the command-line. You give it a "magic" first line, so the system knows which command to use to follow the instructions in the script. And then you deal with the legacies of history and after saving/exiting, you mark the file "executable", so you can run it.

The basic magic first line is #!/bin/sh -- the #! is the bit which says "the rest of the line is the command to run to use this file correctly" and the /bin/sh is the shell. You could also use /bin/bash, or various other things.

So create a file do_backups:

rsync -a -e "ssh -p 6587" /home/me/Pictures/

and then chmod +x do_backups.

The -a says "do everything under this directory"; the -e changes the command used to connect, so that you can add the port; the trailing / on /home/me/Pictures/ is important to rsync -- one of its quirks.

It really is as simple as taking the command you'd run at the prompt and putting it into a file, with a special first line. It's designed to be the same commands, the same syntax, and so on.

rsync will look for changes on its own -- that's part of its job.

Do you also need pointers to the cron part?

share|improve this answer
Thank you Phil for responding, I have the cron part with no problem But lets say that I want to backup multiple directories in one run. Now the above will backup my pictures to the pictures directory leaving that directory intact but if I do multiple /home/me/Pictures/ /home/me/Documents /home/me/recipes It creates a home folder with all the sub-directories under it on the remote server. I just want it to copy the content of the multiple directories to the remote server directories i.e. Pictures recipes etc without creating the home/me/documents/etc Thanks Janice – Janice Young Jan 19 '11 at 18:26
Put multiple rsync commands into one script. – Phil P Jan 19 '11 at 22:19
If you're trying to avoid typing a password multiple times, then you can make the SSH more secure than using passwords, by using SSH Public Key authentication. You can make that easier, to the point where it doesn't require a password at all, but to make that safe you need to do some fiddling to restrict what can be done with a given key and that gets ... not complex, but involved and requires a bit more understanding. The above should work for the time being. – Phil P Jan 19 '11 at 22:21

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.