Skip to content

Commit a7943c1

Browse files
committed
Added --note option for backup command
1 parent da283d3 commit a7943c1

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

src/backup.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
750750
*/
751751
int
752752
do_backup(time_t start_time, bool no_validate,
753-
pgSetBackupParams *set_backup_params, bool no_sync)
753+
pgSetBackupParams *set_backup_params, bool no_sync, char *note)
754754
{
755755
PGconn *backup_conn = NULL;
756756
PGNodeInfo nodeInfo;
@@ -766,6 +766,9 @@ do_backup(time_t start_time, bool no_validate,
766766
/* Update backup status and other metainfo. */
767767
current.status = BACKUP_STATUS_RUNNING;
768768
current.start_time = start_time;
769+
770+
current.note = note;
771+
769772
StrNCpy(current.program_version, PROGRAM_VERSION,
770773
sizeof(current.program_version));
771774

src/catalog.c

+7
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,10 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
15241524
/* print external directories list */
15251525
if (backup->external_dir_str)
15261526
fio_fprintf(out, "external-dirs = '%s'\n", backup->external_dir_str);
1527+
1528+
if (backup->note)
1529+
fio_fprintf(out, "note = %s\n", backup->note);
1530+
15271531
}
15281532

15291533
/*
@@ -1761,6 +1765,7 @@ readBackupControlFile(const char *path)
17611765
{'b', 0, "from-replica", &backup->from_replica, SOURCE_FILE_STRICT},
17621766
{'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT},
17631767
{'s', 0, "external-dirs", &backup->external_dir_str, SOURCE_FILE_STRICT},
1768+
{'s', 0, "note", &backup->note, SOURCE_FILE_STRICT},
17641769
{0}
17651770
};
17661771

@@ -2027,6 +2032,8 @@ pgBackupInit(pgBackup *backup)
20272032
backup->external_dir_str = NULL;
20282033
backup->root_dir = NULL;
20292034
backup->files = NULL;
2035+
backup->note = NULL;
2036+
20302037
}
20312038

20322039
/* free pgBackup object */

src/pg_probackup.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool temp_slot = false;
7878
bool backup_logs = false;
7979
bool smooth_checkpoint;
8080
char *remote_agent;
81-
81+
static char *backup_note = NULL;
8282
/* restore options */
8383
static char *target_time = NULL;
8484
static char *target_xid = NULL;
@@ -177,6 +177,7 @@ static ConfigOption cmd_options[] =
177177
{ 'b', 183, "delete-expired", &delete_expired, SOURCE_CMD_STRICT },
178178
{ 'b', 184, "merge-expired", &merge_expired, SOURCE_CMD_STRICT },
179179
{ 'b', 185, "dry-run", &dry_run, SOURCE_CMD_STRICT },
180+
{ 's', 238, "note", &backup_note, SOURCE_CMD_STRICT },
180181
/* restore options */
181182
{ 's', 136, "recovery-target-time", &target_time, SOURCE_CMD_STRICT },
182183
{ 's', 137, "recovery-target-xid", &target_xid, SOURCE_CMD_STRICT },
@@ -769,7 +770,7 @@ main(int argc, char *argv[])
769770
elog(ERROR, "required parameter not specified: BACKUP_MODE "
770771
"(-b, --backup-mode)");
771772

772-
return do_backup(start_time, no_validate, set_backup_params, no_sync);
773+
return do_backup(start_time, no_validate, set_backup_params, no_sync, backup_note);
773774
}
774775
case RESTORE_CMD:
775776
return do_restore_or_validate(current.backup_id,

src/pg_probackup.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ struct pgBackup
387387
backup_path/instance_name/backup_id */
388388
parray *files; /* list of files belonging to this backup
389389
* must be populated explicitly */
390+
char *note;
391+
390392
};
391393

392394
/* Recovery target for restore and validate subcommands */
@@ -642,7 +644,7 @@ extern const char *pgdata_exclude_dir[];
642644

643645
/* in backup.c */
644646
extern int do_backup(time_t start_time, bool no_validate,
645-
pgSetBackupParams *set_backup_params, bool no_sync);
647+
pgSetBackupParams *set_backup_params, bool no_sync, char *note);
646648
extern void do_checkdb(bool need_amcheck, ConnectionOptions conn_opt,
647649
char *pgdata);
648650
extern BackupMode parse_backup_mode(const char *value);

src/show.c

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ print_backup_json_object(PQExpBuffer buf, pgBackup *backup)
416416
json_add_value(buf, "status", status2str(backup->status), json_level,
417417
true);
418418

419+
if (backup->note){
420+
json_add_value(buf, "note", backup->note,
421+
json_level, true);
422+
423+
}
419424
json_add(buf, JT_END_OBJECT, &json_level);
420425
}
421426

0 commit comments

Comments
 (0)