@@ -126,9 +126,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
126126/* Initialize size summary */
127127current .data_bytes = 0 ;
128128
129- /* do some checks on the node */
130- sanityChecks ();
131-
132129/*
133130 * Obtain current timeline by scanning control file, theh LSN
134131 * obtained at output of pg_start_backup or pg_stop_backup does
@@ -152,11 +149,9 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
152149if (current .backup_mode == BACKUP_MODE_DIFF_PAGE ||
153150current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
154151{
155- pgBackup * prev_backup ;
156-
157152prev_backup = catalog_get_last_data_backup (backup_list ,current .tli );
158153if (prev_backup == NULL )
159- elog (ERROR ,"Timeline has changed since last full backup."
154+ elog (ERROR ,"Timeline has changed since last full backup. "
160155"Create new full backup before an incremental one." );
161156}
162157
@@ -233,8 +228,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
233228if (current .backup_mode == BACKUP_MODE_DIFF_PAGE ||
234229current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
235230{
236- /* find last completed database backup */
237- prev_backup = catalog_get_last_data_backup (backup_list ,current .tli );
231+ Assert (prev_backup );
238232pgBackupGetPath (prev_backup ,prev_file_txt ,lengthof (prev_file_txt ),
239233DATABASE_FILE_LIST );
240234prev_files = dir_read_file_list (pgdata ,prev_file_txt );
@@ -1337,21 +1331,21 @@ backup_files(void *arg)
13371331static void
13381332add_files (parray * files ,const char * root ,bool add_root ,bool is_pgdata )
13391333{
1340- parray * list_file ;
1341- int i ;
1334+ parray * list_file ;
1335+ size_t i ;
13421336
13431337list_file = parray_new ();
13441338
13451339/* list files with the logical path. omit $PGDATA */
13461340dir_list_file (list_file ,root , true, true,add_root );
13471341
13481342/* mark files that are possible datafile as 'datafile' */
1349- for (i = 0 ;i < ( int ) parray_num (list_file );i ++ )
1343+ for (i = 0 ;i < parray_num (list_file );i ++ )
13501344{
1351- pgFile * file = (pgFile * )parray_get (list_file ,i );
1352- char * relative ;
1353- char * fname ;
1354- int path_len ;
1345+ pgFile * file = (pgFile * )parray_get (list_file ,i );
1346+ char * relative ;
1347+ char * fname ;
1348+ size_t path_len ;
13551349
13561350/* data file must be a regular file */
13571351if (!S_ISREG (file -> mode ))
@@ -1367,6 +1361,10 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
13671361
13681362/* Get file name from path */
13691363fname = last_dir_separator (relative );
1364+ if (fname == NULL )
1365+ fname = relative ;
1366+ else
1367+ fname ++ ;
13701368
13711369/* Remove temp tables from the list */
13721370if (fname [0 ]== 't' && isdigit (fname [1 ]))
@@ -1379,32 +1377,41 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
13791377
13801378path_len = strlen (file -> path );
13811379/* Get link ptrack file to relations files */
1382- if (path_len > 6 && strncmp (file -> path + (path_len - 6 ),"ptrack" ,6 )== 0 )
1380+ if (path_len > 6 &&
1381+ strncmp (file -> path + (path_len - 6 ),"ptrack" ,6 )== 0 )
13831382{
1384- pgFile * search_file ;
1385- pgFile * * pre_search_file ;
1386- int segno = 0 ;
1387- while (true) {
1388- pgFile tmp_file ;
1383+ pgFile * search_file ;
1384+ pgFile * * pre_search_file ;
1385+ int segno = 0 ;
1386+
1387+ while (true)
1388+ {
1389+ pgFile tmp_file ;
1390+
13891391tmp_file .path = pg_strdup (file -> path );
13901392
13911393/* Segno fits into 6 digits since it is not more than 4000 */
13921394if (segno > 0 )
1393- sprintf (tmp_file .path + path_len - 7 ,".%d" ,segno );
1395+ sprintf (tmp_file .path + path_len - 7 ,".%d" ,segno );
13941396else
1395- tmp_file .path [path_len - 7 ]= '\0' ;
1397+ tmp_file .path [path_len - 7 ]= '\0' ;
13961398
1397- pre_search_file = (pgFile * * )parray_bsearch (list_file ,& tmp_file ,pgFileComparePath );
1399+ pre_search_file = (pgFile * * )parray_bsearch (list_file ,
1400+ & tmp_file ,
1401+ pgFileComparePath );
13981402
13991403if (pre_search_file != NULL )
14001404{
14011405search_file = * pre_search_file ;
14021406search_file -> ptrack_path = pg_strdup (file -> path );
14031407search_file -> segno = segno ;
1404- }else {
1408+ }
1409+ else
1410+ {
14051411pg_free (tmp_file .path );
14061412break ;
14071413}
1414+
14081415pg_free (tmp_file .path );
14091416segno ++ ;
14101417}
@@ -1413,63 +1420,24 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
14131420pgFileFree (file );
14141421parray_remove (list_file ,i );
14151422i -- ;
1416- continue ;
14171423}
1418-
14191424/* compress map file it is not data file */
1420- if (path_len > 4 && strncmp (file -> path + (path_len - 4 ),".cfm" ,4 )== 0 )
1421- continue ;
1422-
1423- /* name of data file start with digit */
1424- if (fname == NULL )
1425- fname = relative ;
1426- else
1427- fname ++ ;
1428- if (!isdigit (fname [0 ]))
1429- continue ;
1430-
1431- file -> is_datafile = true;
1425+ else if (path_len > 4 &&
1426+ strncmp (file -> path + (path_len - 4 ),".cfm" ,4 )== 0 )
14321427{
1433- int find_dot ;
1434- int check_digit ;
1435- char * text_segno ;
1436- for (find_dot = path_len - 1 ;file -> path [find_dot ]!= '.' && find_dot >=0 ;find_dot -- );
1437- if (find_dot <=0 )
1438- continue ;
1439-
1440- text_segno = file -> path + find_dot + 1 ;
1441- for (check_digit = 0 ;text_segno [check_digit ]!= '\0' ;check_digit ++ )
1442- if (!isdigit (text_segno [check_digit ]))
1443- {
1444- check_digit = -1 ;
1445- break ;
1446- }
1447-
1448- if (check_digit == -1 )
1449- continue ;
1450-
1451- file -> segno = (int )strtol (text_segno ,NULL ,10 );
1452- }
1453- }
1428+ pgFile * * pre_search_file ;
1429+ pgFile tmp_file ;
14541430
1455- /* mark cfs relations as not data */
1456- for (i = 0 ;i < (int )parray_num (list_file );i ++ )
1457- {
1458- pgFile * file = (pgFile * )parray_get (list_file ,i );
1459- int path_len = (int )strlen (file -> path );
1460-
1461- if (path_len > 4 && strncmp (file -> path + (path_len - 4 ),".cfm" ,4 )== 0 )
1462- {
1463- pgFile * * pre_search_file ;
1464- pgFile tmp_file ;
14651431tmp_file .path = pg_strdup (file -> path );
1466- tmp_file .path [path_len - 4 ]= '\0' ;
1432+ tmp_file .path [path_len - 4 ]= '\0' ;
14671433pre_search_file = (pgFile * * )parray_bsearch (list_file ,
1468- & tmp_file ,pgFileComparePath );
1434+ & tmp_file ,
1435+ pgFileComparePath );
14691436if (pre_search_file != NULL )
14701437{
1471- FileMap * map ;
1472- int md = open (file -> path ,O_RDWR |PG_BINARY ,0 );
1438+ FileMap * map ;
1439+ int md = open (file -> path ,O_RDWR |PG_BINARY ,0 );
1440+
14731441if (md < 0 )
14741442elog (ERROR ,"add_files(). cannot open cfm file '%s'" ,file -> path );
14751443
@@ -1485,16 +1453,51 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
14851453(* pre_search_file )-> is_datafile = false;
14861454
14871455if (cfs_munmap (map )< 0 )
1488- elog (LOG ,"add_files(). CFS failed to unmap file %s: %m" ,file -> path );
1456+ elog (LOG ,"add_files(). CFS failed to unmap file %s: %m" ,
1457+ file -> path );
14891458if (close (md )< 0 )
1490- elog (LOG ,"add_files(). CFS failed to close file %s: %m" ,file -> path );
1459+ elog (LOG ,"add_files(). CFS failed to close file %s: %m" ,
1460+ file -> path );
14911461}
14921462else
1493- elog (ERROR ,"corresponding segment '%s' is not found" ,tmp_file .path );
1463+ elog (ERROR ,"corresponding segment '%s' is not found" ,
1464+ tmp_file .path );
14941465
14951466pg_free (tmp_file .path );
14961467}
1468+ /* name of data file start with digit */
1469+ else if (isdigit (fname [0 ]))
1470+ {
1471+ int find_dot ;
1472+ int check_digit ;
1473+ char * text_segno ;
1474+
1475+ file -> is_datafile = true;
1476+
1477+ /*
1478+ * Find segment number.
1479+ */
1480+
1481+ for (find_dot = (int )path_len - 1 ;
1482+ file -> path [find_dot ]!= '.' && find_dot >=0 ;
1483+ find_dot -- );
1484+ /* There is not segment number */
1485+ if (find_dot <=0 )
1486+ continue ;
1487+
1488+ text_segno = file -> path + find_dot + 1 ;
1489+ for (check_digit = 0 ;text_segno [check_digit ]!= '\0' ;check_digit ++ )
1490+ if (!isdigit (text_segno [check_digit ]))
1491+ {
1492+ check_digit = -1 ;
1493+ break ;
1494+ }
1495+
1496+ if (check_digit != -1 )
1497+ file -> segno = (int )strtol (text_segno ,NULL ,10 );
1498+ }
14971499}
1500+
14981501parray_concat (files ,list_file );
14991502}
15001503