How to synchronize two folders in linux

this days I’ve discover a very good command in linux : rsync

rsync -avHP  --numeric-ids --delete null/images/  /var/lib/jetty6/webapps/images/
-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
    --no-OPTION             turn off an implied OPTION (e.g. --no-D)
-v, --verbose               increase verbosity
-H, --hard-links            preserve hard links
-P                          same as --partial --progress

With this option rsync will transfer numeric group and user IDs rather than using user and group names and mapping them at both ends.
By default rsync will use the username and groupname to determine
what ownership to give files. The special uid 0 and the special group 0 are never mapped via user/group names even if the <strong>--numeric-ids</strong> option is not specified.
If a user or group has no name on the source system or it has no match
on the destination system, then the numeric ID from the source system is used instead. See also the comments on the lquse chrootrq setting in the rsyncd.conf manpage for information on how the chroot setting affects rsync's ability to look up the names of the users and groups and what you can do about it.
This tells rsync to delete extraneous files from the receiving side (ones that aren't on the sending side), but only for the directories that are being synchronized. You must have asked rsync to send the whole directory (e.g. lqdirrq or lqdir/rq) without using a wildcard for the directory's contents (e.g. lqdir/*rq) since the wildcard is expanded by the shell and rsync thus gets a request to transfer individual files, not the files' parent directory. Files that are excluded from the transfer are also excluded from being deleted unless you use the <strong>--delete-excluded</strong> option or mark the rules as only matching on the sending side (see the include/exclude modifiers in the FILTER RULES section).
Categorized as Linux

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.