Skip to content

Commit

Permalink
nc-restore: Check for free space in $TMPDIR before extracting tar file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanarri authored and nachoparker committed Apr 2, 2019
1 parent 29429f0 commit 41a4e84
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bin/ncp/BACKUPS/nc-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41a4e84

Please sign in to comment.