How to Use rsync in Linux
For various organizations and companies, data is the most important to them. Even for e-commerce, data is equally important. Rsync is a tool/software that backs up important data through the network. It is also a network protocol for synchronizing folders and files between systems through the network on Unix-like and Window systems. Rsync can copy or display directories and copy files. Rsync listens to TCP port 873 by default and Copies files through remote shell such as rsh and ssh. Rsync must be installed on both the remote and local systems.
The main advantages of rsync are:
Speed: All content will be copied locally and remotely. Next time, only the changed block or byte will be transmitted.
Secure: data can be encrypted over ssh.
Low bandwidth: rsync can compress and decompress data blocks at both ends.
Syntax:
- # Rsysnc [options] source path destination path
Example: 1-enable Compression
- [Root @ localhost/] # rsync-zvr/home/aloft // backuphomedir
- Building file list... done
- . Bash_logout
- . Bash_profile
- . Bashrc
- Sent 472 bytes encoded ed 86 bytes 1116.00 bytes/sec
- Total size is324 speedup is0.58
The preceding rsync command uses-z to enable compression.-v is visualized and-r is recursive. The above is synchronized between the local/home/aloft/AND/backuphomedir.
Example: 2-Preserve the attributes of files and folders
- [Root @ localhost/] # rsync-azvr/home/aloft // backuphomedir
- Building file list... done
- ./
- . Bash_logout
- . Bash_profile
- . Bashrc
-
- Sent 514 bytes encoded ed 92 bytes 1212.00 bytes/sec
- Total size is324 speedup is0.53
We used the-a option above, which retains the owner and group, timestamp, soft link, and permission and runs in recursive mode.
Example: 3-synchronize local data to a remote host
- Root @ localhost/] # rsync-avz/home/aloft/azmath@192.168.1.4: 192.168.1.4:/share/rsysnctest/
- Password:
-
- Building file list... done
- ./
- . Bash_logout
- . Bash_profile
- . Bashrc
- Sent 514 bytes encoded ed 92 bytes 1212.00 bytes/sec
- Total size is324 speedup is0.53
The preceding command allows you to synchronize data between local and remote machines. As you can see, you are prompted to enter the password when Synchronizing files to another system. During remote synchronization, you must specify the user name and IP address or Host Name of the remote system.
Example: 4-remote synchronization to local
- [Root @ localhost/] # rsync-avz azmath@192.168.1.4: 192.168.1.4:/share/rsysnctest // home/aloft/
- Password:
- Building file list... done
- ./
- . Bash_logout
- . Bash_profile
- . Bashrc
- Sent 514 bytes encoded ed 92 bytes 1212.00 bytes/sec
- Total size is324 speedup is0.53
The preceding command synchronizes remote files to the local device.
Example: 5-find out the differences between files
- [Root @ localhost backuphomedir] # rsync-avzi/backuphomedir/home/aloft/
- Building file list... done
- Cd ++ backuphomedir/
- > F ++ backuphomedir/. bash_logout
- > F ++ backuphomedir/. bash_profile
- > F ++ backuphomedir/. bashrc
- > F ++ backuphomedir/abc
- > F ++ backuphomedir/xyz
-
- Sent 650 bytes encoded ed 136 bytes 1572.00 bytes/sec
- Total size is324 speedup is0.41
The above command helps you find out the differences between the source address and the target address in the file or directory.
Example: 6-Backup
The rsync command can be used to back up linux.
You can use rsync in cron to schedule backups.
- 00 ***/usr/local/sbin/bkpscript &>/dev/null
- Vi/usr/local/sbin/bkpscript
-
- Rsync-avz-e 'ssh-p2093 '/home/test/root@192.168.1.150:/Oracle/data/
Rsync + inotify implement real-time synchronization and backup of Git data
Rsync for file backup Synchronization
Rsync synchronizes two servers
Remote synchronization of Rsync in CentOS 6.5
Use Rsync in Ubuntu Linux for data backup and Synchronization
Linux uses the Rsync client to synchronize directories with the server for backup
Rsync details: click here
Rsync: click here
This article permanently updates the link address: