1

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 [email protected]/Pictures. 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

1 Answer 1

1

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:

#!/bin/sh
rsync -a -e "ssh -p 6587" /home/me/Pictures/ [email protected]:/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?

3
  • 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 @remoteserver.com:/ 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 Jan 19, 2011 at 18:26
  • 1
    Put multiple rsync commands into one script.
    – Phil P
    Jan 19, 2011 at 22:19
  • 1
    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, 2011 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .