Friday, July 11, 2014

Copy and sync files with rsync remotely

Copying files using rsync from remote server to local machine

Using rsync is as simple as remembering 2 or 3 parameters.

rsync -a [SOURCE] [DESTINATION]

-a uses archive mode so the file permissions and parameters are kept. It is not required.
I usually use verbose and compression, so it looks like this:
rsync -avz [SOURCE] [DESTINATION]

for remote connections, [SOURCE] and [DESTINATION] can both be in the form:
user@host:/path/

If you want to include hidden files, try:
rsync -a ~/.[^.]* /path/to/backup

Here is part of the synopsis from the rsync man page:
       Local:  rsync [OPTION...] SRC... [DEST]

       Access via remote shell:
         Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

       Usages with just one SRC arg and no DEST arg will list the source files
       instead of copying.

You can schedule it to run in 15 minute intervals by typing "crontab -e" and adding the following line to the end:
*/15 * * * * rsync [SRC] [DEST] 1>/dev/null 2>/dev/null

No comments:

Post a Comment