rsync - 10 examples in 11 days (Day 08)

m4r4v

m4r4v

Posted on July 23, 2020

rsync - 10 examples in 11 days (Day 08)

Day 08

10 examples in 11 days

Sync Remote to Local over SSH

Yesterday on Day 07 I showed how we can sync files from our local machine to our remote machine using ssh. Today is the other way around. I will request a file from remote to local.

The syntax it's almost the same one from yesterday, the difference between yesterday's and the the one I am using today is that with the one below, I will not remove my remote file and the yesterday's source will be our destination and our destination will be yesterday's source. Let's remember the syntax and let me describe it to you so you can see by your self what I am talking about:

Note: As yesterday I will not show the local nor remote machines IP. Instead I will always display 111.111.111.111 IP as remote and 222.222.222.222 as local

iamgroot@laptop:~$ rsync (1)--progress (2)-vhre (3)ssh (4)iamgroot@111.111.111.111:(5)[remote folder]/(6)[remote file] (7)[local folder to download]
Enter fullscreen mode Exit fullscreen mode

Let's see what the above syntax does:

  1. --progress: shows progress while synching
  2. I used -vhre options
  • -v: verbose
  • -h: human readable
  • -r: recursive
  • -e: allows us to use ssh as remote shell and execute its commands
  1. ssh: invoking the ssh service to be used as remote shell.
  2. ssh connection parameters
  3. remote folder with full path
  4. remote file to download
  5. local folder where the remote file will be downloaded

Note: If the local folder doesn't exist it will be created

I created a folder called download-folder in my remote instance and inside of it I created a file called file_download.txt. I will download this file into my ~/Sync folder that we have been using.

iamgroot@remote-instance:~$ mkdir download-folder && touch download-folder/file_download.txt && echo "Hello World I will be downloaded" >> download-folder/file_download.txt
Enter fullscreen mode Exit fullscreen mode

Now let's sync from remote to local

iamgroot@laptop:~$ rsync --progress -vhre ssh iamgroot@111.111.111.111:download-folder/file_download.txt ~/Sync
receiving incremental file list
file_download.txt
             12 100%   11.72kB/s    0:00:00 (xfr#1, to-chk=0/1)

sent 43 bytes  received 113 bytes  34.67 bytes/sec
total size is 12  speedup is 0.08
Enter fullscreen mode Exit fullscreen mode

Let's check if it got downloaded

iamgroot@laptop:~$ ls Sync/
file1.txt  file2.txt  file3.txt  file_download.txt
Enter fullscreen mode Exit fullscreen mode

Nice right?

As you can see so far, rsync is a great tool to keep your files sync locally and remotely.

We are almost ending this series, hope you all readers are enjoying it, let me know if you have any doubt and I will be more than happy to help.


Thanks for reading, keep it safe!!

Follow, ❤ or 🦄

💖 💪 🙅 🚩
m4r4v
m4r4v

Posted on July 23, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related