diff --git a/backup/backup.sh b/backup/backup.sh index a5e848c..50452e9 100755 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -3,16 +3,6 @@ # execute script in its location folder cd $(dirname $0) -deleteOldest() { - line_num=0 - while IFS= read -r -d $'\0'; do - if [ $line_num == 1 ]; then - $(rm -rf ${REPLY}) - fi - ((line_num++)) - done < <(find -maxdepth 1 -type d -print0 | sort -z) -} - # array of available collection names col=(app_user awarding decoration rank squad user promotion player war campaign) @@ -35,14 +25,15 @@ do if [ -z "$1" ] then mongoexport --db cc --collection $i --out ${DATE}/collections/${i}.json; - if [ $(ls -l | grep -c ^d) -gt 5 ]; then - deleteOldest - fi 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}