Reputation: 632
I have followed below process to backup my database file.
image 1 :
Image 2 :
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
Upvotes: 0
Views: 383
Reputation: 46249
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
Upvotes: 1