openGauss：gs_basebackup
Tags: opengauss
Published: 2023-03-22 03:17:40

gs_basebackup
Background Information
After the successful deployment of openGauss, various problems and abnormal states will be encountered during the operation of the database. openGauss provides the gs_basebackup tool for basic physical backup. The realization goal of gs_basebackup is to copy the binary of the server database file, and its realization principle uses the replication protocol. When executing gs_basebackup remotely, a system administrator account is required. gs_basebackup currently supports hot backup mode and compressed format backup.

 illustrate:

gs_basebackup only supports full backup of the master and backup, not incremental.
gs_basebackup currently supports hot backup mode and compressed format backup.
When gs_basebackup backs up a tablespace with an absolute path, if the backup is performed on the same machine, you can use tablespace-mapping to redirect the path of the tablespace, or use the archive mode for backup.
If the incremental detection point function is enabled and double-write is enabled, gs_basebackup will also back up double-write files.
If the pg_xlog directory is a soft link, no soft link will be established during backup, and the data will be backed up directly to the pg_xlog directory of the destination path.
Revocation of user backup rights during the backup process may result in backup failure or unavailable backup data.
If there is no response from the server due to temporary network failures, etc., gs_basebackup will exit after waiting for a maximum of 120 seconds.
prerequisite
The openGauss database can be connected normally.

User rights are not revoked during backup.

The replication link needs to be configured in pg_hba.conf, and the link must be established by a system administrator.

If the xlog transmission mode is stream mode, you need to configure the number of max_wal_senders, at least one is available.

If the xlog transfer mode is fetch mode, it is necessary to set the wal_keep_segments parameter high enough so that the log will not be removed before the end of the backup.

When restoring, it is necessary to ensure that there are backup files in the backup directory of each node. If the backup file is lost, it needs to be copied from other nodes.

grammar
show help information

gs_basebackup -? | --help
Display version number information

gs_basebackup -V | --version
Parameter Description

The gs_basebackup parameters can be divided into the following categories:

-D directory

Backup file output directory, required.

Common parameters:

-c, --checkpoint=fast|spread

Sets the checkpoint mode to fast or spread (default).

-l, --label=LABEL

Set labels for backups.

-P, --progress

Enable progress reporting.

-v, --verbose

Enable verbose mode.

-V, --version

Exit after printing the version.

-?, --help

Displays the gs_basebackup command line parameters.

-T, --tablespace-mapping=olddir=newdir

Relocate tablespaces in directory olddir into newdir during backup. For this to work, olddir must match exactly the path where the tablespace resides (but it is not an error if the tablespace in olddir is not included in the backup). olddir and newdir must be absolute paths. If a path happens to contain an = sign, escape it with a backslash. This option can be used multiple times for multiple tablespaces.

-F, --format=plain|tar

Set the output format to plain (default) or tar. If this parameter is not set, the default –format=plain. The plain format writes the output as a flat file, using the same layout as the current data directory and tablespace. When the cluster has no additional tablespaces, the entire database will be placed in the target directory. If the cluster contains additional tablespaces, the main data directory will be placed in the target directory, but all other tablespaces will be placed in the same absolute path as they are on the server. The tar mode writes the output as a tar file in the target directory. The main data directory will be written to a file called base.tar, and the other tablespaces will be named after their OIDs. The generated tar package needs to be decompressed with the gs_tar command.

-X, –xlog-method=fetch|stream

Set the xlog transmission method. If this parameter is not set, the default –xlog-method=stream. Include the required write-ahead log files (WAL files) in the backup. This includes all write-ahead logs generated during the backup. The fetch method collects the write-ahead log files at the end of the backup. Therefore, it is necessary to set the wal_keep_segments parameter high enough so that the log is not removed until the end of the backup. If the log is already rotated when it is time to transfer, the backup will fail and be unusable. The stream method streams the write-ahead log when the backup is created. This will open a second connection to the server and start streaming the write-ahead log in parallel to running the backup. Therefore, it will use up to two connections configured by the max_wal_senders parameter. Using this mode does not require additional write-ahead logs to be kept on the master, as long as clients can keep receiving write-ahead logs.

-x,

--xlog Using this option is equivalent to using -X with the method fetch.

-Z –compress=level

Enables gzip compression on tar file output, and specifies the compression level (0 to 9, with 0 being no compression and 9 being best compression). Compression is only available when using the tar format and automatically appends the suffix .gz to all tar filenames.

-z

Enables gzip compression of tar file output, using the default compression level. Compression is only available when using the tar format and automatically appends the suffix .gz to all tar filenames.

-t, --rw-timeout

Set the checkpoint time limit during backup, the default time limit is 120s. When the full checkpoint of the database takes a long time, you can appropriately increase the rw-timeout limit time.

connection parameters

-h, --host=HOSTNAME

Specifies the hostname on which the server is running or the path to a Unix domain socket.

-p, --port=PORT

Specifies the port number of the database server.

The default port number can be modified by the port parameter.

-U, --username=USERNAME

Specifies the user to connect to the database.

-s, --status-interval=INTERVAL

The time in seconds for the status packet sent to the server.

-w, --no-password

No password prompt appears.

-W, --password

When the -U parameter is used to connect to a local database or a remote database, a password prompt can appear by specifying this option.