Skip to content

Commit af0e674

Browse files
committed
Add automatic detect of replica and remove same option.
1 parent f0703e5 commit af0e674

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

backup.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static void get_lsn(PGconn *conn, PGresult *res, XLogRecPtr *lsn, bool stop_back
6666
static void get_xid(PGresult *res, uint32 *xid);
6767
static void pg_ptrack_clear(void);
6868
static bool pg_ptrack_support(void);
69+
static bool pg_is_in_recovery(void);
6970
static char *pg_ptrack_get_and_clear(Oid tablespace_oid,
7071
Oid db_oid,
7172
Oid rel_oid,
@@ -115,6 +116,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
115116
pgBackup *prev_backup = NULL;
116117

117118
/* Block backup operations on a standby */
119+
from_replica = pg_is_in_recovery();
118120
if (pg_is_standby() && !from_replica)
119121
elog(ERROR, "Backup cannot run on a standby.");
120122

@@ -653,9 +655,29 @@ pg_ptrack_support(void)
653655
disconnect();
654656
return false;
655657
}
658+
PQclear(res_db);
659+
disconnect();
656660
return true;
657661
}
658662

663+
static bool
664+
pg_is_in_recovery(void)
665+
{
666+
PGresult *res_db;
667+
reconnect();
668+
res_db = execute("SELECT pg_is_in_recovery()", 0, NULL);
669+
670+
if (PQgetvalue(res_db, 0, 0)[0] == 't')
671+
{
672+
PQclear(res_db);
673+
disconnect();
674+
return true;
675+
}
676+
PQclear(res_db);
677+
disconnect();
678+
return false;
679+
}
680+
659681
static void
660682
pg_ptrack_clear(void)
661683
{

doc/pg_arman.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ absolute paths; relative paths are not allowed.
246246
**--stream**:
247247
Enable stream replication for save WAL during backup process.
248248

249-
**--from-replica**:
250-
Use non exclusive start backup for replica. Only for 9.6 and higher.
251-
252249

253250
### RESTORE OPTIONS
254251

expected/option.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Backup options:
2626
--keep-data-generations=N keep GENERATION of full data backup
2727
--keep-data-days=DAY keep enough data backup to recover to DAY days age
2828
--backup-pg-log start backup pg_log directory
29-
--from-replica use non exclusive start backup for replica
3029

3130
Restore options:
3231
--recovery-target-time time stamp up to which recovery will proceed

pg_arman.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ static pgut_option options[] =
6767
{ 'b', 10, "backup-pg-log", &backup_logs },
6868
{ 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_ENV },
6969
{ 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_ENV },
70-
{ 'b', 12, "from-replica", &from_replica },
7170
/* options with only long name (keep-xxx) */
7271
{ 'i', 1, "keep-data-generations", &keep_data_generations, SOURCE_ENV },
7372
{ 'i', 2, "keep-data-days", &keep_data_days, SOURCE_ENV },
@@ -247,7 +246,6 @@ pgut_help(bool details)
247246
printf(_(" --keep-data-generations=N keep GENERATION of full data backup\n"));
248247
printf(_(" --keep-data-days=DAY keep enough data backup to recover to DAY days age\n"));
249248
printf(_(" --backup-pg-log start backup pg_log directory\n"));
250-
printf(_(" --from-replica use non exclusive start backup for replica\n"));
251249
printf(_("\nRestore options:\n"));
252250
printf(_(" --recovery-target-time time stamp up to which recovery will proceed\n"));
253251
printf(_(" --recovery-target-xid transaction ID up to which recovery will proceed\n"));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy