1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-25 09:01:48 +02:00

Added --note option for backup command

This commit is contained in:
Victor Spirin 2020-03-12 14:54:03 +03:00
parent da283d3ead
commit a7943c1b46
5 changed files with 22 additions and 4 deletions

View File

@ -750,7 +750,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
*/
int
do_backup(time_t start_time, bool no_validate,
pgSetBackupParams *set_backup_params, bool no_sync)
pgSetBackupParams *set_backup_params, bool no_sync, char *note)
{
PGconn *backup_conn = NULL;
PGNodeInfo nodeInfo;
@ -766,6 +766,9 @@ do_backup(time_t start_time, bool no_validate,
/* Update backup status and other metainfo. */
current.status = BACKUP_STATUS_RUNNING;
current.start_time = start_time;
current.note = note;
StrNCpy(current.program_version, PROGRAM_VERSION,
sizeof(current.program_version));

View File

@ -1524,6 +1524,10 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
/* print external directories list */
if (backup->external_dir_str)
fio_fprintf(out, "external-dirs = '%s'\n", backup->external_dir_str);
if (backup->note)
fio_fprintf(out, "note = %s\n", backup->note);
}
/*
@ -1761,6 +1765,7 @@ readBackupControlFile(const char *path)
{'b', 0, "from-replica", &backup->from_replica, SOURCE_FILE_STRICT},
{'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT},
{'s', 0, "external-dirs", &backup->external_dir_str, SOURCE_FILE_STRICT},
{'s', 0, "note", &backup->note, SOURCE_FILE_STRICT},
{0}
};
@ -2027,6 +2032,8 @@ pgBackupInit(pgBackup *backup)
backup->external_dir_str = NULL;
backup->root_dir = NULL;
backup->files = NULL;
backup->note = NULL;
}
/* free pgBackup object */

View File

@ -78,7 +78,7 @@ bool temp_slot = false;
bool backup_logs = false;
bool smooth_checkpoint;
char *remote_agent;
static char *backup_note = NULL;
/* restore options */
static char *target_time = NULL;
static char *target_xid = NULL;
@ -177,6 +177,7 @@ static ConfigOption cmd_options[] =
{ 'b', 183, "delete-expired", &delete_expired, SOURCE_CMD_STRICT },
{ 'b', 184, "merge-expired", &merge_expired, SOURCE_CMD_STRICT },
{ 'b', 185, "dry-run", &dry_run, SOURCE_CMD_STRICT },
{ 's', 238, "note", &backup_note, SOURCE_CMD_STRICT },
/* restore options */
{ 's', 136, "recovery-target-time", &target_time, SOURCE_CMD_STRICT },
{ 's', 137, "recovery-target-xid", &target_xid, SOURCE_CMD_STRICT },
@ -769,7 +770,7 @@ main(int argc, char *argv[])
elog(ERROR, "required parameter not specified: BACKUP_MODE "
"(-b, --backup-mode)");
return do_backup(start_time, no_validate, set_backup_params, no_sync);
return do_backup(start_time, no_validate, set_backup_params, no_sync, backup_note);
}
case RESTORE_CMD:
return do_restore_or_validate(current.backup_id,

View File

@ -387,6 +387,8 @@ struct pgBackup
backup_path/instance_name/backup_id */
parray *files; /* list of files belonging to this backup
* must be populated explicitly */
char *note;
};
/* Recovery target for restore and validate subcommands */
@ -642,7 +644,7 @@ extern const char *pgdata_exclude_dir[];
/* in backup.c */
extern int do_backup(time_t start_time, bool no_validate,
pgSetBackupParams *set_backup_params, bool no_sync);
pgSetBackupParams *set_backup_params, bool no_sync, char *note);
extern void do_checkdb(bool need_amcheck, ConnectionOptions conn_opt,
char *pgdata);
extern BackupMode parse_backup_mode(const char *value);

View File

@ -416,6 +416,11 @@ print_backup_json_object(PQExpBuffer buf, pgBackup *backup)
json_add_value(buf, "status", status2str(backup->status), json_level,
true);
if (backup->note){
json_add_value(buf, "note", backup->note,
json_level, true);
}
json_add(buf, JT_END_OBJECT, &json_level);
}