From a215d41ec35defe67d9f1c8d659a7887108c7dfc Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sun, 28 May 2017 00:51:23 +0200 Subject: [PATCH] finish backup-script for export/import data --- .gitignore | 5 ++--- backup/backup.sh | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 2f9baf4..54262ee 100644 --- a/.gitignore +++ b/.gitignore @@ -44,14 +44,13 @@ Thumbs.db /public resource/ - -backup/collections/ +mongodb-data/ +backup/ .idea/ node_modules */nbproject* .npm/ -mongodb-data/ .bash_history .bash_logout .bashrc diff --git a/backup/backup.sh b/backup/backup.sh index a85aac4..cba27ee 100755 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -1,13 +1,18 @@ #!/bin/bash +# array of available collection names col=(app_user awarding decoration rank squad user) for i in "${col[@]}" do - if [ "$1" == "restore" ] + # provide date for restore process, if data import is needed + if [ -z "$1" ] then - mongoimport --db cc --collection $i --file collections/${i}.json + mongoexport --db cc --collection $i --out $(date '+%Y-%m-%d')/collections/${i}.json; + cp -R ../api/resource $(date '+%Y-%m-%d')/ else - mongoexport --db cc --collection $i --out collections/${i}.json; + mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json + rm -rf ../api/resource + cp -Rv ${1}/resource ../api/ fi done