[
317
]
The
archive
mode is great and all, but wouldn't it be nice to be able to watch what
rsync
is up to when it runs? Add the
-v
option and try the command again:
sudo rsync -av /home/myuser /backup
This time,
rsync
will display on your terminal what it's doing as it runs (
-v
activates
verbose
mode). This is actually one of my favorite variations of the
rsync
command,
as I like to copy everything and retain all the metadata, as well as watch what
rsync
is doing as it works.
What if I told you that
rsync
supports SSH by default? It's true! Using
rsync
, you can
easily copy data from one node to another, even over SSH. The same options apply,
so you don't actually have to do anything different other than point
rsync
to the
other server, rather than to another directory on your local server:
sudo rsync -av /home/myuser admin@192.168.1.5:/backup
With this example, I'm copying the
home
directory for
myuser
to the
/backup
directory
on server
192.168.1.5
. I'm connecting to the other server as the
admin
user. Make
sure you change the user account and IP address accordingly, and also make sure
the user account you use has access to the
/backup
directory. When you run this
command, you should get prompted for the SSH password as you would when
using plain SSH to connect to the server. After the connection is established, the
files will be copied to the target server and directory.
Now, we'll get into some even cooler examples (some of which are potentially
destructive), and we probably won't want to work with an actual
home
directory
for these, unless it's a test account and you don't care about its contents. As I've
mentioned before, you should have some test files to play with. When practicing,
simply replace my directories with yours. Here's another variation worth trying:
sudo rsync -av --delete /src /target
Now I'm introducing you to the
--delete
option. This option allows you to
synchronize two directories. Let me explain why this is important. With every
rsync
example up until now, we've been copying files from point A to point B, but we
weren't deleting anything. For example, let's say you've already used
rsync
to copy
contents from point A to point B. Then, you delete some files from point A. When
you use
rsync
to copy files from point A to point B again, the files you deleted in
point A won't be deleted in point B. They'll still be there. This is because by default,
rsync
copies data between two locations, but it doesn't remove anything. With the
--delete
option, you're effectively synchronizing the two points, thus you're telling
rsync
to make them the same by allowing it to delete files in the target that are no
longer in the source.
Sharing and Transferring Files
Do'stlaringiz bilan baham: |