1
00:00:00,000 --> 00:00:16,679
Hey guys and welcome back. So in the previous nugget we had learned how we could use the

2
00:00:16,679 --> 00:00:22,920
tar utility to create a backup archive and we talked about how we could actually move

3
00:00:22,920 --> 00:00:28,320
that archive potentially to other remote servers. Now how on earth would we actually

4
00:00:28,320 --> 00:00:33,600
invoke this behavior? What tools do we have available for us? Well the reality is the

5
00:00:33,600 --> 00:00:40,280
big tool for this is one called R-Sync. Now what R-Sync is, it really is a tool for remote

6
00:00:40,280 --> 00:00:46,159
synchronization hence the name. Basically it's going to be used to copy and to synchronize

7
00:00:46,159 --> 00:00:53,960
different files and directories between a local server and a remote server. Now one of the cool

8
00:00:53,960 --> 00:00:59,960
features of the R-Sync utility is that it's not going to do a full copy of the data that we're

9
00:00:59,960 --> 00:01:05,879
trying to sync between say server one and server two. Similar to what we talked about before with

10
00:01:05,879 --> 00:01:12,400
respect to incremental backups and differential backups, instead when we happen to use R-Sync,

11
00:01:12,400 --> 00:01:20,159
R-Sync will efficiently only copy over files that need to be copied over IE if we happen to make a

12
00:01:20,239 --> 00:01:27,759
copy from server one to server two and then we happen to add a new file to server one,

13
00:01:27,759 --> 00:01:34,239
let's just say file one dot txt. If we happen to sync our data back over, because the only difference

14
00:01:34,239 --> 00:01:39,799
here is file one dot txt, that is the only thing that is new here that is not present over here

15
00:01:39,799 --> 00:01:46,159
already. The only thing that is going to be sent over via R-Sync is this file right here. So this

16
00:01:46,159 --> 00:01:51,599
is going to be nice and lightweight and nice and efficient. So an important flag we have to

17
00:01:51,599 --> 00:01:59,200
understand for the purposes of using the R-Sync utility is this dash A flag. This is for archive

18
00:01:59,200 --> 00:02:05,280
and this is going to be very useful when we want to be copying over multiple files and directories

19
00:02:05,280 --> 00:02:10,960
and say for example files within those directories. Using the archive flag is going to allow us to

20
00:02:10,960 --> 00:02:18,159
preserve a lot of valuable information such as the actual permissions of those files will be retained

21
00:02:18,159 --> 00:02:24,480
and copied over as well as the file ownership so on so forth. Now we also have additional options,

22
00:02:24,480 --> 00:02:31,280
we can use dash N to perform what is called a dry run IE. Just simulate the changes that would happen

23
00:02:31,280 --> 00:02:37,760
IE, don't actually copy over, just give us a summary of what you would copy over if you're going to do

24
00:02:37,840 --> 00:02:43,199
it for real. So this can be a good way for us to check what is actually in sync between our local

25
00:02:43,199 --> 00:02:49,359
server and the remote server without actually taxing the network or changing anything on any of the

26
00:02:49,359 --> 00:02:56,560
storage devices and much like the dash A flag whereby we can recursively copy files whilst

27
00:02:56,560 --> 00:03:03,199
keeping permissions and ownership. If we use the dash R flag we get that recursive copy IE will

28
00:03:03,199 --> 00:03:08,799
actually copy over the directory and the sub directories and the files within however we will

29
00:03:08,799 --> 00:03:15,599
not keep the ownership and the permissions and we can also use flags such as dash Z to invoke

30
00:03:15,599 --> 00:03:22,639
compression and we can also use dash H to output the information in a human readable format. So a lot

31
00:03:22,639 --> 00:03:28,319
of really cool and useful options with this command so with that said how about we dive in and look

32
00:03:28,319 --> 00:03:33,439
at this tool in action then. Okay so what I actually want to do is let me just close down my SSH

33
00:03:33,439 --> 00:03:38,879
session and I'll open my machine up right here. What I'm going to do is I'm going to open up

34
00:03:38,879 --> 00:03:44,400
another machine that I'm going to copy my data to. So what I'll do is I'll go to my virtual box

35
00:03:44,400 --> 00:03:49,919
and what I'll do is I'll power on one of my Ubuntu machines which is on the same network. Okay just

36
00:03:49,919 --> 00:03:55,439
give this a moment and in the meantime I'll log in to my device on the right here. Okay so here

37
00:03:55,439 --> 00:04:01,359
is my other device online what I'll do is I'll just log into this one as well type in my password.

38
00:04:01,359 --> 00:04:06,960
Okay so on the left hand side here what I will do is an IP adder to see my IP address. We can

39
00:04:06,960 --> 00:04:16,159
actually see the IP address is 192.1680.44. If I open up my terminal here and I do an IP adder

40
00:04:16,159 --> 00:04:23,600
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

41
00:04:23,600 --> 00:04:31,520
I'll ping 192.1680.44 and we can actually see we do have reachability. Now what I want to do here

42
00:04:31,520 --> 00:04:36,640
is if I do an LS we can actually see this particular backup file that we just created

43
00:04:36,640 --> 00:04:42,879
in the previous Nuggets. I want to actually transfer that information or that file should I say

44
00:04:42,879 --> 00:04:48,640
over to this remote server. So what I'll do here is I'll clear the screen here. Now the command that

45
00:04:48,719 --> 00:04:55,839
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

46
00:04:55,839 --> 00:05:01,919
I will do dash h to have human readable output and now specify the actual file I want to copy

47
00:05:01,919 --> 00:05:09,519
so that will be backup dot tbz. Now what I need to do is I need to specify whereabouts I want to

48
00:05:09,519 --> 00:05:14,879
copy this to. Now before I do anything what I should say is that I want to be able to log in

49
00:05:14,879 --> 00:05:21,519
to this machine here on the left. So on the left here I have a user of ipv0 and I'm going to need

50
00:05:21,519 --> 00:05:27,600
to know the password for this particular machine right here. Now another thing we need to know

51
00:05:27,600 --> 00:05:32,240
is whereabouts do we want to copy this to. So what I'll actually do here is I'll create a directory

52
00:05:32,240 --> 00:05:38,399
here I'll just call this directory test backup okay so we can do ls here is this particular

53
00:05:38,399 --> 00:05:44,159
directory and if I happen to go into this directory actually I'll just dive in I do a pwd

54
00:05:44,160 --> 00:05:51,439
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

55
00:05:52,080 --> 00:05:58,560
zh as I said before specify the file backup dot tbz. Now what I need to do is to log in to that

56
00:05:58,560 --> 00:06:05,520
machine on the left so I'll log in as ipv0 and I will say at and I'll give that machine's ip

57
00:06:05,520 --> 00:06:13,840
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

58
00:06:13,839 --> 00:06:20,079
do a colon and then specify the path where I actually want to copy this file to. So what is the path the

59
00:06:20,079 --> 00:06:28,560
path on the left is going to be this particular path here so I'll say home ipv0 test backup. Now if I

60
00:06:28,560 --> 00:06:34,399
enter now what I'm going to have to do is to type in the password for the machine on the left okay so

61
00:06:34,399 --> 00:06:39,519
I'll type in that password and we can see here the file has been copied and we can see the size of the

62
00:06:39,519 --> 00:06:46,719
file that was indeed sent. So now if I do an ls on the left and this directory notice we actually

63
00:06:46,719 --> 00:06:52,959
have a copy of this tarball which of course what we could do is we could extract this as we did in

64
00:06:52,959 --> 00:07:01,120
the previous nugget we can say tarxvjf and specify the name of the file which is backup dot tbz if

65
00:07:01,120 --> 00:07:06,159
I hit enter this is now going to extract all this information give it some time okay so that is now

66
00:07:06,160 --> 00:07:11,920
finished if I do an ls we can see we have these directory structures I can go into say for example

67
00:07:11,920 --> 00:07:18,240
the var directory as we did before we do an ls we have all of this information that we saved from

68
00:07:18,240 --> 00:07:25,120
the machine on the right now copied and in this form extracted to the machine on the left very

69
00:07:25,120 --> 00:07:30,560
very cool so what I'll do here is I'll go back to my home directory here and what I will also do

70
00:07:30,639 --> 00:07:36,959
is I will use rsync with the dash a flag this is the archive flag this is going to allow it to be

71
00:07:36,959 --> 00:07:43,360
able to copy multiple files and directories as opposed to a single tarball whilst keeping

72
00:07:43,360 --> 00:07:48,480
all of the permissions and ownership in place so what I'll do here I'll just create a new directory

73
00:07:48,480 --> 00:07:53,519
and I'll just call this one blattest and I'll cd into blattest and I'll just create some files I'll

74
00:07:53,919 --> 00:08:00,879
touch file 1, file 2 and file 3 okay so what I want to do here is I actually want to copy the

75
00:08:00,879 --> 00:08:07,120
contents of blattest and those three files within so what I will do is I'll say rsync and I'll say

76
00:08:07,120 --> 00:08:14,079
dash a this time the archive flag and then I'll just do as I did before vzh and then I'll specify

77
00:08:14,079 --> 00:08:19,279
what it is I want to copy over which is blattest and then I'll specify where it is I want to copy

78
00:08:19,279 --> 00:08:26,799
it so I'll say ipv0 at 192 168 0.44 and actually let me just create a new directory I'll just call

79
00:08:26,799 --> 00:08:36,079
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

80
00:08:36,079 --> 00:08:41,279
hit enter I'll type in the password for the machine on the left hit enter again now we can see here

81
00:08:41,279 --> 00:08:47,759
we actually have this incremental copy so if I do an ls and I go into random dump I do an ls we can

82
00:08:47,759 --> 00:08:54,240
see here we actually have these three files now the cool thing is is if I go into my blattest once

83
00:08:54,240 --> 00:09:01,120
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

84
00:09:01,120 --> 00:09:07,679
run the same command i.e copy the same folder blattest and I hit enter type in my passwords hit

85
00:09:07,679 --> 00:09:15,600
enter again notice the only file that was sent over was file 4 because file 1 2 and 3 already existed

86
00:09:15,600 --> 00:09:21,120
so the only thing that had to be sent was the difference i.e the change in the contents if I

87
00:09:21,120 --> 00:09:27,759
do an ls now suddenly we now see file 4 has indeed been copied over ok dox as you can see here the

88
00:09:27,759 --> 00:09:34,480
rsync utility is very very useful for being able to transfer our backup data between different systems

89
00:09:34,480 --> 00:09:40,080
and it works in this incremental fashion ok dox I hope this has been informative for you and I'd

90
00:09:40,080 --> 00:09:45,360
like to thank you for viewing

