From 4e8d6b427956f56f0551dfab1dc07b5ae49837ab Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Mon, 9 Oct 2017 19:20:25 +0200 Subject: [PATCH] Secure backup script from deleting by accident --- backup/backup.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backup/backup.sh b/backup/backup.sh index 50452e9..f39eea6 100755 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -16,7 +16,6 @@ if [ -z "$1" ] tar -xzf ${DATE}.tar.gz rm -rf ../api/resource cp -Rv ${DATE}/resource ../api/ - fi for i in "${col[@]}" @@ -39,5 +38,8 @@ if [ -z "$1" ] tar -zcf ${DATE}.tar.gz ${DATE} fi -rm -rf ${DATE} - +# to avoid file deletion, if date to apply is entered with .tar.gz ending +if [[ $1 =~ ^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$ ]] + then + rm -rf ${DATE} +fi