Skip to content

Instantly share code, notes, and snippets.

@blohinn
Last active October 21, 2019 20:10
Show Gist options
  • Save blohinn/e301fb4d13c75d7db59de747c0fc358f to your computer and use it in GitHub Desktop.
Save blohinn/e301fb4d13c75d7db59de747c0fc358f to your computer and use it in GitHub Desktop.

Revisions

  1. blohinn revised this gist Oct 21, 2019. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions Бэкап postgres из докера
    Original file line number Diff line number Diff line change
    @@ -7,3 +7,24 @@ docker exec -t tatcamps.prod.postgres pg_dump -U tatcamp --column-inserts tatcam
    docker exec -t ulmts.postgres psql -U ulmts ulmts -t -c "drop schema public cascade; create schema public;"

    cat your_dump.sql | docker exec -i tatcamps.dev.postgres psql -U tatcamp -d tatcamp

    ############################


    # # Работает внутри контейнера (без приставки docker exec -t <container_uid>) # #

    docker exec -t <container_uid> pg_dump -U smartnet -d smartnet -F c > dump_`date +%d-%m-%Y"_"%H-%M`.gz

    docker exec -t <container_uid> pg_restore -U smartnet -d smartnet <dumpfile>.gz

    # # Через gzip (запуск за пределами контейнера) # #

    docker exec -t <container_uid> pg_dump -U smartnet -d smartnet | gzip > dump_`date +%d-%m-%Y"_"%H-%M`.gz

    gunzip <dumpfile>.gz

    cat <dumpfile> | docker exec -i <container_uid> psql -U smartnet -d smartnet

    # Или сразу, без распаковки

    gzcat <dumpfile>.gz | docker exec -i <container_uid> psql -U smartnet -d smartnet
  2. blohinn revised this gist Sep 16, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Бэкап postgres из докера
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,6 @@

    docker exec -t tatcamps.prod.postgres pg_dump -U tatcamp --column-inserts tatcamp > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

    docker exec -t ulmts.postgres psql -U ulmts ulmts -t -c "drop schema public cascade; create schema public;"

    cat your_dump.sql | docker exec -i tatcamps.dev.postgres psql -U tatcamp -d tatcamp
  3. blohinn created this gist Apr 25, 2019.
    7 changes: 7 additions & 0 deletions Бэкап postgres из докера
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Бэкап данных (+ создание таблиц)

    Подразумевается, что бд tatcamps.dev.postgres существует, но таблицы в ней удалены для создания бэкапов

    docker exec -t tatcamps.prod.postgres pg_dump -U tatcamp --column-inserts tatcamp > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

    cat your_dump.sql | docker exec -i tatcamps.dev.postgres psql -U tatcamp -d tatcamp