Fix backup script
parent
8bdc6713b8
commit
f3c1c9a92a
|
@ -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}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue