rsync (Remote Synchronization) is a cross-platform console application for data synchronization with minimal traffic consumption.

    installation for CentOS:

    yum -y install rsync  
    

    For Debian/Ubuntu:

    sudo aptitude install rsync  
    

    Here is an example of local synchronization:

    sudo rsync -avh --delete /var/www/ /root/backup/www/  
    

    Synchronization of data to a remote server:

    sudo rsync -avh --delete /var/www/ root@192.168.1.50:/root/backup/www/  
    

    Synchronization of data to local from remote server:

    sudo rsync -avh root@192.168.1.50:/var/www/ /root/backup/www/  
    

    Via SSH with a non-standard port:

    sudo rsync -avh -e "ssh -p 1111" root@192.168.1.50:/var/www/ /root/backup/www/  
    

    To exclude some subdirectories, for example if we sync /var/www/ and want to exclude /var/www/dir/ and /var/www/dir/tmp/, we can add to the command:

    --exclude='dir/' --exclude='dir/tmp/'
    

    To move files from the remote server to the local one:

    sudo rsync -avh --remove-source-files root@192.168.1.50:/var/www/ /var/www/  
    

    Example of copying mysql data to another disk:

    rsync -vrplogDtH -progress /var/lib/mysql/ /newhdd/var/lib/mysql/  
    

    The built-in help can be obtained by the command:

    man rsync  
    

    In /etc/default/rsync you can configure rsync to run as a daemon.

    When synchronizing with other servers, rsync must also be installed on them or SSH must be specified.

    Startup parameters

    • -v (-verbose, detailed mode)
    • -r (-recursive, to copy data recursively)
    • -R (-relative, use relative paths when creating symbolic links)
    • -a (-archive, archive mode, copy data recursively, preserving symlinks, permissions and other information)
    • -b (-backup, backup mode, see also -backup-dir=DIR and -suffix=SUFFIX)
    • -c (-checksum, checksum instead of time and size)
      -delete (remove files)
    • -f (-filter=RULE, create filtering rule)
    • -h (-human-readable, output data in human-readable format, see also -progress)
    • -h (-hard-links, store hard-links)
    • -n (-dry-run, trial mode without any changes)
    • -p (-perms, save rights)
    • -z (-compress, compress data during transfer, see also -compress-level=NUM and -skip-compress=LIST)
    • -x (-one-file-system, do not go beyond current mount point)
    • -q (-quiet, short mode)
    • -W (-whole-file, full copy instead of copying changed data)