Fix backup script

feature/user-self-management
Florian Hartwich 2017-08-27 15:33:04 +02:00
parent 8bdc6713b8
commit f3c1c9a92a
1 changed files with 20 additions and 8 deletions

View File

@ -16,24 +16,36 @@ deleteOldest() {
# array of available collection names # array of available collection names
col=(app_user awarding decoration rank squad user promotion player war) 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[@]}" for i in "${col[@]}"
do do
# provide date for restore process, if data import is needed # provide date for restore process, if data import is needed
if [ -z "$1" ] if [ -z "$1" ]
then then
DATE=$(date '+%Y-%m-%d')
mongoexport --db cc --collection $i --out ${DATE}/collections/${i}.json; 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 if [ $(ls -l | grep -c ^d) -gt 5 ]; then
deleteOldest deleteOldest
fi fi
else else
tar -xzf ${1}.tar.gz
mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json
rm -rf ../api/resource
cp -Rv ${1}/resource ../api/
rm -R ${1}
fi fi
done done
if [ -z "$1" ]
then
tar -zcf ${DATE}.tar.gz ${DATE}
fi
#rm -rf ${DATE}