IT/Docker

Docker postgresql db 백업, 복원 방법.

bepuri 2023. 12. 14. 11:31
728x90

구글엔 없는게 없다..

https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database

 

Backup/Restore a dockerized PostgreSQL database

I'm trying to backup/restore a PostgreSQL database as is explained on the Docker website, but the data is not restored. The volumes used by the database image are: VOLUME ["/etc/postgresql", "/v...

stackoverflow.com

Giovanni Aravena Morales 요 분이 쓰신 댓글을 참고 했고

명령은 아래와 같음

#백업
docker exec -t your-db-container pg_dumpall -c -U your-db-user > dump_$(date +%Y-%m-%d_%H_%M_%S).sql

#복원
cat your_dump.sql | docker exec -iT your-db-container psql -U your-db-user -d your-db-name

 

내 경우 복원 과정에서 아래와 같은 tty 오류가 나서

the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

-T 옵션을 붙여주니 정상적으로 작동했다.

 

여기서 -T옵션은 tty를 끄는거다. 현재 bash에서 cat으로 input을 가져오는데 그게 tty가 아니다보니,

docker compose 상의 bash는 tty로 구동되어 서로 맞춰주기 위해서 docker 쪽에서 tty를 꺼버린거다.

 

아마 윈도우와 리눅스 간의 서로다른 입력기 차이 때문에 제대로 데이터가 들어가지 않은듯하다.

 

 

728x90