diff options
author | Tanarri <Tanarri@users.noreply.github.com> | 2019-03-14 02:03:56 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2019-04-02 03:03:35 +0300 |
commit | 41a4e84a3eab6c0661c860ab2f6cf032cf886add (patch) | |
tree | ba21211c9139f2d318363fdfaf733599de3c9187 /bin/ncp | |
parent | 29429f0c421d28fa93dc05e12359827b470f274b (diff) |
nc-restore: Check for free space in $TMPDIR before extracting tar filev1.10.7
Diffstat (limited to 'bin/ncp')
-rw-r--r-- | bin/ncp/BACKUPS/nc-restore.sh | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/bin/ncp/BACKUPS/nc-restore.sh b/bin/ncp/BACKUPS/nc-restore.sh index df474120..eee58c18 100644 --- a/bin/ncp/BACKUPS/nc-restore.sh +++ b/bin/ncp/BACKUPS/nc-restore.sh @@ -37,10 +37,20 @@ cleanup(){ local RET=$?; echo "Cleanup..."; rm -rf "${TMPDIR}"; trap "" EXIT; e trap cleanup INT TERM HUP ERR EXIT rm -rf "$TMPDIR" && mkdir -p "$TMPDIR" +[[ "$BACKUPFILE" =~ ".tar.gz" ]] && compress_arg="-I pigz" + +# CHECK FREE SPACE IN $TMPDIR +echo "check free space..." # allow at least ~100 extra MiB +extractedsize=$(tar $compress_arg -tvf "$BACKUPFILE" | awk '{s+=$3} END{printf "%.0f", (s/1024)}') # Size of extracted files in "KB" +size=$(($extractedsize + 100*1024)) +free=$( df "$TMPDIR" | tail -1 | awk '{ print $4 }' ) +[ $size -ge $free ] && { + echo "free space check failed. Need $size KB in $TMPDIR"; + exit 1; +} + # EXTRACT FILES echo "extracting backup file $BACKUPFILE..." - -[[ "$BACKUPFILE" =~ ".tar.gz" ]] && compress_arg="-I pigz" tar $compress_arg -xf "$BACKUPFILE" -C "$TMPDIR" || exit 1 ## SANITY CHECKS |