44 lines
912 B
Bash
Executable File
44 lines
912 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# execute script in its location folder
|
|
cd $(dirname $0)
|
|
|
|
# array of available collection names
|
|
col=(app_user awarding decoration rank squad user promotion player war campaign)
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
DATE=$(date '+%Y-%m-%d')
|
|
mkdir -p ${DATE}/resource
|
|
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
|
|
mongoexport --db cc --collection $i --out ${DATE}/collections/${i}.json;
|
|
else
|
|
mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json
|
|
fi
|
|
done
|
|
|
|
if [ $(ls -lt --hide=backup.sh | wc -l) -gt 6 ]; then
|
|
$(rm "$(ls -t --hide=backup.sh | tail -1)")
|
|
fi
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
tar -zcf ${DATE}.tar.gz ${DATE}
|
|
fi
|
|
|
|
rm -rf ${DATE}
|
|
|