rsync command in Linux- www.techiev.com rsync : Rsync, which stands for " remote sync ", is a remote and local fi...
![]() |
rsync command in Linux- www.techiev.com |
rsync:
Rsync, which stands for "remote sync", is a remote and local file synchronization tool
rsync used a "quick check algorithm" to transfer the files.
It is used to copying and synchronizing the files and directories locally as well as two different servers.
It is fast and secure and flexible.
In realtime mostly used for servers file Backups.
It is the replacement of rcp command.
It will support the links, groups, file permissions as well.
In the rsync command, there were several options available.
1. -r option: Sync the content dir1 to dir2 in the same system
Syntax: rsync -r dir1/ dir2
Where -r option is recursive
2. -a option: It stands for "archive" and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions.
Syntax: rsync -a dir1/ dir2
Where " -a " is a combination flag.
3.Trailing slash ( / ): Using a trailing slash it will sync the file inside the directory when not using directory itself is transferred
4. -n or --dry-run: Double-check the argument before executing the rsync command.
Syntax: rsync -anv dir1/ dir2
Example: With trailing slash(/)
rsync -anv man1/ man
Without trailing slash(/)
rsync -anv man1 man
5. -z option: If you are transferring files that have not already been compressed, like text files, you can reduce the network transfer by adding compression with the -z option
6. -p option: The -P flag is very helpful. It combines the flags --progress and --partial
Syntax: rsync -azP source destination
7. --delete option: Before using delete option use -dry-run option and do testing to prevent data loss
Syntax: rsync -a --delete source destination
8.--exclude= option: exclude certain files or directories located inside a directory you are syncing, you can do so by specifying them in a comma-separated list following the --exclude= option
Syntax: rsync -a --exclude=pattern_to_exclude source destination
9. --include= option: we have specified a pattern to exclude, we can override that exclusion for files that match a different pattern by using the --include= option
Syntax: rsync -a --exclude=pattern_to_exclude --include=pattern_to_include source destination
10.--backup option: rsync’s --backup option can be used to store backups of important files. It is used in conjunction with the --backup-dir option, which specifies the directory where the backup files should be stored.
Syntax: Syntax: rsync -a --delete --backup --backup-dir=/path/to/backups /path/to/source destination
Rsync to sync with a remote system:
1.SSH access to the remote machine and rsync installed on both sides
2.Must set up SSH keys
1.Push operation:
Pushes the directory or folder or file from local machine to the remote machine
2.pull operation:
sync a remote directory to the local system.
Syntax : push operation:
rsync -a ~/dir1 username@remote_host:destination_directory
Syntax: pull operation:
rsync -a username@remote_host:/home/username/dir1 place_to_sync_on_local_machine
COMMENTS