Restoring from Full Backup Files to a Self-Built PostgreSQL Database

You can download backup files by referring to Downloading a Full Backup File and restore data from them.

Prerequisites

  1. A tool for decompressing TAR files must be installed in a Unix-like system.
  2. Either python2.7 or python3 can be used.
  3. The following third-party packages need to be installed: lz4, gzip, and shutil.
  4. The version of the local database must be the same as that of the cloud database.
  5. Plugins of the same version as the cloud database are installed in the local database.

Procedure

  1. Prepare a local directory for storing tablespaces.
  2. Stop the local database server.
  3. Store the following configuration files in the data directory of the local database to another directory: postgresql.conf, pg_hba.conf, and recovery.done.
  4. Clear the data directory of the local database.
  5. Download the decompression tool.
  6. Run the following command to decompress backup files to the directory prepared in Step 1:

    python restore_obs_file.py src_file target_dir

    Variables in the command are described as follows:

    src_file: indicates the directory where PostgreSQL full backup files are stored.

    target_dir: indicates the directory to which data is restored. The directory has been prepared in 1. The directory must be empty. If the directory does not exist, the system automatically creates it.

    The following directories are generated after the decompression:

    • data: stores full backup data. The recovery.done file has been deleted.
    • xlog: stores incremental backup data.
    • tblspc: stores tablespace directory files (if the original backup contains tablespace files).

  7. Copy the files in 6 to the specified directory of the local database.

    1. Copy all the decompressed files in the data directory to the data directory of the local database, and then replace the three files in the data directory of the local database with the configuration files saved in step 3.
    2. Copy the decompressed files in the xlog directory to the pg_xlog or pg_wal folder in the data directory of the local database. (The folder names vary according to database versions.)
    3. Move the decompressed tablespace folder (if any) in the tblspc directory to the tablespace directory created in step 1 and modify the soft link of the corresponding tablespace in data\tablespace_map.

  8. Reboot the database and wait until the database restoration is complete.