1
00:00:00,080 --> 00:00:08,310
In this session we are going to learn about RDB persistent. So  I have already logged into the server

2
00:00:08,330 --> 00:00:09,770
and right now I am in the Home Directory of

3
00:00:09,770 --> 00:00:11,420
Redis  Admin User

4
00:00:14,400 --> 00:00:20,660
and if you remember all our Redis File  or Redis Configuration is available under Redis- stable

5
00:00:20,790 --> 00:00:26,800
Directory. So we are moving inside Redis- stable Directory and here if i do ls-lrt

6
00:00:29,230 --> 00:00:31,220
I can see Redis.conf File.

7
00:00:31,650 --> 00:00:38,970
Okay so, this is the file in which we are going to make Configuration related changes to enable RDB

8
00:00:39,000 --> 00:00:41,760
Snapshotting.  Okay.

9
00:00:41,810 --> 00:00:45,110
So I'm going to open this file using VI Editor.

10
00:01:01,370 --> 00:01:01,640
okay.

11
00:01:01,660 --> 00:01:07,780
So you need to scroll down a bit and you need to reach to the point where it talks about RDB

12
00:01:11,100 --> 00:01:11,340
okay.

13
00:01:11,370 --> 00:01:17,460
So right now,  this is the  line which is talking about db file name.

14
00:01:17,910 --> 00:01:24,880
Okay so this,  db file name is going to be the Snapshot File Name, which is going to get created.

15
00:01:24,930 --> 00:01:27,750
So by default it is called dumb.rdb.

16
00:01:28,110 --> 00:01:30,860
So whenever it is going to perform the Snapshotting,

17
00:01:31,050 --> 00:01:34,050
It is going to create a file which is called dumb.rdb.

18
00:01:34,210 --> 00:01:37,080
And if you want to change the name you can do that.

19
00:01:37,110 --> 00:01:44,480
So it is just an Optional Name or if you want to just keep the same name,  you can do that as well.

20
00:01:44,550 --> 00:01:46,530
So let's say,  I want to change it to

21
00:01:53,210 --> 00:01:55,340
dump_redis.rdb

22
00:01:55,370 --> 00:02:00,280
So I have,  I just need to make those changes in the  Configuration File.

23
00:02:02,090 --> 00:02:08,760
And now you'll be wondering on,  at which location this file is going to get saved.

24
00:02:09,100 --> 00:02:09,390
Okay.

25
00:02:09,420 --> 00:02:14,790
So the way to specify that is,  here using these dir parameter.

26
00:02:14,970 --> 00:02:16,730
So you make a change  here.

27
00:02:16,930 --> 00:02:17,140
Okay.

28
00:02:17,160 --> 00:02:19,530
So by default it is pointing to ./

29
00:02:20,070 --> 00:02:27,570
So by that what it means is,  that whichever place basically you are going to start Redis from,  the

30
00:02:27,570 --> 00:02:33,750
same directory is going to be used for keeping this dump_redis.rdb

31
00:02:33,810 --> 00:02:39,480
Now if I do not make any changes and I just want to demonstrate  you,  how it is going to work.

32
00:02:39,480 --> 00:02:43,680
So let me just save this and exit from here

33
00:02:48,360 --> 00:02:53,920
and let me go back to the home directory of this user.  Okay.

34
00:02:53,960 --> 00:02:58,790
If I do pwd,  You can see right now I am in the home directory of Redis Admin and if  i do ls,

35
00:02:58,800 --> 00:03:05,920
the only directories or  the files you see are, these are the 3 items which you see.

36
00:03:06,480 --> 00:03:06,720
Okay.

37
00:03:06,740 --> 00:03:14,480
So I am going to start Redis Server by providing Redis Server and also we need to supply the Configuration

38
00:03:14,490 --> 00:03:20,190
File Name. So which is available at this location.

39
00:03:20,210 --> 00:03:25,330
So I'm specifying that and also we are using &

40
00:03:25,340 --> 00:03:28,200
So start this process as a background.

41
00:03:28,280 --> 00:03:34,790
Now notice in this case,  the you know, the Redis dump file which is going to be created is,  going to be created

42
00:03:34,790 --> 00:03:36,290
at this location.

43
00:03:36,640 --> 00:03:42,460
which  is /home/redisadmin.  Because this is the location from where we are starting Redis

44
00:03:42,490 --> 00:03:49,030
server and by default for the directory in the Redis.conf  file,  it was specified as./

45
00:03:49,160 --> 00:03:55,000
So basically it is similar like present working directory.  Okay.

46
00:03:55,010 --> 00:04:02,870
So once I hit enter and if I do ls,  right now there is nothing available because  Redis has not

47
00:04:02,870 --> 00:04:04,300
performed any Snapshotting.

48
00:04:04,620 --> 00:04:04,880
Okay.

49
00:04:04,970 --> 00:04:13,700
So we also need to specify,  what is this Snapshotting. Mechanism or basically how often Snapshotting should take

50
00:04:13,700 --> 00:04:14,060
place.

51
00:04:14,060 --> 00:04:19,220
So if you go and open this file again using VI  editor,  you will also notice,

52
00:04:26,080 --> 00:04:29,500
I guess we need to go bit up.  Okay.

53
00:04:29,630 --> 00:04:30,330
All right,  here.

54
00:04:30,350 --> 00:04:38,060
So by default you see, these are the default configuration which is available here but you can specify

55
00:04:38,060 --> 00:04:43,130
the configuration based on the approach which you want to follow.

56
00:04:43,130 --> 00:04:46,930
So in this case using save as a keyword.

57
00:04:47,210 --> 00:04:53,330
What it is telling to Redis is,  that save or snapshot all the data every 900 seconds.

58
00:04:53,510 --> 00:04:56,520
If there is at least one key has been changed.

59
00:04:56,700 --> 00:04:57,020
Okay.

60
00:04:57,020 --> 00:05:01,910
The second line what it is telling is that  perform a Snapshotting every 300 seconds.

61
00:05:01,910 --> 00:05:07,220
If there are 10 keys,  which has been added or updated.

62
00:05:07,650 --> 00:05:08,120
Okay.

63
00:05:08,180 --> 00:05:10,430
And the third one is telling about

64
00:05:13,350 --> 00:05:15,990
to perform a snapshot every 60 seconds.

65
00:05:16,110 --> 00:05:25,350
If there are 10000 Keys has been changed. Okay so all of these three conditions are going to get checked.

66
00:05:25,400 --> 00:05:29,080
And based on that,  the Snapshotting is going to happen.

67
00:05:29,120 --> 00:05:36,290
Now what I will do is I'll  create one more piece of line and I will say to

68
00:05:40,970 --> 00:05:42,800
snapshot every 30 seconds

69
00:05:48,320 --> 00:05:51,170
and we can save there is 50 keys changed.

70
00:05:51,500 --> 00:05:55,130
Okay so I have added,  added it as a First Line.

71
00:05:55,130 --> 00:06:02,620
This can be, you know, any line but usually the practice is you give the higher number on the top and

72
00:06:02,630 --> 00:06:08,720
then you give  the lower number of Snapshotting at the bottom but that's all about how you want

73
00:06:08,720 --> 00:06:12,820
to basically document your these things.

74
00:06:12,820 --> 00:06:13,930
But yeah.

75
00:06:13,950 --> 00:06:15,140
So that's all for now.

76
00:06:15,270 --> 00:06:23,360
And if I'm going to save it and again whenever you make any changes in redis.conf

77
00:06:23,460 --> 00:06:26,540
It is not going to reflect automatically.

78
00:06:26,730 --> 00:06:30,640
So whatever changes I have done there,  has not been reflected as of now.

79
00:06:31,210 --> 00:06:33,480
So I need to restart Redis.

80
00:06:37,550 --> 00:06:41,420
So what I will do is,  I'll just kill this process.

81
00:06:45,990 --> 00:06:47,790
Now if I see Redis  is not running

82
00:06:51,430 --> 00:06:54,910
I'll copy paste this Redis  startup command  to start Redis.

83
00:07:01,620 --> 00:07:08,020
Okay let's do  ls-lrt. So right now,  we do not see any dump file which has been created.

84
00:07:08,060 --> 00:07:10,130
Now let's start inserting data to Redis

85
00:07:16,690 --> 00:07:21,220
So I already have a file which is called country code names.

86
00:07:21,220 --> 00:07:26,380
It is having around 240 plus record. So  I'm going to insert this  to Redis.

87
00:07:35,880 --> 00:07:40,630
So I'm going to use Mass Insertion Approach or Redis cli  pipe Approach.

88
00:07:50,190 --> 00:07:52,160
Okay so it has performed the insertion

89
00:07:55,550 --> 00:08:03,080
and now if I go back to Home Directory and do  ls-lrt. Now you can see we have a dump_redis. rdb File

90
00:08:03,080 --> 00:08:10,070
Okay so which means,  it has performed the snapshot or taken a snapshot based

91
00:08:10,070 --> 00:08:10,460
on the

92
00:08:13,620 --> 00:08:16,730
whatever configuration which we have defined in the Configuration File.

93
00:08:17,330 --> 00:08:18,310
Okay.

94
00:08:18,340 --> 00:08:20,500
Now what is the mechanism to restore it.

95
00:08:26,030 --> 00:08:29,120
So basically our dump file is available here.

96
00:08:29,810 --> 00:08:34,520
So we need to make sure in this case,  basically when we are starting Redis

97
00:08:37,460 --> 00:08:43,820
and since in the Redis.conf File, dir property is set to ./   which means present working

98
00:08:43,820 --> 00:08:44,630
directory.

99
00:08:44,720 --> 00:08:50,900
So whenever you start Redis, it is going to look for this dump file in the current working directory.

100
00:08:51,260 --> 00:08:54,500
And then if it is available, it is going to restore everything.

101
00:08:54,500 --> 00:09:00,920
But if you are starting Redis  from the directory, where this file or dump.rdb file doesn't

102
00:09:00,920 --> 00:09:07,160
exist,  then it will not be able to restore anything. It would be assuming there is no snapshot available

103
00:09:07,820 --> 00:09:10,300
and it will not be able to restore any data.

104
00:09:11,790 --> 00:09:13,500
So let me show you that approach.

105
00:09:13,560 --> 00:09:20,170
So we'll move to raw_data directory and here if you see, we do not have any

106
00:09:20,180 --> 00:09:23,070
dump_redis.rdb  file.

107
00:09:32,790 --> 00:09:35,370
so let me kill  this Redis process.

108
00:09:44,640 --> 00:09:45,000
Okay.

109
00:09:45,010 --> 00:09:47,120
We do not have Redis running right now.

110
00:09:47,590 --> 00:09:51,040
So let's say, if I start Redis from here

111
00:10:01,990 --> 00:10:02,270
okay.

112
00:10:02,310 --> 00:10:08,580
So in this case Redis will not be able to restore the data because in the configuration file we have

113
00:10:08,580 --> 00:10:13,920
defined that dumpfile  is going to be stored at ./ location which is present working directory

114
00:10:14,340 --> 00:10:21,020
but when I am starting Redis, I am starting from the location where Redis doesn't have or basically there

115
00:10:21,020 --> 00:10:23,580
is no dump file.  okay or

116
00:10:23,620 --> 00:10:26,750
There is no snapshot file available, which can be restored.

117
00:10:26,820 --> 00:10:32,190
So Redis is just going to assume that there is  nothing available to restore and it is just

118
00:10:32,190 --> 00:10:36,300
going to start without loading any data.

119
00:10:36,910 --> 00:10:43,230
Okay so let's start this and let's connect to Redis, using Redis cli.  Specify the port

120
00:10:47,200 --> 00:10:55,960
and if I do dbsize,  you can see I do not have any data and if I do Keys *  you can see we do not have

121
00:10:55,960 --> 00:11:04,690
any data. The reason being is, we restarted it from a different directory and there was no dumped file available

122
00:11:04,690 --> 00:11:07,230
to restore.

123
00:11:07,500 --> 00:11:16,140
So now there are two things which you can do.  Either you can move back to directory where you have this

124
00:11:16,200 --> 00:11:22,770
dump_redis.rdb file available or let's say you want to restart Redis from any

125
00:11:22,770 --> 00:11:27,870
other location. In that case you can move this file from this location to the location from where you

126
00:11:27,870 --> 00:11:29,250
want to start Redis from.

127
00:11:30,160 --> 00:11:30,710
OK.

128
00:11:30,720 --> 00:11:37,740
So in this case I'm just going to kill previous  Redis process and then we will be starting Redis from

129
00:11:37,770 --> 00:11:38,460
this location

130
00:11:53,360 --> 00:11:53,720
okay.

131
00:11:53,740 --> 00:12:00,750
So we do not have Redis running  right now and currently I am in the Redis Admin Users Home

132
00:12:00,760 --> 00:12:05,220
Directory and where we have dump_redis. rdb file available

133
00:12:05,380 --> 00:12:10,870
So I'm going to start Redis by using Redis-server Command.

134
00:12:14,050 --> 00:12:20,200
and also going to provide the Configuration File Location and let's start this as a background process.

135
00:12:22,390 --> 00:12:27,020
So once we do that and when we log in to Redis using Redis cli

136
00:12:33,270 --> 00:12:43,450
and if I  run dbsize,  this time you can see we have 247 Key Value Pair available in Redis.

137
00:12:43,460 --> 00:12:48,050
And if I do Keys *  you can see these are the number of keys which are available.

138
00:12:48,080 --> 00:12:53,690
So basically what it has done is,  it has restored the snapshot which was taken

139
00:12:58,030 --> 00:12:58,400
OK.

140
00:12:58,460 --> 00:13:03,680
If you want to see any value available for this key.  You can use Get command and you can see the data

141
00:13:03,680 --> 00:13:04,220
is available in

142
00:13:12,200 --> 00:13:12,530
OK.

143
00:13:12,570 --> 00:13:13,560
So that's one way.

144
00:13:15,510 --> 00:13:15,780
OK.

145
00:13:15,810 --> 00:13:20,910
So this is probably not the best approach in the Production.  In the Production,  you always want your

146
00:13:20,910 --> 00:13:28,650
dump rdb file to be created at a fixed location and also always to be restored from that fixed location

147
00:13:28,770 --> 00:13:37,790
because in a production you're going to run Redis from a,  through probably some start up Script and you

148
00:13:37,790 --> 00:13:40,610
don't want all this location to be, you know, Volatile.

149
00:13:40,620 --> 00:13:50,030
You  want it to be Static.  So let's go back to Redis- stable directory and then move on or  basically

150
00:13:50,030 --> 00:13:51,170
open the file which we want

151
00:13:51,170 --> 00:13:51,590
to Edit.

152
00:14:00,150 --> 00:14:07,270
and then move back to this location,  where it say directory and here you specify the full name or full  path

153
00:14:07,270 --> 00:14:14,820
of the directory,  where you want to keep all  this snapshotting   file or from where you want to restore

154
00:14:14,820 --> 00:14:15,690
the snapshot file.

155
00:14:15,820 --> 00:14:16,130
Okay.

156
00:14:16,160 --> 00:14:18,600
So here I'm going to specify

157
00:14:24,090 --> 00:14:27,360
home redis admin.

158
00:14:27,390 --> 00:14:32,450
So now this is the location or probably I will also specify redis backup.

159
00:14:33,060 --> 00:14:41,310
Okay,  so this is the  directory  where the Redis is going to basically, you know,  put all the snapshot file or

160
00:14:41,310 --> 00:14:47,260
this is the location from where it is going to restore the snapshot file.

161
00:14:47,340 --> 00:14:53,360
I'm not sure if, you know, Redis will automatically create this directory. So let's check that.  I've saved

162
00:14:53,360 --> 00:14:55,540
it and I'm coming out of this

163
00:14:55,780 --> 00:15:01,620
Editor and let's kill the existing Redis process.

164
00:15:25,720 --> 00:15:47,580
Okay so let's remove this dump file,  which was available.

165
00:15:48,420 --> 00:15:48,700
Okay.

166
00:15:48,710 --> 00:15:51,800
So we see,  we do not have any of Redis  process running right now.

167
00:15:52,730 --> 00:15:58,150
And let's start Redis and now I can start Redis from any location.

168
00:15:58,150 --> 00:16:03,030
It doesn't matter that I need to be on the same location where, you know, Redis  snapshot files

169
00:16:03,030 --> 00:16:03,880
are going to be kept.

170
00:16:04,430 --> 00:16:10,620
So I can be in any location,  just to demonstrate you I'm moving to /tmp location.

171
00:16:11,300 --> 00:16:16,690
You see my current working directory  /tmp and from here we'll be starting that

172
00:16:16,700 --> 00:16:16,940
Redis.

173
00:16:21,250 --> 00:16:28,060
So the command is used Redis-server and also specify the location where configuration file

174
00:16:28,060 --> 00:16:28,640
is available

175
00:16:36,410 --> 00:16:37,640
and give & in the end

176
00:16:37,730 --> 00:16:39,870
So this  process runs  as a background process.

177
00:16:40,550 --> 00:16:42,880
Okay so that's it.

178
00:16:43,150 --> 00:16:46,120
And if I go back to the, My Home Directory

179
00:16:53,450 --> 00:16:58,220
and if I do ls-lrt,  here right now we do not see any backup directory created here.

180
00:16:58,850 --> 00:17:04,160
So let's try to load some data to Redis.

181
00:17:37,860 --> 00:17:38,140
okay.

182
00:17:38,160 --> 00:17:42,960
So  there seems to be some issue in starting Redis. So let's check the Logs

183
00:17:54,440 --> 00:17:54,740
okay.

184
00:17:54,770 --> 00:18:00,130
So in the Log Directory, we see  there is a error  which is related to,  it cannot find this directory.

185
00:18:00,140 --> 00:18:05,190
So whatever directory which you provide,  there must exist.

186
00:18:05,360 --> 00:18:07,680
Redis  is not going to create that directory.

187
00:18:07,820 --> 00:18:09,260
So let's create this directory

188
00:18:18,230 --> 00:18:18,560
okay.

189
00:18:18,570 --> 00:18:20,790
Now if I just clear the screen and show you.

190
00:18:20,790 --> 00:18:25,770
So we have created a directory,  which is called Redis_backup

191
00:18:27,920 --> 00:18:35,020
and now let's move back to /tmp.  From this location we are going to start Redis Server.

192
00:18:52,400 --> 00:18:52,890
okay.

193
00:18:52,890 --> 00:18:54,490
Now let's connect to Redis and see if

194
00:18:54,560 --> 00:18:55,940
this time we are able to connect

195
00:19:01,030 --> 00:19:01,370
okay.

196
00:19:01,380 --> 00:19:03,600
So this time we can successfully connect to Redis

197
00:19:04,250 --> 00:19:07,780
And if I do dbsize,  right now we do not have any data.

198
00:19:07,790 --> 00:19:13,590
Because if you remember,  previously we had already removed the dumb file and also we made some Configuration

199
00:19:13,590 --> 00:19:16,150
Changes.

200
00:19:16,770 --> 00:19:17,780
OK so

201
00:19:22,230 --> 00:19:23,460
our goal this time is

202
00:19:26,770 --> 00:19:32,380
that once we insert the data,  that snap  or the dumb file should be getting created inside

203
00:19:32,380 --> 00:19:33,440
Redis_backup directory.

204
00:19:33,470 --> 00:19:34,660
So right now if I see

205
00:19:37,530 --> 00:19:39,430
insider  Redis_backup directory,

206
00:19:39,440 --> 00:19:40,750
We do not have any file.

207
00:19:40,920 --> 00:19:46,660
OK because we have not performed any insertion or  there is basically no keys have changed and in the

208
00:19:46,690 --> 00:19:47,610
Configuration File

209
00:19:47,620 --> 00:19:52,390
We have defined,  how many minimum number of keys should change, before  Redis performs a Snapshot.

210
00:19:52,940 --> 00:19:53,190
OK.

211
00:19:53,230 --> 00:19:56,410
So we have to insert some data

212
00:20:02,900 --> 00:20:06,410
so I'll be inserting data using,  Redis cli pipe method

213
00:20:20,110 --> 00:20:20,380
OK.

214
00:20:20,390 --> 00:20:23,070
So it has inserted around 200.

215
00:20:23,390 --> 00:20:28,700
Basically it has made key changes, 249 key changes, and now if I go back to

216
00:20:31,860 --> 00:20:38,940
Redis_backup  directory,  we can see there is a dumb file is created

217
00:20:46,070 --> 00:20:54,090
and now regardless of the position which we are in,  let's say we move on to, let's say we go back to,

218
00:20:54,090 --> 00:21:00,570
/tmp  directory and let's kill the existing Redis process and we will restart Redis.

219
00:21:15,960 --> 00:21:18,460
so right now,  we do not have Redis process running

220
00:21:24,000 --> 00:21:25,740
and I'm going to use this command.

221
00:21:28,530 --> 00:21:28,800
OK.

222
00:21:28,820 --> 00:21:34,520
So my current working directory is  /tmp and I'm going to start Redis from this location but

223
00:21:34,520 --> 00:21:42,740
you will notice unlike the, you know, the way we started previously, when we started previously Redis

224
00:21:42,740 --> 00:21:49,910
from a different location,  then the Redis.dump file present in, we were not able to restore any

225
00:21:49,910 --> 00:21:55,540
data But this time we have specified in Redis.conf directory  that all the backup is going to be

226
00:21:55,540 --> 00:22:01,790
stored in to /home/redisadmin/redis_backup directory.   So it knows

227
00:22:01,790 --> 00:22:07,160
the location and it is going to pick or  scan  for the dump file  from that location and then it is going to

228
00:22:07,160 --> 00:22:07,640
restore.

229
00:22:08,480 --> 00:22:15,820
So let's run this,  to start Redis server and let's connect to Redis  server.

230
00:22:19,330 --> 00:22:19,630
Okay.

231
00:22:19,650 --> 00:22:24,930
Now if I run dbsize,  you can see I still have 247 keys available

232
00:22:30,320 --> 00:22:37,390
so basically whatever data,  whatever snapshot data was available, it has been successfully restored. Okay

233
00:22:37,440 --> 00:22:43,020
so that's about Redis RDB Approach of Snapshotting

234
00:22:43,260 --> 00:22:47,400
And Restoring.  In next session we are going to learn about AOF
