Database backup in docker environment (postgresql, mysql) example code

Database backup in docker environment (postgresql, mysql) example code

posgresql backup/restore

1. Backup

DATE=`date +%Y%m%d-%H%M`
BACK_DATA=xxapp-data-${DATE}.out # Set the name of the backup file here. Adding the date is to prevent duplication. docker exec pg-db pg_dumpall -U postgres > ${BACK_DATA} # pg-db is the docker name of the database

2. Recovery

docker cp ${BACK_DATA} pg-db:/tmp
docker exec pg-db psql -U postgres -f /tmp/${BACK_DATA} postgres

mysql backup/restore

1. Backup

DATE=`date +%Y%m%d-%H%M`
BACK_DATA=xxapp-data-${DATE}.sql
# mysql-db is the docker name of the database, xxxpwd is the root user password, app-db is the name of the data to be backed up docker exec mysql-db mysqldump -uroot -pxxxpwd --databases app-db > ${BACK_DATA}

2. Restore the following ${BACK_DATA} to replace it with the actual generated file name

docker cp ${BACK_DATA} mysql-db:/tmp 
docker exec -it mysql-db mysql -uroot -pxxxpwd 
mysql> source /tmp/${BACK_DATA}.sql
mysql> \q
Bye

Replenish

postgresql backs up all databases, mysql backs up a specific database.

Summarize

The above is the database backup (postgresql, mysql) in the docker environment introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • About Docker deployment postgresql database
  • Running PostgreSQL in Docker and recommending several connection tools
  • Solution for creating multiple databases when Docker starts PostgreSQL
  • How to install Postgres 12 + pgadmin in local Docker (support Apple M1)
  • Detailed steps to upgrade PostgreSQL in Docker environment
  • How to install and persist the postgresql database in docker
  • How to run postgreSQL with docker
  • How to deploy docker to access postgres database

<<:  MySQL index usage instructions (single-column index and multi-column index)

>>:  Detailed explanation of type protection in TypeScript

Recommend

Automatically install the Linux system based on cobbler

1. Install components yum install epel-rpm-macros...

How to Monitor Linux Memory Usage Using Bash Script

Preface There are many open source monitoring too...

How to build an ELK log system based on Docker

Background requirements: As the business grows la...

Thoroughly understand JavaScript prototype and prototype chain

Table of contents Preface Laying the foundation p...

Vue implements form data validation example code

Add rules to the el-form form: Define rules in da...

MySQL query method with multiple conditions

mysql query with multiple conditions Environment:...

Four methods of using JS to determine data types

Table of contents Preface 1. typeof 2. instanceof...

Solution to the docker command exception "permission denied"

In Linux system, newly install docker and enter t...

A brief analysis of MySQL backup and recovery

Table of contents 1. Introduction 2. Simple defin...

Complete steps to quickly build a vue3.0 project

Table of contents 1. We must ensure that the vue/...

Example of Form action and onSubmit

First: action is an attribute of form. HTML5 has d...

The w3c organization gives style recommendations for html4

This is the style recommendation given by the W3C ...

Detailed installation history of Ubuntu 20.04 LTS

This article records the creation of a USB boot d...