24.1. Дамп SQL
cd ~/pg-967_1c
Собираем образ командой:
docker build -t pg:967_1c .
docker volume create --name pgdata
Запускаем:
docker run --detach --rm --volume pgdata:/var/lib/postgresql/data --name pg1c --publish 5432:5432 pg:967_1c
Постоянный запуск :
docker run --detach --restart=always --volume pgdata:/var/lib/postgresql/data --name pg1c --publish 5432:5432 pg:967_1c
----------------------------------------------------------------------------------------------------
$ docker exec -i pg1c /usr/bin/pg_dump -U postgres demo1 | gzip > ~/demo1.sql.gz
Backup одной базы demo1:
$ docker exec -t -u postgres pg1c /usr/bin/pg_dump demo1 -c > demo1_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore в туже базу:
$ cat demo1_26-11-2018_17_31_53.sql | docker exec -i pg1c psql -Upostgres
Restore в другую базу:
$ cat demo1_26-11-2018_17_31_53.sql | docker exec -i pg1c psql -Upostgres demo2
Backup, restore postgres in docker container
dumpall все базы
$ docker exec -t -u postgres pg1c /usr/bin/pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore:
cat dump_26-11-2018_17_19_25.sql | docker exec -i pg1c psql -Upostgres
$ docker exec -t -u postgres pg1c /usr/bin/vacuumdb --verbose --analyze --full --quiet --username postgres --dbname=demo1
docker exec -i nlc-pg1cTest psql -U postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'log_prod' AND pid <> pg_backend_pid();" && \
docker exec -i nlc-pg1cTest psql -U postgres -c "drop database log_prod;" && \
docker exec -i nlc-pg1cTest psql -U postgres -c "create database log_prod;" && \
cat /backups/sql/$DATE/log_prod.custom | docker exec -i nlc-pg1cTest sh -c "pg_restore -d 'postgres://postgres:пароль@127.0.0.1/log_prod' -v -1"
cd ~/pg-967_1c
Собираем образ командой:
docker build -t pg:967_1c .
docker volume create --name pgdata
Запускаем:
docker run --detach --rm --volume pgdata:/var/lib/postgresql/data --name pg1c --publish 5432:5432 pg:967_1c
Постоянный запуск :
docker run --detach --restart=always --volume pgdata:/var/lib/postgresql/data --name pg1c --publish 5432:5432 pg:967_1c
----------------------------------------------------------------------------------------------------
$ docker exec -i pg1c /usr/bin/pg_dump -U postgres demo1 | gzip > ~/demo1.sql.gz
Backup одной базы demo1:
$ docker exec -t -u postgres pg1c /usr/bin/pg_dump demo1 -c > demo1_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore в туже базу:
$ cat demo1_26-11-2018_17_31_53.sql | docker exec -i pg1c psql -Upostgres
Restore в другую базу:
$ cat demo1_26-11-2018_17_31_53.sql | docker exec -i pg1c psql -Upostgres demo2
Backup, restore postgres in docker container
dumpall все базы
$ docker exec -t -u postgres pg1c /usr/bin/pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore:
cat dump_26-11-2018_17_19_25.sql | docker exec -i pg1c psql -Upostgres
$ docker exec -t -u postgres pg1c /usr/bin/vacuumdb --verbose --analyze --full --quiet --username postgres --dbname=demo1
docker exec -i nlc-pg1cTest psql -U postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'log_prod' AND pid <> pg_backend_pid();" && \
docker exec -i nlc-pg1cTest psql -U postgres -c "drop database log_prod;" && \
docker exec -i nlc-pg1cTest psql -U postgres -c "create database log_prod;" && \
cat /backups/sql/$DATE/log_prod.custom | docker exec -i nlc-pg1cTest sh -c "pg_restore -d 'postgres://postgres:пароль@127.0.0.1/log_prod' -v -1"
Комментариев нет:
Отправить комментарий