To use rsync to synchronize a local directory with a remote directory, you can use the following command:

rsync -avz -e ssh /local/directory user@remote:/remote/directory

This command uses rsync to copy files from the local directory /local/directory to the remote directory /remote/directory using the ssh protocol. The -a option tells rsync to preserve file permissions, ownership, and timestamps, while the -v option provides verbose output and the -z option tells rsync to compress the data during transfer. The -e ssh option tells rsync to use the ssh protocol for the transfer.

You can also use rsync to sync a remote directory with a local directory. The command for this would be:

rsync -avz -e ssh user@remote:/remote/directory /local/directory

You can also sync the directories in a bi-directional way using the --delete flag which will delete files in the destination directory if they are deleted in the source directory.

rsync -avz --delete -e ssh user@remote:/remote/directory /local/directory

This command would delete the files in the local directory if they are deleted in the remote directory.

 

Here's an example of using rsync to synchronize the local directory /home/user/documents with a remote directory /home/user/backup on a server with the IP address 192.168.1.100:

rsync -avz -e ssh /home/user/documents user@192.168.1.100:/home/user/backup

This command will copy all files and subdirectories from the local directory /home/user/documents to the remote directory /home/user/backup on the server with IP address 192.168.1.100. The -a option preserves file permissions, ownership, and timestamps, the -v option provides verbose output, and the -z option compresses the data during transfer.

You can also use this command to sync the remote directory with a local directory:

rsync -avz -e ssh user@192.168.1.100:/home/user/backup /home/user/documents

This command will copy all files and subdirectories from the remote directory /home/user/backup on the server with IP address 192.168.1.100 to the local directory /home/user/documents.

You can also use the --delete flag to delete files in the destination directory if they are deleted in the source directory

rsync -avz --delete -e ssh user@192.168.1.100:/home/user/backup /home/user/documents

This command will copy all files and subdirectories from the remote directory /home/user/backup on the server with IP address 192.168.1.100 to the local directory /home/user/documents and also delete the files in the local directory if they are deleted in the remote directory

 

Previous Post Next Post