Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*-------------------------------------------------------------------------
 *
 * xlogbackup.c
 *      Internal routines for base backups.
 *
 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * IDENTIFICATION
 *      src/backend/access/transam/xlogbackup.c
 *-------------------------------------------------------------------------
 */
 
#include "postgres.h"
 
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xlogbackup.h"
 
/*
 * Build contents for backup_label or backup history file.
 *
 * When ishistoryfile is true, it creates the contents for a backup history
 * file, otherwise it creates contents for a backup_label file.
 *
 * Returns the result generated as a palloc'd string.
 */
char *
build_backup_content(BackupState *state, bool ishistoryfile)
{
    char        startstrbuf[128];
    char        startxlogfile[MAXFNAMELEN]; /* backup start WAL file */
    XLogSegNo   startsegno;
    StringInfoData result;
 
    Assert(state != NULL);
 
    initStringInfo(&result);
 
    /* Use the log timezone here, not the session timezone */
    pg_strftime(startstrbuf, sizeof(startstrbuf), "%Y-%m-%d %H:%M:%S %Z",
                pg_localtime(&state->starttime, log_timezone));
 
    XLByteToSeg(state->startpoint, startsegno, wal_segment_size);
    XLogFileName(startxlogfile, state->starttli, startsegno, wal_segment_size);
    appendStringInfo(&result, "START WAL LOCATION: %X/%08X (file %s)\n",
                     LSN_FORMAT_ARGS(state->startpoint), startxlogfile);
 
    if (ishistoryfile)
    {
        char        stopxlogfile[MAXFNAMELEN];  /* backup stop WAL file */
        XLogSegNo   stopsegno;
 
        XLByteToSeg(state->stoppoint, stopsegno, wal_segment_size);
        XLogFileName(stopxlogfile, state->stoptli, stopsegno, wal_segment_size);
        appendStringInfo(&result, "STOP WAL LOCATION: %X/%08X (file %s)\n",
                         LSN_FORMAT_ARGS(state->stoppoint), stopxlogfile);
    }
 
    appendStringInfo(&result, "CHECKPOINT LOCATION: %X/%08X\n",
                     LSN_FORMAT_ARGS(state->checkpointloc));
    appendStringInfoString(&result, "BACKUP METHOD: streamed\n");
    appendStringInfo(&result, "BACKUP FROM: %s\n",
                     state->started_in_recovery ? "standby" : "primary");
    appendStringInfo(&result, "START TIME: %s\n", startstrbuf);
    appendStringInfo(&result, "LABEL: %s\n", state->name);
    appendStringInfo(&result, "START TIMELINE: %u\n", state->starttli);
 
    if (ishistoryfile)
    {
        char        stopstrfbuf[128];
 
        /* Use the log timezone here, not the session timezone */
        pg_strftime(stopstrfbuf, sizeof(stopstrfbuf), "%Y-%m-%d %H:%M:%S %Z",
                    pg_localtime(&state->stoptime, log_timezone));
 
        appendStringInfo(&result, "STOP TIME: %s\n", stopstrfbuf);
        appendStringInfo(&result, "STOP TIMELINE: %u\n", state->stoptli);
    }
 
    /* either both istartpoint and istarttli should be set, or neither */
    Assert(XLogRecPtrIsValid(state->istartpoint) == (state->istarttli != 0));
    if (XLogRecPtrIsValid(state->istartpoint))
    {
        appendStringInfo(&result, "INCREMENTAL FROM LSN: %X/%08X\n",
                         LSN_FORMAT_ARGS(state->istartpoint));
        appendStringInfo(&result, "INCREMENTAL FROM TLI: %u\n",
                         state->istarttli);
    }
 
    return result.data;
}