@@ -23,7 +23,7 @@ static pgBackup* get_closest_backup(timelineInfo *tlinfo);
23
23
static pgBackup * get_oldest_backup (timelineInfo * tlinfo );
24
24
static const char * backupModes [] = {"" , "PAGE" , "PTRACK" , "DELTA" , "FULL" };
25
25
static pgBackup * readBackupControlFile (const char * path );
26
- static void create_backup_dir (pgBackup * backup , const char * backup_instance_path );
26
+ static int create_backup_dir (pgBackup * backup , const char * backup_instance_path );
27
27
28
28
static bool backup_lock_exit_hook_registered = false;
29
29
static parray * locks = NULL ;
@@ -976,6 +976,7 @@ catalog_get_backup_list(InstanceState *instanceState, time_t requested_backup_id
976
976
}
977
977
else if (strcmp (base36enc (backup -> start_time ), data_ent -> d_name ) != 0 )
978
978
{
979
+ /* TODO there is no such guarantees */
979
980
elog (WARNING , "backup ID in control file \"%s\" doesn't match name of the backup folder \"%s\"" ,
980
981
base36enc (backup -> start_time ), backup_conf_path );
981
982
}
@@ -1421,21 +1422,33 @@ get_multi_timeline_parent(parray *backup_list, parray *tli_list,
1421
1422
return NULL ;
1422
1423
}
1423
1424
1424
- /* Create backup directory in $BACKUP_PATH
1425
- * Note, that backup_id attribute is updated,
1426
- * so it is possible to get diffrent values in
1425
+ /*
1426
+ * Create backup directory in $BACKUP_PATH
1427
+ * (with proposed backup->backup_id)
1428
+ * and initialize this directory.
1429
+ * If creation of directory fails, then
1430
+ * backup_id will be cleared (set to INVALID_BACKUP_ID).
1431
+ * It is possible to get diffrent values in
1427
1432
* pgBackup.start_time and pgBackup.backup_id.
1428
1433
* It may be ok or maybe not, so it's up to the caller
1429
1434
* to fix it or let it be.
1430
1435
*/
1431
1436
void
1432
- pgBackupCreateDir (pgBackup * backup , InstanceState * instanceState , time_t start_time )
1437
+ pgBackupInitDir (pgBackup * backup , const char * backup_instance_path )
1433
1438
{
1434
- int i ;
1435
- parray * subdirs = parray_new ();
1436
- parray * backups ;
1437
- pgBackup * target_backup ;
1439
+ int i ;
1440
+ char temp [MAXPGPATH ];
1441
+ parray * subdirs ;
1438
1442
1443
+ /* Try to create backup directory at first */
1444
+ if (create_backup_dir (backup , backup_instance_path ) != 0 )
1445
+ {
1446
+ /* Clear backup_id as indication of error */
1447
+ backup -> backup_id = INVALID_BACKUP_ID ;
1448
+ return ;
1449
+ }
1450
+
1451
+ subdirs = parray_new ();
1439
1452
parray_append (subdirs , pg_strdup (DATABASE_DIR ));
1440
1453
1441
1454
/* Add external dirs containers */
@@ -1447,38 +1460,13 @@ pgBackupCreateDir(pgBackup *backup, InstanceState *instanceState, time_t start_t
1447
1460
false);
1448
1461
for (i = 0 ; i < parray_num (external_list ); i ++ )
1449
1462
{
1450
- char temp [MAXPGPATH ];
1451
1463
/* Numeration of externaldirs starts with 1 */
1452
1464
makeExternalDirPathByNum (temp , EXTERNAL_DIR , i + 1 );
1453
1465
parray_append (subdirs , pg_strdup (temp ));
1454
1466
}
1455
1467
free_dir_list (external_list );
1456
1468
}
1457
1469
1458
- /* Get list of all backups*/
1459
- backups = catalog_get_backup_list (instanceState , INVALID_BACKUP_ID );
1460
- if (parray_num (backups ) > 0 )
1461
- {
1462
- target_backup = (pgBackup * ) parray_get (backups , 0 );
1463
- if (start_time > target_backup -> backup_id )
1464
- {
1465
- backup -> backup_id = start_time ;
1466
- create_backup_dir (backup , instanceState -> instance_backup_subdir_path );
1467
- }
1468
- else
1469
- {
1470
- elog (ERROR , "Cannot create directory for older backup" );
1471
- }
1472
- }
1473
- else
1474
- {
1475
- backup -> backup_id = start_time ;
1476
- create_backup_dir (backup , instanceState -> instance_backup_subdir_path );
1477
- }
1478
-
1479
- if (backup -> backup_id == 0 )
1480
- elog (ERROR , "Cannot create backup directory: %s" , strerror (errno ));
1481
-
1482
1470
backup -> database_dir = pgut_malloc (MAXPGPATH );
1483
1471
join_path_components (backup -> database_dir , backup -> root_dir , DATABASE_DIR );
1484
1472
@@ -1488,10 +1476,8 @@ pgBackupCreateDir(pgBackup *backup, InstanceState *instanceState, time_t start_t
1488
1476
/* create directories for actual backup files */
1489
1477
for (i = 0 ; i < parray_num (subdirs ); i ++ )
1490
1478
{
1491
- char path [MAXPGPATH ];
1492
-
1493
- join_path_components (path , backup -> root_dir , parray_get (subdirs , i ));
1494
- fio_mkdir (FIO_BACKUP_HOST , path , DIR_PERMISSION , false);
1479
+ join_path_components (temp , backup -> root_dir , parray_get (subdirs , i ));
1480
+ fio_mkdir (FIO_BACKUP_HOST , temp , DIR_PERMISSION , false);
1495
1481
}
1496
1482
1497
1483
free_dir_list (subdirs );
@@ -1500,33 +1486,26 @@ pgBackupCreateDir(pgBackup *backup, InstanceState *instanceState, time_t start_t
1500
1486
/*
1501
1487
* Create root directory for backup,
1502
1488
* update pgBackup.root_dir if directory creation was a success
1489
+ * Return values (same as dir_create_dir()):
1490
+ * 0 - ok
1491
+ * -1 - error (warning message already emitted)
1503
1492
*/
1504
- void
1493
+ int
1505
1494
create_backup_dir (pgBackup * backup , const char * backup_instance_path )
1506
1495
{
1507
- int attempts = 10 ;
1496
+ int rc ;
1497
+ char path [MAXPGPATH ];
1508
1498
1509
- while (attempts -- )
1510
- {
1511
- int rc ;
1512
- char path [MAXPGPATH ];
1513
-
1514
- join_path_components (path , backup_instance_path , base36enc (backup -> backup_id ));
1499
+ join_path_components (path , backup_instance_path , base36enc (backup -> backup_id ));
1515
1500
1516
- rc = fio_mkdir (FIO_BACKUP_HOST , path , DIR_PERMISSION , true);
1517
-
1518
- if (rc == 0 )
1519
- {
1520
- backup -> root_dir = pgut_strdup (path );
1521
- return ;
1522
- }
1523
- else
1524
- {
1525
- elog (WARNING , "Cannot create directory \"%s\": %s" , path , strerror (errno ));
1526
- sleep (1 );
1527
- }
1528
- }
1501
+ /* TODO: add wrapper for remote mode */
1502
+ rc = fio_mkdir (FIO_BACKUP_HOST , path , DIR_PERMISSION , true);
1529
1503
1504
+ if (rc == 0 )
1505
+ backup -> root_dir = pgut_strdup (path );
1506
+ else
1507
+ elog (WARNING , "Cannot create directory \"%s\": %s" , path , strerror (errno ));
1508
+ return rc ;
1530
1509
}
1531
1510
1532
1511
/*
0 commit comments