Rsync Command is one of many linux basic command must be mastered by sysadmins. If you as sysadmin doesn’t know basic command to use rsync it’s very disappointment. So as a sysadmin we must know at least the basic command of rsync even just for copy file from local computer to a server or copy file from remote server to local computer.
Tips: Text Manipulation Tools
In this article we will trying to learn how to use rsync in linux. I’m not an expert on this things, honestly this is my first article writing in english by the way. Okay let’s start.
What Rsync Is?
Rsync is a utility we can use to transfer or synchronize file, mostly its used by linux user to get or push file to the remote server. You can read more about rsync from wikipedia here.
Why Use Rsync?
Because Rsync is really fast for transfer files. For some reason i think rsync can be made to be a secure connection with ssh.
Is It Only Linux That Can Use Rsync?
For the first time i used rsync the answer is yes, rsync is only work in linux terminal. But few days ago i have try for windows 10. If you want try to use rsync in windows computer, you can read more in here.
Because i’m still beginner to in this topic, i’m just will show you about Rsync Command that i have been used. I know that Rsync have many command we can use, but like i said, i was beginner. If you want to know more about it, you can click here.
Let’s Get Started
Pull Data With Rsync Command From Remote Server
Now first command is to pull or get data from remote server. I assume you know the detail about remote server like ssh username, ip address, ssh port, and the password. So lets see the command below, and later i will try to explain.
rsync -azh --progress user@ipserver:/path/to/directory/file /path/to/local/pc/
Explain Pull Data
-a, --archive archive mode -z, --compress compress file data during the transfer -h, --human-readable output numbers in a human-readable format --progress progress during transfer
Example Pull Data (Video)
Push Data With Rsync Command To Remote Server
Next we will try to push or send data to remote server. Make sure you have the login details. Then the command will like below. This time we will try to combine rsync with ssh to push data to remote server.
rsync -e ssh --progress /path/to/local/file user@ipserver:/path/to/server
Explain Push Data
-e, --rsh=COMMAND specify the remote shell to use
Example Push Data (Video)
How About If Remote Server Not Using Port 22?
In some cases, we will change the default ssh port for security. Then, how do we connect to a remote server with the ssh port that has been changed? It turns out that rsync can also be used to connect using a custom port. Here are the instructions:
rsync -azvh -e 'ssh -p port' --progress user@ipserver:/path/to/server/file /path/to/local/folder/
This is very basic command you can use to transfer data using rsync. The rsync manual contains a wide variety of examples. You can read here. Let me know if you find anything more exciting, so i can learn from you.
Here i’m not an expert or pro in linux or sysadmin, but just try to share little experience with my job. My article here is not so perfect, but i hope this article can help someone who just trying using linux like me. Hope you Enjoy.
Copy Directories (Update 23.11.2021)
I also using rsync to send entire directory complete with sub-directory and the file inside it to my local server using this command;
rsync -za --progress /source/directory/sub-directory user@destination:/path/to/destination/folder