Makefile: sync_media
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
tobias 2024-07-16 15:34:24 +02:00
parent 1496eefc14
commit 2e372d1aae

View File

@ -8,6 +8,8 @@ REMOTE_CONTAINER_PATH=/data/db/mongodump
LOCAL_PATH=/tmp/mongodump LOCAL_PATH=/tmp/mongodump
LOCAL_DB=test LOCAL_DB=test
LOCAL_CONTAINER_NAME=nextload-mongo-1 LOCAL_CONTAINER_NAME=nextload-mongo-1
REMOTE_VOLUME_NAME = nextload-demo_autonomic_zone_payload_uploads
LOCAL_VOLUME_NAME = nextload_payload_uploads
ENV_FILE=.env ENV_FILE=.env
include $(ENV_FILE) include $(ENV_FILE)
@ -28,4 +30,20 @@ sync_db:
docker cp $(LOCAL_PATH)/ $(LOCAL_CONTAINER_NAME):/tmp/mongodump docker cp $(LOCAL_PATH)/ $(LOCAL_CONTAINER_NAME):/tmp/mongodump
@echo "Step 4: Drop the existing local database and restore the dump" @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) docker exec -it $(LOCAL_CONTAINER_NAME) mongorestore --drop --username $(MONGO_USER) --password $(MONGO_PASSWORD) --authenticationDatabase admin --db $(LOCAL_DB) /tmp/mongodump/$(LOCAL_DB)
sync_media:
@echo "Step 1: Create a tar archive of the remote Docker volume"
rm -rf /tmp/$(REMOTE_VOLUME_NAME)
mkdir -p /tmp/$(REMOTE_VOLUME_NAME)
ssh -p $(REMOTE_PORT) $(REMOTE_USER)@$(REMOTE_SERVER) \
"docker run --rm -v $(REMOTE_VOLUME_NAME):/volume -v /tmp:/backup alpine tar -czf /backup/$(REMOTE_VOLUME_NAME).tar.gz -C /volume ."
@echo "Step 2: Copy the media from remote volume to local volume"
scp -P $(REMOTE_PORT) $(REMOTE_USER)@$(REMOTE_SERVER):/tmp/$(REMOTE_VOLUME_NAME).tar.gz /tmp/$(REMOTE_VOLUME_NAME).tar.gz
docker run --rm -v /tmp:/volume -v $(LOCAL_VOLUME_NAME):/backup alpine tar -xzf /volume/$(REMOTE_VOLUME_NAME).tar.gz -C /backup
@echo "Step 3: Cleanup temporary files"
rm /tmp/$(REMOTE_VOLUME_NAME).tar.gz
@echo "Media synchronization complete."