27
27
static int server_version = 0 ;
28
28
29
29
static bool in_backup = false; /* TODO: more robust logic */
30
- /* List of commands to execute at error processing for snapshot */
31
- static parray * cleanup_list ;
32
30
33
31
/*
34
32
* Backup routines
@@ -44,10 +42,7 @@ static bool pg_is_standby(void);
44
42
static void get_lsn (PGresult * res , XLogRecPtr * lsn );
45
43
static void get_xid (PGresult * res , uint32 * xid );
46
44
47
- static bool dirExists (const char * path );
48
-
49
45
static void add_files (parray * files , const char * root , bool add_root , bool is_pgdata );
50
- static int strCompare (const void * str1 , const void * str2 );
51
46
static void create_file_list (parray * files ,
52
47
const char * root ,
53
48
const char * subdir ,
@@ -174,209 +169,19 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
174
169
175
170
/* initialize backup list from non-snapshot */
176
171
files = parray_new ();
177
- join_path_components (path , backup_path , SNAPSHOT_SCRIPT_FILE );
178
-
179
- /*
180
- * Check the existence of the snapshot-script.
181
- * backup use snapshot when snapshot-script exists.
182
- */
183
- if (fileExists (path ))
184
- {
185
- parray * tblspc_list ; /* list of name of TABLESPACE backup from snapshot */
186
- parray * tblspcmp_list ; /* list of mounted directory of TABLESPACE in snapshot volume */
187
- PGresult * tblspc_res ; /* contain spcname and oid in TABLESPACE */
188
-
189
- tblspc_list = parray_new ();
190
- tblspcmp_list = parray_new ();
191
- cleanup_list = parray_new ();
192
-
193
- /*
194
- * append 'pg_tblspc' to list of directory excluded from copy.
195
- * because DB cluster and TABLESPACE are copied separately.
196
- */
197
- for (i = 0 ; pgdata_exclude [i ]; i ++ ); /* find first empty slot */
198
- pgdata_exclude [i ] = PG_TBLSPC_DIR ;
199
-
200
- /*
201
- * when DB cluster is not contained in the backup from the snapshot,
202
- * DB cluster is added to the backup file list from non-snapshot.
203
- */
204
- parray_qsort (tblspc_list , strCompare );
205
- if (parray_bsearch (tblspc_list , "PG-DATA" , strCompare ) == NULL )
206
- add_files (files , pgdata , false, true);
207
- else
208
- /* remove the detected tablespace("PG-DATA") from tblspc_list */
209
- parray_rm (tblspc_list , "PG-DATA" , strCompare );
210
-
211
- /*
212
- * select the TABLESPACE backup from non-snapshot,
213
- * and append TABLESPACE to the list backup from non-snapshot.
214
- * TABLESPACE name and oid is obtained by inquiring of the database.
215
- */
216
-
217
- reconnect ();
218
- tblspc_res = execute ("SELECT spcname, oid FROM pg_tablespace WHERE "
219
- "spcname NOT IN ('pg_default', 'pg_global') ORDER BY spcname ASC" , 0 , NULL );
220
- disconnect ();
221
- for (i = 0 ; i < PQntuples (tblspc_res ); i ++ )
222
- {
223
- char * name = PQgetvalue (tblspc_res , i , 0 );
224
- char * oid = PQgetvalue (tblspc_res , i , 1 );
225
-
226
- /* when not found, append it to the backup list from non-snapshot */
227
- if (parray_bsearch (tblspc_list , name , strCompare ) == NULL )
228
- {
229
- char dir [MAXPGPATH ];
230
- join_path_components (dir , pgdata , PG_TBLSPC_DIR );
231
- join_path_components (dir , dir , oid );
232
- add_files (files , dir , true, false);
233
- }
234
- else
235
- /* remove the detected tablespace from tblspc_list */
236
- parray_rm (tblspc_list , name , strCompare );
237
- }
238
-
239
- /*
240
- * tblspc_list is not empty,
241
- * so snapshot-script output the tablespace name that not exist.
242
- */
243
- if (parray_num (tblspc_list ) > 0 )
244
- elog (ERROR_SYSTEM , "snapshot-script output the name of tablespace that not exist" );
245
-
246
- /* clear array */
247
- parray_walk (tblspc_list , free );
248
- parray_free (tblspc_list );
249
-
250
- /* backup files from non-snapshot */
251
- pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
252
- backup_files (pgdata , path , files , prev_files , lsn , NULL );
253
-
254
- /* notify end of backup */
255
- pg_stop_backup (& current );
256
-
257
- /* create file list of non-snapshot objects */
258
- create_file_list (files , pgdata , DATABASE_FILE_LIST , NULL , false);
259
172
260
- /* backup files from snapshot volume */
261
- for (i = 0 ; i < parray_num (tblspcmp_list ); i ++ )
262
- {
263
- char * spcname ;
264
- char * mp = NULL ;
265
- char * item = (char * ) parray_get (tblspcmp_list , i );
266
- parray * snapshot_files = parray_new ();
267
-
268
- /*
269
- * obtain the TABLESPACE name and the directory where it is stored.
270
- * Note: strtok() replace the delimiter to '\0'. but no problem because
271
- * it doesn't use former value
272
- */
273
- if ((spcname = strtok (item , "=" )) == NULL || (mp = strtok (NULL , "\0" )) == NULL )
274
- elog (ERROR_SYSTEM , "snapshot-script output illegal format: %s" , item );
275
-
276
- elog (LOG , "========================================" );
277
- elog (LOG , "backup files from snapshot: \"%s\"" , spcname );
278
-
279
- /* tablespace storage directory not exist */
280
- if (!dirExists (mp ))
281
- elog (ERROR_SYSTEM , "tablespace storage directory doesn't exist: %s" , mp );
282
-
283
- /*
284
- * create the previous backup file list to take differential backup
285
- * from the snapshot volume.
286
- */
287
- if (prev_files != NULL )
288
- prev_files = dir_read_file_list (mp , prev_file_txt );
289
-
290
- /* when DB cluster is backup from snapshot, it backup from the snapshot */
291
- if (strcmp (spcname , "PG-DATA" ) == 0 )
292
- {
293
- /* append DB cluster to backup file list */
294
- add_files (snapshot_files , mp , false, true);
295
- /* backup files of DB cluster from snapshot volume */
296
- backup_files (mp , path , snapshot_files , prev_files , lsn , NULL );
297
- /* create file list of snapshot objects (DB cluster) */
298
- create_file_list (snapshot_files , mp , DATABASE_FILE_LIST ,
299
- NULL , true);
300
- /* remove the detected tablespace("PG-DATA") from tblspcmp_list */
301
- parray_rm (tblspcmp_list , "PG-DATA" , strCompare );
302
- i -- ;
303
- }
304
- /* backup TABLESPACE from snapshot volume */
305
- else
306
- {
307
- int j ;
308
-
309
- /*
310
- * obtain the oid from TABLESPACE information acquired by inquiring of database.
311
- * and do backup files of TABLESPACE from snapshot volume.
312
- */
313
- for (j = 0 ; j < PQntuples (tblspc_res ); j ++ )
314
- {
315
- char dest [MAXPGPATH ];
316
- char prefix [MAXPGPATH ];
317
- char * name = PQgetvalue (tblspc_res , j , 0 );
318
- char * oid = PQgetvalue (tblspc_res , j , 1 );
319
-
320
- if (strcmp (spcname , name ) == 0 )
321
- {
322
- /* append TABLESPACE to backup file list */
323
- add_files (snapshot_files , mp , true, false);
324
-
325
- /* backup files of TABLESPACE from snapshot volume */
326
- join_path_components (prefix , PG_TBLSPC_DIR , oid );
327
- join_path_components (dest , path , prefix );
328
- backup_files (mp , dest , snapshot_files , prev_files , lsn , prefix );
329
-
330
- /* create file list of snapshot objects (TABLESPACE) */
331
- create_file_list (snapshot_files , mp , DATABASE_FILE_LIST ,
332
- prefix , true);
333
- /*
334
- * Remove the detected tablespace("PG-DATA") from
335
- * tblspcmp_list.
336
- */
337
- parray_rm (tblspcmp_list , spcname , strCompare );
338
- i -- ;
339
- break ;
340
- }
341
- }
342
- }
343
- parray_concat (files , snapshot_files );
344
- }
345
-
346
- /*
347
- * tblspcmp_list is not empty,
348
- * so snapshot-script output the tablespace name that not exist.
349
- */
350
- if (parray_num (tblspcmp_list ) > 0 )
351
- elog (ERROR_SYSTEM , "snapshot-script output the name of tablespace that not exist" );
352
-
353
- /* clear array */
354
- parray_walk (tblspcmp_list , free );
355
- parray_free (tblspcmp_list );
356
-
357
-
358
- /* don't use 'parray_walk'. element of parray not allocate memory by malloc */
359
- parray_free (cleanup_list );
360
- PQclear (tblspc_res );
361
- }
362
- /* when snapshot-script not exist, DB cluster and TABLESPACE are backup
363
- * at same time.
364
- */
365
- else
366
- {
367
- /* list files with the logical path. omit $PGDATA */
368
- add_files (files , pgdata , false, true);
173
+ /* list files with the logical path. omit $PGDATA */
174
+ add_files (files , pgdata , false, true);
369
175
370
- /* backup files */
371
- pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
372
- backup_files (pgdata , path , files , prev_files , lsn , NULL );
176
+ /* backup files */
177
+ pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
178
+ backup_files (pgdata , path , files , prev_files , lsn , NULL );
373
179
374
- /* notify end of backup */
375
- pg_stop_backup (& current );
180
+ /* notify end of backup */
181
+ pg_stop_backup (& current );
376
182
377
- /* create file list */
378
- create_file_list (files , pgdata , DATABASE_FILE_LIST , NULL , false);
379
- }
183
+ /* create file list */
184
+ create_file_list (files , pgdata , DATABASE_FILE_LIST , NULL , false);
380
185
381
186
/* print summary of size of backup mode files */
382
187
for (i = 0 ; i < parray_num (files ); i ++ )
@@ -750,22 +555,6 @@ fileExists(const char *path)
750
555
return true;
751
556
}
752
557
753
- /*
754
- * Return true if the path is a existing directory.
755
- */
756
- static bool
757
- dirExists (const char * path )
758
- {
759
- struct stat buf ;
760
-
761
- if (stat (path , & buf ) == -1 && errno == ENOENT )
762
- return false;
763
- else if (S_ISREG (buf .st_mode ))
764
- return false;
765
- else
766
- return true;
767
- }
768
-
769
558
/*
770
559
* Notify end of backup to server when "backup_label" is in the root directory
771
560
* of the DB cluster.
@@ -1011,15 +800,6 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1011
800
parray_concat (files , list_file );
1012
801
}
1013
802
1014
- /*
1015
- * Comparison function for parray_bsearch() compare the character string.
1016
- */
1017
- static int
1018
- strCompare (const void * str1 , const void * str2 )
1019
- {
1020
- return strcmp (* (char * * ) str1 , * (char * * ) str2 );
1021
- }
1022
-
1023
803
/*
1024
804
* Output the list of files to backup catalog
1025
805
*/
0 commit comments