Detailed explanation of psql database backup and recovery in docker

Detailed explanation of psql database backup and recovery in docker

1. Postgres database backup in Docker

Order:

docker exec it db_13 pg_dumpall -c -U mrp > mrp217

explain:

docker exec it [name of the image database in docker] pg_dumpall -c -U [user name] > [name of the database to be exported]

2. Postgres Database Backup

Order:

pg_dump --host xxxxx --port 5434 --username odoo > odoo217 mrp

explain:

pg_dump –host [address] –port [port] –username [database username] > [exported file] [database name]

3. Restore locally and restore to docker directly through the command line

psql -U odoo (user name) -h localhost -p 6543 (port mapped by docker) -d odoo (database name) -f /media/liang/_dde_data/mrp217

4. Before restoring the database in docker, delete the old database, create a new one, and then restore it (regular database updates)

docker exec -it db13 bash #Enter daocker
psql -U odoo (user name) -d postgres # Enter the psql database

After entering, perform database operations:
drop databse odoo; # delete the database
create database odoo; #Create a new database, exit dockers and then restore the database

4.1 Another recovery, mine is not applicable here

pg_dump -h localhost -p 5432 -U odoo -F c -b -v -f "/usr/20200214.backup" mrp in docker, function: back up from docker database to docker
docker cp db_mrp_sync:/usr/20200214.backup ./ outside docker, function: from docker to the server outside docker
scp xxxxxx:/home/xxx/20200214.backup D:\ Connect to the remote and import to the local location
pg_restore -d <database name> /path/to/your/file/mrp.sql -c -U <user name>

5. Import from the test server to the local

scp xxxx:/home/xxx/mrp217 D:\ Connect to the remote and import to the local location without shell tool installed
scp ip: the path of the backup file in the test server, the local path to be imported

The above is all the content compiled by the editor of 123WORDPRESS.COM. I hope it can help you.

You may also be interested in:
  • Database backup in docker environment (postgresql, mysql) example code
  • Docker container regularly backs up the database and sends it to the specified mailbox (design idea)

<<:  Linux tac command implementation example

>>:  Solve the problem of resetting the Mysql root user account password

Recommend

Use nginx to dynamically convert image sizes to generate thumbnails

The Nginx ngx_http_image_filter_module module (ng...

Common tags in XHTML

What are XHTML tags? XHTML tag elements are the b...

In-depth understanding of uid and gid in docker containers

By default, processes in the container run with r...

An example of elegantly writing status labels in Vue background

Table of contents Preface optimization Extract va...

Build nginx virtual host based on domain name, port and IP

There are three types of virtual hosts supported ...

5 ways to determine whether an object is an empty object in JS

1. Convert the json object into a json string, an...

Detailed tutorial on installing pxc cluster with docker

Table of contents Preface Preliminary preparation...

Several ways to backup MySql database

mysqldump tool backup Back up the entire database...

React+TypeScript project construction case explanation

React project building can be very simple, but if...

How to implement gzip compression in nginx to improve website speed

Table of contents Why use gzip compression? nginx...

8 ways to manually and automatically backup your MySQL database

As a popular open source database management syst...

How to split data in MySQL table and database

Table of contents 1. Vertical (longitudinal) slic...

The whole process of node.js using express to automatically build the project

1. Install the express library and generator Open...