amazon media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

Transferring files with rsync In [Ubuntu]

If you are coming from a GUI world, then you know transferring files from one location or folder to another is as easy as doing a few mouse clicks, the way it works in GNU/Linux is a bit different, although similar.

In GNU/Linux, rsync is one of the most useful utilities available for transferring data, it is a fast, powerful and versatile copying tool, it can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon.

Unlike in the GUI environment that features a minimum option for transferring, rsync offers a large number of options for the transfer of data, what I find interesting is that it can be used for backups and mirroring files.

Additional Features are:

  • support for copying links, devices, owners, groups, and permissions
  • exclude and exclude-from options similar to GNU tar
  • a CVS exclude mode for ignoring the same files that CVS would ignore
  • can use any transparent remote shell, including ssh or rsh
  • does not require super-user privileges
  • pipelining of file transfers to minimize latency costs
  • support for anonymous or authenticated rsync daemons (ideal for mirroring)

Note: Rsync doesn't support the transfer of files between two remote hosts, it only copies files from a remote host to local, and vice versa.

To get started with rsync, I'll suggest you create a test folder, and a test files in the folder for illustration, so, we would be backing up the test folder.

First, create a test folder:

sudo mkdir /home/test

I am creating the test folder in the home directory of my current user

Change your working directory into the the test folder, and create a random text file:

sudo touch file.txt

The next point of action is utilizing the rsycn command to backup our test folder:

sudo rsync -r /home/test /backup

The above command is using rsync as root to copy the content of the test directory (the source directory) to a backup directory (/backup) (which is the target directory, it would automatically create one if you don't already have a specified folder)

The -r option copies the file recursively, say you have multiple folder in the test directory, it would copy the directories, sub directories, and any files it find in there.

The directory is already owned by the root user, but in cases where you need to retain permission of a specific folder, and you've already copied the file with rsync, you can fix it by adding an -a option, e.g:

sudo rsync -a /home/test /backup

rsync won't copy the file again since it has already been copied before, the only thing it would do here is copy and replace the permission of the source directory to the target directory, so, it basically copies what was different.

If you want to display what the process is doing as it runs, you can activate the verbose mode, e.g

sudo rsync -av /home/test /backup

Copying Data Over SSH

You can use rsync to copy data locally to a remote server via SSH, for example:

sudo rsync -av /home/test ServerA:/backup

The command above is copying the test folder directory to the /backup directory on ServerA, ServerA is a simplification of my SSH Connection, learn how it's done below:

Synchronizing Files With Rsycn

Up until now, we've been copying files from one location to another, but what if we actually want to move files from one directory to another?

This is where the --delete option comes in, with this option you can keep files in sync, for example, if you copy a file from location A to B, and you've deleted some files in point A, with the --delete option it would look what has been removed in point A, and also apply the same to B, meaning it delete the removed file in point A to keep it in sync.

An example of the --delete option:

sudo rsync -av --delete /home/test /backup

Keeping the Same File as Separate in Target Location

If you want to copy, and keep the same file as separate in the target location, you use the -b (backup) option, The -b option renames files on the target that are being overwritten, this way you'll still have the original file, example:

sudo rsync -avb --delete /src  /target

Related Post(s)

  • How To Access Windows 10 Drive/Folder in VirtualBox

    To access Windows drive or folder in your Guest OS, you first of all, install VirtualBox guest utilities: sudo apt-get install virtualbox-guest-utils You then Add a shared folder by going into: Setti

  • Send Mail with Attachment Using Mutt in GNU/Linux

    Mutt is a powerful text-based mail client for Unix/Linux operating systems. It features color support, message threading, MIME support...

  • Using Pageant To Automatically Authenticate SSH key in Putty

    I can't count how many times I have typed my ssh key passphrase whenever my ssh connection times out, it is so annoying and repetitive. Well, thanks to the putty pageant, you can do that seamlessly.

  • Installing WP-CLI In a GNU/Linux Server

    WP-CLI is a command-line interface for WordPress. It can also be used with ClassicPress, as they are no differences in their usage, maybe just minimal if you are updating or downloading new ClassicPr

  • How To Send Mail To Multiple Addresses Using (mailx)

    In this guide, you'll learn a couple of ways you can send mail to multiple addresses using mailx. mailx is a utility program for sending and receiving mail. I assume you already have mailx command, i

  • Mounting and Unmounting Cloud Storage With (Rclone) in GNU/Linux

    Ever wondered if you could mount your preferred cloud storage as a virtual drive on your system? Thanks to Rclone, you can mount and access different kinds of cloud storage from a file manager, I'll