Use rsync to realize remote synchronization of data between VPS and backup VPS data

888u

Last update at :2024-03-05,Edit by888u

Whether you are building a website or running code, data is always the most important thing, and backup must be the first priority. Today, Lao Wang will introduce to you a command under Linux: rsync. With the help of rsync, data synchronization between VPS can be very conveniently achieved, thereby achieving the purpose of backing up VPS data.

Introduction to rsync

rsync is an application software under Unix that can synchronize the files and directories of two VPS and make appropriate use of differential encoding to reduce the amount of data transmission. An important feature of rsync that is not common in similar software is that the image of each target only needs to be sent once. rsync can copy/display directory contents, copy files, and optionally compress and recursively copy.

rsync parameters

Commonly used rsync parameters include:

-v: Display detailed synchronization information -a: Archive mode, equivalent to -rlptgoD -r: recursive directory -l: Synchronize soft link files -p: retain permissions -t: Synchronize the "modify time" of the source file to the target machine -g: Keep files belonging to groups -o: Keep the file owner -D: Same as --devices --specials, keep device files and special files -z: Before sending data, compress it first and then transmit it. -H: keep hard links -n: Perform a trial run without making any changes -P same as --partial --progress --partial: Support breakpoint resume download --progress: Display the progress of the transfer --delete: If the source file disappears, the target file will also be deleted --delete-excluded: Specify files to be deleted on the destination --delete-after: By default, rsync cleans the files at the destination before starting data synchronization; if this option is used, rsync will synchronize the data first, and then delete the files that need to be cleaned after all is completed. --exclude=PATTERN: Exclude files matching PATTERN --exclude-from=FILE: If there are many files to be excluded, they can be written in a certain file. -e ssh: Use SSH encrypted tunnel transmission

rsync backup VPS data instance

Of course rsync supports local file synchronization, as follows:

rsync -avH /etc/data/ /tmp/desc/

But what I want to introduce to you today is data synchronization between different VPS. For example, if you have a VPS, you want to back up /etc/data.zip on this VPS to /root/backup on another VPS. directory (user: root, IP: 44.44.44.44), then you only need to execute the following command on the working VPS:

rsync -avP /etc/data.zip root@144.44.44.44:/root/backup

Then enter the SSH password of the backup VPS to complete data synchronization.

If you don’t want to enter the password every time you synchronize, then just configure the SSH key. For specific tutorials, refer to: Linux VPS generates SSH public key and configure SSH public key for password-free login.

Recommended site search: IP address, free cloud computer host permanent use, IP address search, online registration query, Hong Kong free virtual host, cloud virtual host, vps host, US vps host, Hong Kong cn2 server, asp.net space,

Use rsync to realize remote synchronization of data between VPS and backup VPS data

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码