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

RGB color table collection

RGB color table color English name RGB 16 colors ...

Two methods of restoring MySQL data

1. Introduction Some time ago, there were a serie...

A complete example of implementing a timed crawler with Nodejs

Table of contents Cause of the incident Use Node ...

Detailed tutorial on compiling and installing python3.6 on linux

1. First go to the official website https://www.p...

Two methods of MySql comma concatenation string query

The following two functions are used in the same ...

Detailed explanation of Linux index node inode

1. Introduction to inode To understand inode, we ...

Nginx external network access intranet site configuration operation

background: The site is separated from the front ...

Detailed explanation of the execution process of mysql update statement

There was an article about the execution process ...

JavaScript history object explained

Table of contents 1. Route navigation 2. History ...

Understanding MySQL index pushdown in five minutes

Table of contents What is index pushdown? The pri...

Vue uses element-ui to implement menu navigation

This article shares the specific code of Vue usin...

Vue2.0 implements adaptive resolution

This article shares the specific code of Vue2.0 t...

MySQL uses aggregate functions to query a single table

Aggregate functions Acts on a set of data and ret...