rsync and SSH: synchronize a local folder with a remote one
“rsync” is a file transfer program you can use to update files to (and from) a remote computer in an efficient way. It’s usually pre-installed in most Linux distros.
rsync -a -v -e "ssh -i <private-key-file>" <local-folder> <user>@<server-ip>:<remote-folder>
-ameans “archive mode” and is a shortcut for recursive into directories, copy symlinks as symlinks, preserve permissions, preserve modification times, preserve group, preserve owner (using “sudo”), preserve device files (using “sudo”) and preserve special files.
-eallows to specify the remote shell to use, in this case it allows to specify the SSH parameters (private key and port, for example). If you connect to server with a password, you don’t need to add this parameter.
-vshow the process.
- You can exclude files with
rsync -a <local-folder> <user>@<ip>:<remote-folder> --exclude "*.txt"