Hey guys and welcome back. So in the previous nugget we had learned how we could use the
tar utility to create a backup archive and we talked about how we could actually move
that archive potentially to other remote servers. Now how on earth would we actually
invoke this behavior? What tools do we have available for us? Well the reality is the
big tool for this is one called R-Sync. Now what R-Sync is, it really is a tool for remote
synchronization hence the name. Basically it's going to be used to copy and to synchronize
different files and directories between a local server and a remote server. Now one of the cool
features of the R-Sync utility is that it's not going to do a full copy of the data that we're
trying to sync between say server one and server two. Similar to what we talked about before with
respect to incremental backups and differential backups, instead when we happen to use R-Sync,
R-Sync will efficiently only copy over files that need to be copied over IE if we happen to make a
copy from server one to server two and then we happen to add a new file to server one,
let's just say file one dot txt. If we happen to sync our data back over, because the only difference
here is file one dot txt, that is the only thing that is new here that is not present over here
already. The only thing that is going to be sent over via R-Sync is this file right here. So this
is going to be nice and lightweight and nice and efficient. So an important flag we have to
understand for the purposes of using the R-Sync utility is this dash A flag. This is for archive
and this is going to be very useful when we want to be copying over multiple files and directories
and say for example files within those directories. Using the archive flag is going to allow us to
preserve a lot of valuable information such as the actual permissions of those files will be retained
and copied over as well as the file ownership so on so forth. Now we also have additional options,
we can use dash N to perform what is called a dry run IE. Just simulate the changes that would happen
IE, don't actually copy over, just give us a summary of what you would copy over if you're going to do
it for real. So this can be a good way for us to check what is actually in sync between our local
server and the remote server without actually taxing the network or changing anything on any of the
storage devices and much like the dash A flag whereby we can recursively copy files whilst
keeping permissions and ownership. If we use the dash R flag we get that recursive copy IE will
actually copy over the directory and the sub directories and the files within however we will
not keep the ownership and the permissions and we can also use flags such as dash Z to invoke
compression and we can also use dash H to output the information in a human readable format. So a lot
of really cool and useful options with this command so with that said how about we dive in and look
at this tool in action then. Okay so what I actually want to do is let me just close down my SSH
session and I'll open my machine up right here. What I'm going to do is I'm going to open up
another machine that I'm going to copy my data to. So what I'll do is I'll go to my virtual box
and what I'll do is I'll power on one of my Ubuntu machines which is on the same network. Okay just
give this a moment and in the meantime I'll log in to my device on the right here. Okay so here
is my other device online what I'll do is I'll just log into this one as well type in my password.
Okay so on the left hand side here what I will do is an IP adder to see my IP address. We can
actually see the IP address is 192.1680.44. If I open up my terminal here and I do an IP adder
we can see I am in 192.1680.65 so we're on the same network. Let's try to ping this device here so
I'll ping 192.1680.44 and we can actually see we do have reachability. Now what I want to do here
is if I do an LS we can actually see this particular backup file that we just created
in the previous Nuggets. I want to actually transfer that information or that file should I say
over to this remote server. So what I'll do here is I'll clear the screen here. Now the command that
I'm going to do is going to be rsync and I'm going to say v for verbosity I will say dash z for compression
I will do dash h to have human readable output and now specify the actual file I want to copy
so that will be backup dot tbz. Now what I need to do is I need to specify whereabouts I want to
copy this to. Now before I do anything what I should say is that I want to be able to log in
to this machine here on the left. So on the left here I have a user of ipv0 and I'm going to need
to know the password for this particular machine right here. Now another thing we need to know
is whereabouts do we want to copy this to. So what I'll actually do here is I'll create a directory
here I'll just call this directory test backup okay so we can do ls here is this particular
directory and if I happen to go into this directory actually I'll just dive in I do a pwd
this is the location I want to be copying this to. So what I will do here I'll say rsync I will do v
zh as I said before specify the file backup dot tbz. Now what I need to do is to log in to that
machine on the left so I'll log in as ipv0 and I will say at and I'll give that machine's ip
address which I believe is 192.168.0. was that 44 I think yep 0.44 and now what I'm going to do is to
do a colon and then specify the path where I actually want to copy this file to. So what is the path the
path on the left is going to be this particular path here so I'll say home ipv0 test backup. Now if I
enter now what I'm going to have to do is to type in the password for the machine on the left okay so
I'll type in that password and we can see here the file has been copied and we can see the size of the
file that was indeed sent. So now if I do an ls on the left and this directory notice we actually
have a copy of this tarball which of course what we could do is we could extract this as we did in
the previous nugget we can say tarxvjf and specify the name of the file which is backup dot tbz if
I hit enter this is now going to extract all this information give it some time okay so that is now
finished if I do an ls we can see we have these directory structures I can go into say for example
the var directory as we did before we do an ls we have all of this information that we saved from
the machine on the right now copied and in this form extracted to the machine on the left very
very cool so what I'll do here is I'll go back to my home directory here and what I will also do
is I will use rsync with the dash a flag this is the archive flag this is going to allow it to be
able to copy multiple files and directories as opposed to a single tarball whilst keeping
all of the permissions and ownership in place so what I'll do here I'll just create a new directory
and I'll just call this one blattest and I'll cd into blattest and I'll just create some files I'll
touch file 1, file 2 and file 3 okay so what I want to do here is I actually want to copy the
contents of blattest and those three files within so what I will do is I'll say rsync and I'll say
dash a this time the archive flag and then I'll just do as I did before vzh and then I'll specify
what it is I want to copy over which is blattest and then I'll specify where it is I want to copy
it so I'll say ipv0 at 192 168 0.44 and actually let me just create a new directory I'll just call
this random dump so I'll do my column and I'll say home ipv0 and it's going to random dump and if I
hit enter I'll type in the password for the machine on the left hit enter again now we can see here
we actually have this incremental copy so if I do an ls and I go into random dump I do an ls we can
see here we actually have these three files now the cool thing is is if I go into my blattest once
again and I just create a new file just call this one file 4 and I go back out and if I arrow up and I
run the same command i.e copy the same folder blattest and I hit enter type in my passwords hit
enter again notice the only file that was sent over was file 4 because file 1 2 and 3 already existed
so the only thing that had to be sent was the difference i.e the change in the contents if I
do an ls now suddenly we now see file 4 has indeed been copied over ok dox as you can see here the
rsync utility is very very useful for being able to transfer our backup data between different systems
and it works in this incremental fashion ok dox I hope this has been informative for you and I'd
like to thank you for viewing