Skip to content
Snippets Groups Projects
Commit fc10378f authored by Steffen Vogel's avatar Steffen Vogel :santa_tone2:
Browse files

add backup of data volumes to sample-data.sh

parent 172bea13
No related branches found
No related tags found
No related merge requests found
Pipeline #71202 failed
#!/bin/sh
set +e
ACTION=${1:-restore}
FILE=${2:-VILLAS.mongoarchive}
FILE=${2:-VILLAS.zip}
NAME=$(basename $(pwd))
VOLUME="${NAME}_files"
VOLUME_PATH=$(docker volume inspect ${VOLUME} | jq -r .[0].Mountpoint)
DOCKEROPTS="--interactive --tty --rm --network ${NETWORK} --volume $(pwd):/tmp"
TEMP_PATH=$(mktemp -d)
echo "Temp path: ${TEMP_PATH}"
echo "Volume path: ${VOLUME_PATH}"
case ${ACTION} in
restore)
tar -C ${TEMP_PATH} -x -v -f ${FILE}
docker-compose exec database mongo VILLAS --eval "db.dropDatabase()"
docker-compose exec -T database mongorestore --archive < ${FILE}
docker-compose exec -T database mongorestore --archive < ${TEMP_PATH}/database.mongoarchive
if [ -f ${TEMP_PATH}/files.tar.gz ]; then
rm -rf ${VOLUME_PATH}/*
tar -C ${VOLUME_PATH} -x -z -v -f ${TEMP_PATH}/files.tar.gz
fi
;;
dump)
# docker exec mangles stdout and stderr output. So we must use --quiet
docker-compose exec -T database mongodump --archive --quiet > ${FILE}
docker-compose exec -T database mongodump --archive --quiet > ${TEMP_PATH}/database.mongoarchive
tar -C ${VOLUME_PATH} -c -z -v -f ${TEMP_PATH}/files.tar.gz .
tar -C ${TEMP_PATH} -c -v -f ${FILE} .
;;
*)
......@@ -21,3 +41,4 @@ case ${ACTION} in
;;
esac
#rm -rf ${TMP_PATH}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment