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