@@ -38,11 +38,13 @@ func NewBackupCommand() *cobra.Command {
38
38
"ratelimit" , "" , 0 , "The rate limit of the backup task, MB/s per node" )
39
39
command .PersistentFlags ().Uint32P (
40
40
"concurrency" , "" , 4 , "The size of thread pool on each node that execute the backup task" )
41
+ command .PersistentFlags ().BoolP ("checksum" , "" , true ,
42
+ "Run checksum after backup" )
41
43
42
- command .PersistentFlags ().BoolP ("checksum " , "" , false ,
44
+ command .PersistentFlags ().BoolP ("fastchecksum " , "" , false ,
43
45
"fast checksum backup sst file by calculate all sst file" )
44
46
45
- _ = command .PersistentFlags ().MarkHidden ("checksum " )
47
+ _ = command .PersistentFlags ().MarkHidden ("fastchecksum " )
46
48
return command
47
49
}
48
50
@@ -97,7 +99,17 @@ func newFullBackupCommand() *cobra.Command {
97
99
return errors .New ("at least one thread required" )
98
100
}
99
101
100
- ranges , err := client .PreBackupAllTableRanges (backupTS )
102
+ checksum , err := command .Flags ().GetBool ("checksum" )
103
+ if err != nil {
104
+ return err
105
+ }
106
+ fastChecksum , err := command .Flags ().GetBool ("fastchecksum" )
107
+ if err != nil {
108
+ return err
109
+ }
110
+
111
+ ranges , backupSchemas , err := raw .BuildBackupRangeAndSchema (
112
+ client .GetDomain (), backer .GetTiKV (), backupTS , "" , "" )
101
113
if err != nil {
102
114
return err
103
115
}
@@ -108,38 +120,50 @@ func newFullBackupCommand() *cobra.Command {
108
120
return err
109
121
}
110
122
123
+ // Backup
111
124
ctx , cancel := context .WithCancel (defaultBacker .Context ())
112
125
defer cancel ()
113
126
// Redirect to log if there is no log file to avoid unreadable output.
114
127
updateCh := utils .StartProgress (
115
128
ctx , "Full Backup" , int64 (approximateRegions ), ! HasLogFile ())
116
-
117
129
err = client .BackupRanges (
118
130
ranges , u , backupTS , rate , concurrency , updateCh )
119
131
if err != nil {
120
132
return err
121
133
}
134
+ // Backup has finished
135
+ close (updateCh )
122
136
123
- err = client .CompleteMeta ()
124
- if err != nil {
125
- return err
137
+ // Checksum
138
+ backupSchemasConcurrency := raw .DefaultSchemaConcurrency
139
+ if backupSchemas .Len () < backupSchemasConcurrency {
140
+ backupSchemasConcurrency = backupSchemas .Len ()
126
141
}
142
+ cksctx , ckscancel := context .WithCancel (defaultBacker .Context ())
143
+ defer ckscancel ()
144
+ updateCh = utils .StartProgress (
145
+ cksctx , "Checksum" , int64 (backupSchemas .Len ()), ! HasLogFile ())
146
+ backupSchemas .SetSkipChecksum (! checksum )
147
+ backupSchemas .Start (
148
+ cksctx , backer .GetTiKV (), backupTS , uint (backupSchemasConcurrency ), updateCh )
127
149
128
- checksumSwitch , err := command . Flags (). GetBool ( "checksum" )
150
+ err = client . CompleteMeta ( backupSchemas )
129
151
if err != nil {
130
152
return err
131
153
}
132
- if checksumSwitch {
154
+
155
+ if fastChecksum {
133
156
valid , err := client .FastChecksum ()
134
157
if err != nil {
135
158
return err
136
159
}
137
-
138
160
if ! valid {
139
161
log .Error ("backup FastChecksum not passed!" )
140
162
}
141
-
142
163
}
164
+ // Checksum has finished
165
+ close (updateCh )
166
+
143
167
return client .SaveBackupMeta (u )
144
168
},
145
169
}
@@ -210,13 +234,22 @@ func newTableBackupCommand() *cobra.Command {
210
234
if concurrency == 0 {
211
235
return errors .New ("at least one thread required" )
212
236
}
237
+ checksum , err := command .Flags ().GetBool ("checksum" )
238
+ if err != nil {
239
+ return err
240
+ }
241
+ fastChecksum , err := command .Flags ().GetBool ("fastchecksum" )
242
+ if err != nil {
243
+ return err
244
+ }
213
245
214
- // TODO: include admin check in progress bar.
215
- ranges , err := client . PreBackupTableRanges ( db , table , u , backupTS )
246
+ ranges , backupSchemas , err := raw . BuildBackupRangeAndSchema (
247
+ client . GetDomain (), backer . GetTiKV (), backupTS , db , table )
216
248
if err != nil {
217
249
return err
218
250
}
219
- // the count of regions need to backup
251
+
252
+ // The number of regions need to backup
220
253
approximateRegions := 0
221
254
for _ , r := range ranges {
222
255
var regionCount int
@@ -227,28 +260,35 @@ func newTableBackupCommand() *cobra.Command {
227
260
approximateRegions += regionCount
228
261
}
229
262
263
+ // Backup
230
264
ctx , cancel := context .WithCancel (defaultBacker .Context ())
231
265
defer cancel ()
232
266
// Redirect to log if there is no log file to avoid unreadable output.
233
267
updateCh := utils .StartProgress (
234
268
ctx , "Table Backup" , int64 (approximateRegions ), ! HasLogFile ())
235
-
236
269
err = client .BackupRanges (
237
270
ranges , u , backupTS , rate , concurrency , updateCh )
238
271
if err != nil {
239
272
return err
240
273
}
274
+ // Backup has finished
275
+ close (updateCh )
241
276
242
- err = client .CompleteMeta ()
243
- if err != nil {
244
- return err
245
- }
277
+ // Checksum
278
+ cksctx , ckscancel := context .WithCancel (defaultBacker .Context ())
279
+ defer ckscancel ()
280
+ updateCh = utils .StartProgress (
281
+ cksctx , "Checksum" , int64 (backupSchemas .Len ()), ! HasLogFile ())
282
+ backupSchemas .SetSkipChecksum (! checksum )
283
+ backupSchemas .Start (
284
+ cksctx , backer .GetTiKV (), backupTS , 1 , updateCh )
246
285
247
- checksumSwitch , err := command . Flags (). GetBool ( "checksum" )
286
+ err = client . CompleteMeta ( backupSchemas )
248
287
if err != nil {
249
288
return err
250
289
}
251
- if checksumSwitch {
290
+
291
+ if fastChecksum {
252
292
valid , err := client .FastChecksum ()
253
293
if err != nil {
254
294
return err
@@ -257,6 +297,8 @@ func newTableBackupCommand() *cobra.Command {
257
297
log .Error ("backup FastChecksum not passed!" )
258
298
}
259
299
}
300
+ // Checksum has finished
301
+ close (updateCh )
260
302
261
303
return client .SaveBackupMeta (u )
262
304
},
0 commit comments