From 2e372d1aaedace0101e1f54d61eb4b8983ee4fe4 Mon Sep 17 00:00:00 2001 From: tobias Date: Tue, 16 Jul 2024 15:34:24 +0200 Subject: [PATCH] Makefile: sync_media --- Makefile | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9c4e0c5..b118f99 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,8 @@ REMOTE_CONTAINER_PATH=/data/db/mongodump LOCAL_PATH=/tmp/mongodump LOCAL_DB=test LOCAL_CONTAINER_NAME=nextload-mongo-1 +REMOTE_VOLUME_NAME = nextload-demo_autonomic_zone_payload_uploads +LOCAL_VOLUME_NAME = nextload_payload_uploads ENV_FILE=.env include $(ENV_FILE) @@ -28,4 +30,20 @@ sync_db: 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) \ No newline at end of file + 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." \ No newline at end of file