0

I have followed below process to backup my database file.

image 1 :

enter image description here

Image 2 :

enter image description here

After click on backup , I got a file with name resetmarathon_db.sql

Then I have store this file in my project/DB directory

In docker-compose.yml file I have use volume like below example

volumes:
      - ./DB/resetmarathon_db.sql:/docker-entrypoint-initdb.d/resetmarathon_db.sql

This is the full section of docker-compose.yml file for postgres

resetmarathon_db:
    container_name: resetmarathon_db
    environment:
      POSTGRES_DB: resetmarathon_db
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
    image: postgres:latest
    hostname: resetmarathon_db
    restart: unless-stopped
    networks:
      - resetmarathon-network
    volumes:
      - ./DB/resetmarathon_db.sql:/docker-entrypoint-initdb.d/resetmarathon_db.sql

After build I'm getting only database table name with no any table.

How can I restore my sql file ?

My file and folder structure

enter image description here

2
  • 1
    It isn't an SQL file - it's a "custom" format (which is what you selected) backup file. You can restore it with pg_restore. If you want the docker auto-run stuff it presumably needs to be a genuine sql file. Commented Feb 1, 2022 at 13:56
  • Thanks @RichardHuxton after see your comment , I have downloaded plan sql file and it's working !! Commented Feb 1, 2022 at 14:30

1 Answer 1

1

You need to create the database before you execute your script

Here is a create database script which you can save as a file init_dbScript.sql

DROP DATABASE IF EXISTS resetmarathon_db;
CREATE DATABASE resetmarathon_db;

Then volume it and make sure it will be executed before your script.

volumes:
  - ./DB/resetmarathon_db.sql:/docker-entrypoint-initdb.d/resetmarathon_db.sql
  - ./DB/init_dbScript.sql:/docker-entrypoint-initdb.d/init_dbScript.sql
Sign up to request clarification or add additional context in comments.

2 Comments

after apply this volumes no any changes found.
@NiloyRony Could you try to add create database script in the begin of resetmarathon_db.sql? and make sure your script will be work in a empty database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.