postgresql - Docker Backup and restore postgres -
i using docker postgres:9.4 image. need know how backup , restore volume container.
created volume container:
docker run -v /var/lib/postgresql/data --name dbdata postgres:9.4 /bin/true
using volume
docker run --name=postgres --volumes-from=dbdata -d -p 6432:5432 postgres:9.4
backup volume container
docker run --volumes-from dbdata -v $(pwd):/backup postgres:9.4 tar cvf /backup/backup.tar /var/lib/postgresql/data
restore volume in new container
docker run --name=dbdata-new --volumes-from dbdata -v $(pwd):/backup ubuntu:14.04 /bin/sh -c 'cd /var/lib/postgresql/data && tar xvf /backup/backup.tar'
use in new volume in creating new postgres container:
docker run --name=postgres-new --volumes-from=dbdata-new -d -p 7532:5432 postgres:9.4
issue: i below error in logs when run new container.
initdb: directory "/var/lib/postgresql/data" exists not empty if want create new database system, either remove or empty directory "/var/lib/postgresql/data" or run initdb argument other "/var/lib/postgresql/data"
not sure doing wrong. can please point out making mistake.
could not reproduce issue following steps rudiment data (one record 1 table 1 new db):
psql -u postgres -h $(boot2docker ip || echo 'localhost') -p 6432 -c "create database ttt;" psql -u postgres -h $(boot2docker ip || echo 'localhost') -p 6432 -d ttt -c "create table a(b int); insert a(b) values(1);" psql -u postgres -h $(boot2docker ip || echo 'localhost') -p 6432 -d ttt -c "select * a;"
when start postgres-new
no exceptions in logs , data seems there:
$ psql -u postgres -h $(boot2docker ip || echo 'localhost') -p 7532 -d ttt -c "select * a;" b --- 1 (1 row)
Comments
Post a Comment