mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-01-05 13:20:31 +02:00
Support pg_rman for PG_VERSION_NUM >= 9.3
In Postgres 9.3, XLogRecPtr has been changed to a unique uint64, making the old structure based on two uint32 obsolete. Note that this makes pg_rman incompatible with PG <= 9.2.
This commit is contained in:
parent
44e8da5f2c
commit
1bc0f9baff
33
backup.c
33
backup.c
@ -206,7 +206,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
|
||||
*/
|
||||
lsn = &prev_backup->start_lsn;
|
||||
elog(LOG, _("backup only the page that there was of the update from LSN(%X/%08X).\n"),
|
||||
lsn->xlogid, lsn->xrecoff);
|
||||
(uint32) (*lsn >> 32), (uint32) *lsn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
|
||||
* and append TABLESPACE to the list backup from non-snapshot.
|
||||
* TABLESPACE name and oid is obtained by inquiring of the database.
|
||||
*/
|
||||
|
||||
|
||||
reconnect();
|
||||
tblspc_res = execute("SELECT spcname, oid FROM pg_tablespace WHERE "
|
||||
"spcname NOT IN ('pg_default', 'pg_global') ORDER BY spcname ASC", 0, NULL);
|
||||
@ -446,7 +446,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
|
||||
/* create file list */
|
||||
create_file_list(files, pgdata, NULL, false);
|
||||
}
|
||||
|
||||
|
||||
/* print summary of size of backup mode files */
|
||||
for (i = 0; i < parray_num(files); i++)
|
||||
{
|
||||
@ -518,7 +518,7 @@ do_backup_arclog(parray *backup_list)
|
||||
current.read_arclog_bytes = 0;
|
||||
|
||||
/* switch xlog if database is not backed up */
|
||||
if (current.stop_lsn.xrecoff == 0)
|
||||
if ((uint32) current.stop_lsn == 0)
|
||||
pg_switch_xlog(¤t);
|
||||
|
||||
/*
|
||||
@ -771,10 +771,8 @@ do_backup(pgBackupOption bkupopt)
|
||||
/* initialize backup result */
|
||||
current.status = BACKUP_STATUS_RUNNING;
|
||||
current.tli = 0; /* get from result of pg_start_backup() */
|
||||
current.start_lsn.xlogid = 0;
|
||||
current.start_lsn.xrecoff = 0;
|
||||
current.stop_lsn.xlogid = 0;
|
||||
current.stop_lsn.xrecoff = 0;
|
||||
current.start_lsn = 0;
|
||||
current.stop_lsn = 0;
|
||||
current.start_time = time(NULL);
|
||||
current.end_time = (time_t) 0;
|
||||
current.total_data_bytes = BYTES_INVALID;
|
||||
@ -816,7 +814,7 @@ do_backup(pgBackupOption bkupopt)
|
||||
/* backup serverlog */
|
||||
files_srvlog = do_backup_srvlog(backup_list);
|
||||
pgut_atexit_pop(backup_cleanup, NULL);
|
||||
|
||||
|
||||
/* update backup status to DONE */
|
||||
current.end_time = time(NULL);
|
||||
current.status = BACKUP_STATUS_DONE;
|
||||
@ -1052,8 +1050,10 @@ wait_for_archive(pgBackup *backup, const char *sql)
|
||||
if (backup != NULL)
|
||||
{
|
||||
get_lsn(res, &backup->tli, &backup->stop_lsn);
|
||||
elog(LOG, _("%s(): tli=%X lsn=%X/%08X"), __FUNCTION__, backup->tli,
|
||||
backup->stop_lsn.xlogid, backup->stop_lsn.xrecoff);
|
||||
elog(LOG, _("%s(): tli=%X lsn=%X/%08X"),
|
||||
__FUNCTION__, backup->tli,
|
||||
(uint32) (backup->stop_lsn >> 32),
|
||||
(uint32) backup->stop_lsn);
|
||||
}
|
||||
|
||||
/* get filename from the result of pg_xlogfile_name_offset() */
|
||||
@ -1114,6 +1114,8 @@ static void
|
||||
get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
|
||||
{
|
||||
uint32 off_upper;
|
||||
uint32 xlogid;
|
||||
uint32 xrecoff;
|
||||
|
||||
if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 2)
|
||||
elog(ERROR_PG_COMMAND,
|
||||
@ -1122,8 +1124,8 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
|
||||
|
||||
/* get TimeLineID, LSN from result of pg_stop_backup() */
|
||||
if (sscanf(PQgetvalue(res, 0, 0), "%08X%08X%08X",
|
||||
timeline, &lsn->xlogid, &off_upper) != 3 ||
|
||||
sscanf(PQgetvalue(res, 0, 1), "%u", &lsn->xrecoff) != 1)
|
||||
timeline, &xlogid, &off_upper) != 3 ||
|
||||
sscanf(PQgetvalue(res, 0, 1), "%u", &xrecoff) != 1)
|
||||
{
|
||||
elog(ERROR_PG_COMMAND,
|
||||
_("result of pg_xlogfile_name_offset() is invalid: %s"),
|
||||
@ -1132,7 +1134,10 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
|
||||
|
||||
elog(LOG, "%s():%s %s",
|
||||
__FUNCTION__, PQgetvalue(res, 0, 0), PQgetvalue(res, 0, 1));
|
||||
lsn->xrecoff += off_upper << 24;
|
||||
xrecoff += off_upper << 24;
|
||||
|
||||
/* Set LSN correctly */
|
||||
*lsn = (XLogRecPtr) (xlogid << 32) | xrecoff;
|
||||
}
|
||||
|
||||
/*
|
||||
|
32
catalog.c
32
catalog.c
@ -352,10 +352,12 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
|
||||
|
||||
fprintf(out, "# result\n");
|
||||
fprintf(out, "TIMELINEID=%d\n", backup->tli);
|
||||
fprintf(out, "START_LSN=%x/%08x\n", backup->start_lsn.xlogid,
|
||||
backup->start_lsn.xrecoff);
|
||||
fprintf(out, "STOP_LSN=%x/%08x\n", backup->stop_lsn.xlogid,
|
||||
backup->stop_lsn.xrecoff);
|
||||
fprintf(out, "START_LSN=%x/%08x\n",
|
||||
(uint32) (backup->start_lsn >> 32),
|
||||
(uint32) backup->start_lsn);
|
||||
fprintf(out, "STOP_LSN=%x/%08x\n",
|
||||
(uint32) (backup->stop_lsn >> 32),
|
||||
(uint32) backup->stop_lsn);
|
||||
|
||||
time2iso(timestamp, lengthof(timestamp), backup->start_time);
|
||||
fprintf(out, "START_TIME='%s'\n", timestamp);
|
||||
@ -491,9 +493,11 @@ catalog_read_ini(const char *path)
|
||||
|
||||
if (start_lsn)
|
||||
{
|
||||
XLogRecPtr lsn;
|
||||
if (sscanf(start_lsn, "%X/%X", &lsn.xlogid, &lsn.xrecoff) == 2)
|
||||
backup->start_lsn = lsn;
|
||||
uint32 xlogid;
|
||||
uint32 xrecoff;
|
||||
|
||||
if (sscanf(start_lsn, "%X/%X", &xlogid, &xrecoff) == 2)
|
||||
backup->start_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
|
||||
else
|
||||
elog(WARNING, _("invalid START_LSN \"%s\""), start_lsn);
|
||||
free(start_lsn);
|
||||
@ -501,9 +505,11 @@ catalog_read_ini(const char *path)
|
||||
|
||||
if (stop_lsn)
|
||||
{
|
||||
XLogRecPtr lsn;
|
||||
if (sscanf(stop_lsn, "%X/%X", &lsn.xlogid, &lsn.xrecoff) == 2)
|
||||
backup->stop_lsn = lsn;
|
||||
uint32 xlogid;
|
||||
uint32 xrecoff;
|
||||
|
||||
if (sscanf(stop_lsn, "%X/%X", &xlogid, &xrecoff) == 2)
|
||||
backup->stop_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
|
||||
else
|
||||
elog(WARNING, _("invalid STOP_LSN \"%s\""), stop_lsn);
|
||||
free(stop_lsn);
|
||||
@ -609,10 +615,8 @@ catalog_init_config(pgBackup *backup)
|
||||
backup->compress_data = false;
|
||||
backup->status = BACKUP_STATUS_INVALID;
|
||||
backup->tli = 0;
|
||||
backup->start_lsn.xlogid = 0;
|
||||
backup->start_lsn.xrecoff = 0;
|
||||
backup->stop_lsn.xlogid = 0;
|
||||
backup->stop_lsn.xrecoff = 0;
|
||||
backup->start_lsn = 0;
|
||||
backup->stop_lsn = 0;
|
||||
backup->start_time = (time_t) 0;
|
||||
backup->end_time = (time_t) 0;
|
||||
backup->recovery_xid = 0;
|
||||
|
4
data.c
4
data.c
@ -265,7 +265,7 @@ parse_page(const DataPage *page, int server_version,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*offset = *length = 0;
|
||||
return false;
|
||||
}
|
||||
@ -382,7 +382,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
file->read_size += read_len;
|
||||
|
||||
/* if the page has not been modified since last backup, skip it */
|
||||
if (lsn && !XLogRecPtrIsInvalid(page_lsn) && XLByteLT(page_lsn, *lsn))
|
||||
if (lsn && !XLogRecPtrIsInvalid(page_lsn) && page_lsn < *lsn)
|
||||
continue;
|
||||
|
||||
upper_offset = header.hole_offset + header.hole_length;
|
||||
|
4
dir.c
4
dir.c
@ -238,7 +238,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
|
||||
black_list = parray_new();
|
||||
black_list_file = fopen(path, "r");
|
||||
if (black_list_file == NULL)
|
||||
elog(ERROR_SYSTEM, _("can't open black_list: %s"),
|
||||
elog(ERROR_SYSTEM, _("can't open black_list: %s"),
|
||||
strerror(errno));
|
||||
while (fgets(buf, lengthof(buf), black_list_file) != NULL)
|
||||
{
|
||||
@ -296,11 +296,9 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
|
||||
if (linked[0] != '/')
|
||||
{
|
||||
char dname[MAXPGPATH];
|
||||
char *dnamep;
|
||||
char absolute[MAXPGPATH];
|
||||
|
||||
strncpy(dname, file->path, lengthof(dname));
|
||||
dnamep = dirname(dname);
|
||||
join_path_components(absolute, dname, linked);
|
||||
file = pgFileNew(absolute, omit_symlink);
|
||||
}
|
||||
|
29
restore.c
29
restore.c
@ -224,9 +224,11 @@ base_backup_found:
|
||||
if (check)
|
||||
{
|
||||
pgBackup *backup = (pgBackup *) parray_get(backups, last_restored_index);
|
||||
/* XLByteToSeg(xlrp, logId, logSeg) */
|
||||
needId = backup->start_lsn.xlogid;
|
||||
needSeg = backup->start_lsn.xrecoff / XLogSegSize;
|
||||
uint32 xrecoff = (uint32) backup->start_lsn;
|
||||
uint32 xlogid = (uint32) (backup->start_lsn >> 32);
|
||||
|
||||
needId = xlogid;
|
||||
needSeg = xrecoff / XLogSegSize;
|
||||
}
|
||||
|
||||
for (i = last_restored_index; i >= 0; i--)
|
||||
@ -296,7 +298,7 @@ base_backup_found:
|
||||
elog(INFO, _("restore complete. Recovery starts automatically when the PostgreSQL server is started."));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate and restore backup.
|
||||
@ -780,8 +782,7 @@ readTimeLineHistory(TimeLineID targetTLI)
|
||||
|
||||
timeline = pgut_new(pgTimeLine);
|
||||
timeline->tli = 0;
|
||||
timeline->end.xlogid = 0;
|
||||
timeline->end.xrecoff = 0;
|
||||
timeline->end = 0;
|
||||
|
||||
/* expect a numeric timeline ID as first field of line */
|
||||
timeline->tli = (TimeLineID) strtoul(ptr, &endptr, 0);
|
||||
@ -824,8 +825,8 @@ readTimeLineHistory(TimeLineID targetTLI)
|
||||
/* append target timeline */
|
||||
timeline = pgut_new(pgTimeLine);
|
||||
timeline->tli = targetTLI;
|
||||
timeline->end.xlogid = (uint32) -1; /* lsn in target timelie is valid */
|
||||
timeline->end.xrecoff = (uint32) -1; /* lsn target timelie is valid */
|
||||
/* lsn in target timeline is valid */
|
||||
timeline->end = (uint32) (-1UL << 32) | -1UL;
|
||||
parray_insert(result, 0, timeline);
|
||||
|
||||
/* dump timeline branches for debug */
|
||||
@ -836,7 +837,9 @@ readTimeLineHistory(TimeLineID targetTLI)
|
||||
{
|
||||
pgTimeLine *timeline = parray_get(result, i);
|
||||
elog(LOG, "%s() result[%d]: %08X/%08X/%08X", __FUNCTION__, i,
|
||||
timeline->tli, timeline->end.xlogid, timeline->end.xrecoff);
|
||||
timeline->tli,
|
||||
(uint32) (timeline->end >> 32),
|
||||
(uint32) timeline->end);
|
||||
}
|
||||
}
|
||||
|
||||
@ -873,7 +876,7 @@ satisfy_timeline(const parray *timelines, const pgBackup *backup)
|
||||
{
|
||||
pgTimeLine *timeline = (pgTimeLine *) parray_get(timelines, i);
|
||||
if (backup->tli == timeline->tli &&
|
||||
XLByteLT(backup->stop_lsn, timeline->end))
|
||||
backup->stop_lsn < timeline->end)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -977,8 +980,10 @@ print_backup_id(const pgBackup *backup)
|
||||
{
|
||||
char timestamp[100];
|
||||
time2iso(timestamp, lengthof(timestamp), backup->start_time);
|
||||
printf(_(" %s (%X/%08X)\n"), timestamp, backup->stop_lsn.xlogid,
|
||||
backup->stop_lsn.xrecoff);
|
||||
printf(_(" %s (%X/%08X)\n"),
|
||||
timestamp,
|
||||
(uint32) (backup->stop_lsn >> 32),
|
||||
(uint32) backup->stop_lsn);
|
||||
}
|
||||
|
||||
static void
|
||||
|
12
xlog.c
12
xlog.c
@ -113,12 +113,17 @@ bool
|
||||
xlog_logfname2lsn(const char *logfname, XLogRecPtr *lsn)
|
||||
{
|
||||
uint32 tli;
|
||||
uint32 xlogid;
|
||||
uint32 xrecoff;
|
||||
|
||||
if (sscanf(logfname, "%08X%08X%08X",
|
||||
&tli, &lsn->xlogid, &lsn->xrecoff) != 3)
|
||||
&tli, &xlogid, &xrecoff) != 3)
|
||||
return false;
|
||||
|
||||
lsn->xrecoff *= XLogSegSize;
|
||||
xrecoff *= XLogSegSize;
|
||||
|
||||
/* Finish calculation of LSN */
|
||||
*lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -129,5 +134,6 @@ void
|
||||
xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn)
|
||||
{
|
||||
snprintf(fname, len, "%08X%08X%08X", tli,
|
||||
lsn->xlogid, lsn->xrecoff / XLogSegSize);
|
||||
(uint32) (*lsn / XLogSegSize),
|
||||
(uint32) (*lsn % XLogSegSize));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user