Did you know about Rsync? It is an algorithm-based synchronization tool that has the ability to minimize the amount of data copied. This tool works with the principle of moving parts of the changed files. For information, this tool can synchronize locally and also remotely.
But how can you configure this tool from local directory to remote directory on VPS? This article will answer it!
To be honest you are free to use any version of modern Linux but in this article we use Ubuntu 12.04 as the base. Although the synchronization process by Rsync is not limited to its utility, in this post, we only focus on the utility side. In fact, Rsync is already in some versions of Linux, allowing every user to configure.
Before configuring you must understand how the basic syntax of Rsync works
This works with patterns familiar to cp, scp and ssh. First, create two folders in which some test files are loaded. Here are the commands:
cd /root mkdir directory1 mkdir director2 touch dir1/filex {1.100}
After typing the above commands correctly then you will have ‘dir 1‘, a new directory in which there are up to 100 blank files. Not only ‘dir 1‘, you can also have another empty directory of ‘dir2’. Once you have these two directories, it is now time for you to sync between the content inside dir 1 with the content inside dir 2. Type the following commands:
rsync -r directory1/ directory2
The option ‘-r‘, this is a recursive option and you need it to sync on both directories.
Not only ‘-r‘, you also have the ‘-a‘ option.
rsync -a dir1/ dir2
The ‘-a‘ option, this is a combination option.
The ‘-a’ is an ‘archive’ as a result of repeated synchronization. This symbol is a symbol containing many symbolic links, special files involved, device, time when you modify, group, owner and also permission
We advise you to use the ‘-a’ option. But if you see ‘trailing slash (/)’ then it means ‘fill dir 1’. If you do not see the slash then dir 1 will be placed inside dir 2 and generate the following hierarchy:
~/dir2/dir1/[file]
A slash mark should be considered before starting the Rsync command. You will also be given the ‘-n‘ or ‘-dry-run‘ option and possibly ‘-v’ where ‘-v‘ will produce the following:
rsync -anv directory1/ directory2
This is an example when you use a slash sign:
send a list of incremental files
./ files1 files2 files10 ....
If you do not use that sign:
rsync -anv directory1 directory2
send a list of incremental files
directory1 / directory1 / files1 directory1 / files2 directory1 / files10 . . . .
Steps of synchronization
If you have SSH access to a remote machine (Rsync is installed on both sides), then you can synchronize easily and quickly. You can sync from dir 1 to remote computer with the following syntax:
rsync -a ~/directory1 usernamehere@remote_host:destination-dir-here
Above is what is known as ‘push operation’ because it locates the local system directory to the remote system. If there is a ‘push’ then there is a ‘pull’. Pull operation is done by placing the remote system directory into the local system. Use the syntax as below:
rsync -a username-here@remote_host: /home/username/directory1 path-on-local-pc-sinc
Some warnings:
– Transferring “raw files” (uncompressed) may aggravate the transfer process itself. You are advised to use the ‘-z’ flag in order to reduce network transfer.
For example: rsync -az source destination
– To resume the distorted transfer, use the ‘-p’ flag.
For example: destination source rsync -azP
– You can modify some files without repeating the configuration of the files as a whole.
– To prevent data loss during the modification process, use the ‘delete-run’ option.
– To get rid of unwanted files or directories, you can use the ‘-exclude =’ option.
By configuring Rsync in VPS properly, you can use Rsync which will allow you to perform complex backup operations related to the robustness of the local directory.
Best example commands to sync from Local Directory to Remote Server
rsync -avze "ssh -p 22" /home/local/pathhere root@remote-ip:/remote-path-where-file-will-sent