Makefile: restore mongodb
This commit is contained in:
parent
e93b5e653a
commit
1496eefc14
13
Makefile
13
Makefile
@ -8,10 +8,9 @@ REMOTE_CONTAINER_PATH=/data/db/mongodump
|
||||
LOCAL_PATH=/tmp/mongodump
|
||||
LOCAL_DB=test
|
||||
LOCAL_CONTAINER_NAME=nextload-mongo-1
|
||||
ENV_FILE=.env
|
||||
|
||||
MONGO_USER=mongo
|
||||
MONGO_PASSWORD=mongo
|
||||
MONGO_HOST=mongo
|
||||
include $(ENV_FILE)
|
||||
|
||||
sync_db:
|
||||
@echo "Step 1: Dump the database on production"
|
||||
@ -25,6 +24,8 @@ sync_db:
|
||||
"docker exec $$(docker --context swarm-demo.autonomic.zone ps -q -f name=nextload-demo_autonomic_zone_mongo) \
|
||||
tar -cC $(REMOTE_CONTAINER_PATH) ." | tar -xC $(LOCAL_PATH)
|
||||
|
||||
@echo "Step 3: Drop the existing local database and restore the dump"
|
||||
docker exec -it $(LOCAL_CONTAINER_NAME) mongosh --username $(MONGO_USER) --password $(MONGO_PASSWORD) $(LOCAL_DB) --eval "db.dropDatabase()"
|
||||
docker exec -it $(LOCAL_CONTAINER_NAME) mongorestore --drop --username $(MONGO_USER) --password $(MONGO_PASSWORD) --authenticationDatabase admin $(LOCAL_PATH)
|
||||
@echo "Step 3: Copy the dump from local machine to MongoDB container"
|
||||
docker cp $(LOCAL_PATH)/ $(LOCAL_CONTAINER_NAME):/tmp/mongodump
|
||||
|
||||
@echo "Step 4: Drop the existing local database and restore the dump"
|
||||
docker exec -it $(LOCAL_CONTAINER_NAME) mongorestore --drop --username $(MONGO_USER) --password $(MONGO_PASSWORD) --authenticationDatabase admin --db $(LOCAL_DB) /tmp/mongodump/$(LOCAL_DB)
|
Loading…
Reference in New Issue
Block a user