How to synchronize files from remote server?

bash ssh rsync

The command to synchronize files between directories or servers is rsync. This allows to transfer only necessary files, ie. those which need updating.

Example of transferring files from remote host:

rsync -chavzP --stats user@example.com:/path/to/my-folder /storage
Important to note:
  • This command will create my-folder in /storage folder and transfer all files which it contains.
  • This will preserve permissions
  • Symlinks will be preserved as they are, ie. this command does not follow symlinks
  • Files will be compared by checksum - because of the -c option
  • Connection will be made via ssh so proper keys need to be set up. If ssh server is configured to use passwords, the password prompt will be displayed.
  • The colon after host domain indicates that connection will be made via ssh.

The --stats option will show summary after transfer, similar to following example:

Number of files: 54,694 (reg: 32,595, dir: 22,099)
Number of created files: 54,694 (reg: 32,595, dir: 22,099)
Number of deleted files: 0
Number of regular files transferred: 32,595
Total file size: 373.55M bytes
Total transferred file size: 373.55M bytes
Literal data: 373.55M bytes
Matched data: 0 bytes
File list size: 2.17M
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 716.30K
Total bytes received: 290.23M

sent 716.30K bytes  received 290.23M bytes  1.08M bytes/sec
total size is 373.55M  speedup is 1.28