Bog'liq Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)
[ 315 ] When you've had more NFS practice than you can tolerate, we'll move on to a few
ways in which you can copy files from one node to another without needing to set
up an intermediary service or daemon.
Transferring files with rsync Of all the countless tools and utilities available in the Linux and Unix world, few
are as beloved as
rsync
.
rsync
is a utility that you can use to copy data from one
place to another very easily, and there are many options available to allow you to be
very specific about how you want the data to be transferred. Examples of its many
use cases include copying files while preserving permissions, copying files while
backing up replaced files, and even setting up incremental backups. If you don't
already know how to use
rsync
, you'll probably want to get lots of practice with it,
as it's something you'll soon see will be indispensable during your career as a Linux
administrator, and it is also something that the Linux community generally assumes
you already know.
rsync
is not hard to learn. Most administrators can learn the
basic usage in about an hour or less, but the countless options available will lead
you to learn new tricks even years down the road.
Another aspect that makes
rsync
flexible is the many ways you can manipulate the
source and target directories. I mentioned earlier that
rsync
is a tool you can use to
copy data from one place to another. The beauty of this is that the source and target
can literally be anywhere you'd like. For example, the most common usage of
rsync
is to copy data from a directory on one server to a directory on another server over
the network. However, you don't even have to use the network; you can even copy
data from one directory to another on the same server. While this may not seem like
a useful thing to do at first, consider that the target directory may be a mount point
that leads to a backup disk, or an NFS share that actually exists on another server.
This also works in reverse: you can copy data from a network location to a local
directory if you desire.
To get started with practicing with
rsync
, I recommend that you find some sample
files to work with. Perhaps you have a collection of documents you can use,
MP3 files, videos, text files, basically any kind of data you have lying around. It's
important to make a copy of this data. If we make a mistake we could overwrite
things, so it's best to work with a copy of the data, or data you don't care about,
while you're practicing. If you don't have any files to work with, you can create
some text files. The idea is to practice copying files from one place to another; it
really doesn't matter what you copy or where you send it to. I'll walk you through
some
rsync
examples that will progressively increase in complexity. The first few
examples will show you how to back up a
home
directory, but later examples will
be potentially destructive so you will probably want to work with sample files until
you get the hang of it.