Manager Handbook for Centralized AntDB-T - P5–1
Published: 2023-08-16 07:25:10

Backup recovery
Overview
AntDB backups are classified by backup mechanism:
•Logical backup: The objects and data in the database are backed up to one or more files in the form of SQL statements, which is called logical backup
•Physical backup: Backup by physical file copy, which is called physical backup
Classification by backup method:
•Full backup: all data of the whole database is backed up each time
•Incremental backup: On top of one full backup, only the new data is backed up each time (WAL log archiving)
Logical backups
Suitable scenarios:
•Only some objects or data need to be backed up (more granular backup scenarios)
•Cross-version data migration
•When data volumes are relatively small (e.g., test environments)
•Less demanding on database recovery time
AntDB's logical backup tools:
•pg_dump, pg_dumpall/pg_restore (binary commands)
•copy (SQL statement)
pg_dump
Command description
Outline

```
pg_dump [connection-option...] [option...] [dbname]
```
Description
pg_dump is a tool for backing up an AntDB database. It creates consistent backups even when the database is being used concurrently. pg_dump does not block other users from accessing the database (reading or writing).
pg_dump dumps only a single database. To back up a cluster or a global object common to all databases in a cluster (such as roles and tablespaces), pg_dumpall should be used.
Dumps can be exported to a script or archive file format. Script dumps are plain text files containing SQL commands that can be used to reconstruct the database to the state it was in when it was dumped.
Another optional archive file format must be used in conjunction with pg_restore to rebuild the database. They allow pg_restore to be able to choose what to restore, or even to reorder entries before restoring. Archive file formats are designed to be portable between architectures.
When used in one of the archive file formats and combined with pg_restore, pg_dump provides a flexible archiving and transfer mechanism. pg_dump can be used to back up the entire database, and then pg_restore can be used to check the archive and/or select which parts of the database are to be restored. The most flexible output file formats are the "custom" format (-Fc) and the "directory" format (-Fd). They allow selecting and reordering all archived items, support parallel recovery, and are compressed by default. The "directory" format is the only format that supports parallel dumps.

```
pg_dump --help
    General options:
     -f, --file=FILENAME          output file or directory name
     -F, --format=c|d|t|p         output file format (custom, directory, tar,plain text (default))
     -j, --jobs=NUM               use this many parallel jobs to dump
     -Z, --compress=0-9           compression level for compressed formats
  Options controlling the output content:
     -a, --data-only              dump only the data, not the schema
     -E, --encoding=ENCODING      dump the data in encoding ENCODING
     -n, --schema=PATTERN         dump the specified schema(s) only
     -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)
     -s, --schema-only            dump only the schema, no data
     -t, --table=PATTERN          dump the specified table(s) only
```