From f3c1c9a92a682f2115fd4fe5d77c645ffadc9b32 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sun, 27 Aug 2017 15:33:04 +0200 Subject: [PATCH] Fix backup script --- backup/backup.sh | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/backup/backup.sh b/backup/backup.sh index 3acebd1..02c9a4e 100755 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -16,24 +16,36 @@ deleteOldest() { # array of available collection names col=(app_user awarding decoration rank squad user promotion player war) +if [ -z "$1" ] + then + DATE=$(date '+%Y-%m-%d') + cp -R ../api/resource ${DATE}/ + else + DATE=${1} + tar -xzf ${DATE}.tar.gz + rm -rf ../api/resource + cp -Rv ${DATE}/resource ../api/ + +fi + for i in "${col[@]}" do # provide date for restore process, if data import is needed if [ -z "$1" ] then - DATE=$(date '+%Y-%m-%d') mongoexport --db cc --collection $i --out ${DATE}/collections/${i}.json; - cp -R ../api/resource ${DATE}/ - tar -zcf ${DATE}.tar.gz ${DATE} - rm -R ${DATE} if [ $(ls -l | grep -c ^d) -gt 5 ]; then deleteOldest fi else - tar -xzf ${1}.tar.gz mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json - rm -rf ../api/resource - cp -Rv ${1}/resource ../api/ - rm -R ${1} fi done + +if [ -z "$1" ] + then + tar -zcf ${DATE}.tar.gz ${DATE} +fi + +#rm -rf ${DATE} +