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} +