NOTICE¶
this information is copied from [[http://everythinglinux.org/rsync]]
additional info was taken from http://ubuntuforums.org/showthread.php?t=1837771
and some more info from [[https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/]]
Using Rsync Itself¶
Now on to actually using, or initiating an rsync transfer with rsync itself. It's the same binary as the daemon, just without the "--daemon" flag. It's simplicity is a virtue. I'll start with a commandline that I use in a script to synchronize a Web tree below.
rsync --verbose --progress --stats --compress --rsh=/usr/local/bin/ssh \
--recursive --times --perms --links --delete \
--exclude "*bak" --exclude "*~" --dry-run --max-size='200k' \
/www/* webserver:simple_path_name
Let's go through it one line at a time. The first line calls rsync itself and specifies the options "verbose," progress" and "stats" so that you can see what's going on this first time around. The "compress" and "rsh" options specify that you want your stream compressed and to send it through ssh (remember from above?) for security's sake.
The next line specifies how rsync itself operates on your files. You're telling rsync here to go through your source pathname recursively with "recursive" and to preserve the file timestamps and permissions with "times" and "perms." Copy symbolic links with "links" and delete things from the remote rsync server that are also deleted locally with "delete."
Now we have a line where there's quite a bit of power and flexibility. You can specify GNU tar-like include and exclude patterns here. In this example, I'm telling rsync to ignore some backup files that are common in this Web tree ("*.bak" and "*~" files). You can put whatever you want to match here, suited to your specific needs. You can leave this line out and rsync will copy all your files as they are locally to the remote machine. Depends on what you want.
Finally, the line that specifies the source pathname, the remote rsync machine and rsync "path." The first part "/www/*" specifies where on my local filesytem I want rsync to grab the files from for transmission to the remote rsync server. The next word, "webserver" should be the DNS name or IP address of your rsync server. It can be "w.x.y.z" or "rsync.mydomain.com" or even just "webserver" if you have a nickname defined in your /etc/hosts file, as I do here. The single colon specifies that you want the whole mess sent through your ssh tunnel, as opposed to the regular rsh tunnel. This is an important point to pay attention to! If you use two colons, then despite the specification of ssh on the commandline previously, you'll still go through rsh. Ooops. The last "www" in that line is the rsync "path" that you set up on the server as in the sample above.
Yes, that's it! If you run the above command on your local rsync client, then you will transfer the entire "/www/*" tree to the remote "webserver" machine except backup files, preserving file timestamps and permissions -- compressed and secure -- with visual feedback on what's happening.
Note that in the above example, I used GNU style long options so that you can see what the commandline is all about. You can also use abbreviations, single letters -- to do the same thing. Try running rsync with the "--help" option alone and you can see what syntax and options are available.
Usage of rsync¶
copy all files of current directory toroot@example.com:/root
, use
partial
to continue transfer when it was stalled or brokenbwlimit=100
to set used bandwidth to 100kb/srsync --verbose --progress --times --stats --partial --bwlimit=100 --rsh=/usr/bin/ssh ./* root@example.com:/root
size-only
to ignore timestamps (useful when dealing with windows-shares)recursive
to copy all files in subdirectories as wellrsync --verbose --progress --stats --times --partial --bwlimit=1000 --size-only --recursive /mnt/windows_server/share/ ./
delete
to delete those files on the target not existing on the source (pay some attention here, as you might delete all files in an automated rsync-run)rsync --verbose --progress --recursive --times --size-only --delete --stats --partial /home/VM.bak/ /mnt/sshfs/VM.bak
copy all files younger than 3 days
cd /home/VM.bak
find . -mtime -3 -type f -print0 | rsync -0v --files-from=- /home/VM.bak ~/destination
find:
-mtime -3 will match files 3 days old, and younger.
-type f will find only files.
-print0 will print results with a null at the end, safer in case of strange characters in the filenames.
rsync:-0
uses null as a separation.-v
verbose, to see what's going on.--files-from=-
receive file list from the standard input.
Von Jeremias Keihsler vor fast 6 Jahren aktualisiert · 1 Revisionen