Linux rsync Command and Moving House

george udosen
2 min readDec 6, 2018

--

Recently I had to move my belongings from one computer to another and I had a lot of stuff I had to move. I first thought of using an external HDD to copy then attach to the new device and then copy again. I tried that and it worked but it meant a lot of moves here and there and it interferes with my study and work.

So I remembered the rsync Linux tools that moves materials (files and folders) over a network with little issues (that is if you are authorized to do so). I am a command line person and do most of my daily chores from there and this wasn’t going to be a different case.

Scenario:

  • Two computers on the same network
  • New system IP: 10.23.0.45
  • Can be on the same network or different networks

Basic format of the rsync command would be:

SYNOPSIS
Local: rsync [OPTION...] SRC... [DEST]
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

Several things to note here we can

  1. Use it locally,
  2. Use it remotely via pull or push, and
  3. Use it as a daemon — now this is the cool one.

I will be using the “Push: rsync [OPTION…] SRC… [USER@]HOST:DEST” method and so hers is my command to move a simple file between the old and new computers:

rsync -avz file-to-move.txt george@10.23.0.45:/destination/for/file

And then sit back and enjoy. Now note several things when using the rsync command else you will move more or less than intended. Let me use these simple command examples to explain:

  1. command: rsync /folder/* /destinationA/
  2. command: rsync /folder /destinationA/

In (1) we are moving the “contents” of the folder, hence the “*” to destinationA, and not the “folder” itself, while for the second command we are moving the “folder and contents” not just the contents to “dstinationA”.

Simply put, “if you intend to move the folder contents only” use the first command. But if you want to move the folder and its contents then use the second command.

This is a simplified version of using this tool but you can add a script to the whole works and have bash read that file and send the contents to rsync to automate the moving process for your data. Happy rsyncing!

--

--

george udosen
george udosen

Written by george udosen

DevOps | FullStack developer | Python::Flask | GCP Cloud Certified | AWS & AZURE Cloud Savy | Linux Sysadmin | Google IT Support

No responses yet