From e346527df77f043b4fbfc011ed121b2c437abb97 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Tue, 5 Sep 2017 15:48:15 +0200 Subject: [PATCH] update old backup delete --- backup/backup.sh | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) 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}