Sync files with rsync on ssh Linux / FreeBSD

To copy files over a network using a lot of tools. The most common of them – ftp, and many use scp. To synchronize data using rsync.

If you have access via ssh to the server, this is the simplest way to implement synchronization.

Rsync for ssh – this is a special case of the use of the general form of the command is as follows:
rsync [options] [user @] SERVER: sources … [Recipient]
Pull (copying files from a remote system to the local)

Push (copy the files from the local machine to the remote)

Mandatory parameter is the “source”, there may be several.

The main keys:
-a, archiving mode, includes keys -rlptgoD;
-r, directories are copied recursively;
-l, copy symbolic links “as is”, that is, rsync will not follow them, referring to the files;
-p, preserve file permissions;
-t, preserve modification time of files;
-g, -o, saving the owner and group of the file;
-D, File saving devices and special files;
-u, update mode, skipped files at the destination, with a later modification date than at the source;
-v, displays the names of files to be copied;
-q, does not display error messages;
-z, including compression mode;
-P, Display progress while copying;
-c file check checksum, and size and date modified. The additional load on the processor, greatly increases the time synchronization;
–ignore-errors, continue to back up and remove even after the error;
–max-delete, the maximum number to be deleted at a time of files and directories;
–files-from = FILE, given a list of files and directories to copy in the file;
-e ssh, use the copy ssh;
–bwlimit = KBPS, the speed limit copying.

# Rsync -zavP / backup / file1 / / backup / file2 / user@ / backup
Copied to the server contents of folders / backup / file1 / / backup / file2 / folder in the backup

# Rsync -zavP / backup / file1 / / backup / file2 / user@ / backup
In this example, already copied folders themselves

How to limit the speed of file transfer? You need to put option –bwlimit:
# Rsync -zavP –bwlimit = 100 / backup / file1 / user@ / backup

How to synchronize files with check checksum?
# Rsync -szavP / backup / file1 / user@ / backup

How to copy files from a remote machine to a local?
# Rsync -zavP user@ / backup / backup / file1 /

How to delete a file or directory when copying?
# Rsync -azVP –exclude / temp / / home / data / user@ / backup
Exclude the directory / temp

How to use a non-standard ssh port when copying rsync?
# Rsync -zavP ‘-e ssh -p 12345’ / var / lib / root@ / backup