“This is the 18th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

preface

In order to ensure the security of the database and prevent the loss of data caused by production accidents, we need to back up the database regularly.

Database Backup

① Logical Backup

Use the following command:

gs_dumpall -f 2021-11-19.sql -p 26000

It can realize the storage logical backup of the database and save the database as a. SQL file.

The generated.SQL file contains user information, table structure, and data:

vim 2021-11-19.sql

② File Backup

Create a backup folder first:

mkdir /home/omm/backup-2021-11-19

Backup using the gs_basebackup command:

gs_basebackup -D /home/omm/backup-2021-11-19 -p 26000 -P -l /home/omm/backup-2021-11-19

Check the backup folder and find many directories and configuration files:

Consistent with the current database file:

Backup recovery

① Logical Backup

Delete the test database used for testing:

drop database test;

Run SQL commands using GSQL:

gsql -p 26000 -f 2021-11-19.sql postgres

Test was recovered:

② File Backup

Before restoring, you need to close the database:

gs_om -t stop

If the name of the original directory is changed, the database is deleted. Run the gs_om-t start command to indicate that the database configuration does not exist.

Copy the previously backed up database file and start it again to complete the backup and restore:

cp -r /home/omm/backup-2021-11-19/ /gaussdb/data/db1/

Database structure unchanged: