backup.sh: Clean up junk if tar creation fails
authorMegaBrutal <code+git@megabrutal.com>
Thu, 20 Aug 2015 05:31:48 +0000 (07:31 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Thu, 20 Aug 2015 05:31:48 +0000 (07:31 +0200)
If the file system gets full during tar creation, and the junk files (SQL dumps, partial TAR) stay there, the file system is left with 100% usage.
This may have very unpleasant consequences, so it's best to simply remove those files.

modified:   mysql/backup.sh

mysql/backup.sh

index a68853f7b8a37a0ba18965f9731bf52c7318f3a9..5040f3fccad94eb4d52541dbd30811736b06d1a6 100755 (executable)
@@ -49,5 +49,8 @@ then
        done
 else
        echo "Failed to create archive: ${tarname}."
        done
 else
        echo "Failed to create archive: ${tarname}."
+       echo "Cleaning up..."
+       cd ${stordir}
+       rm -rv ${tempdir}
        exit 1
 fi
        exit 1
 fi