Skip to content

Commit ecf64a8

Browse files
author
Aleksei Shpakovskii
committed
ENT-4242 Check available disk space before creating backups
None that it doesn't matter if $BACKUP_DIR and state/pg/data are on the same drive or not at this point, because both pg_upgrade and `dump | psql` migration methods require two copies of database (old and new one) being available at the same time.
1 parent 3d72a2d commit ecf64a8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packaging/common/cfengine-hub/preinstall.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ if is_upgrade && egrep '^3\.([6-9]|1[01])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/n
2323
cf_console echo "Old backup in $BACKUP_DIR already exists. Please remove before attempting upgrade."
2424
exit 1
2525
fi
26+
mkdir -p "$BACKUP_DIR"
27+
# Try to check if free space on $BACKUP_DIR drive is not less than $PREFIX/state/pg/data contains
28+
if command -v df >/dev/null && command -v du >/dev/null && command -v awk >/dev/null; then
29+
# we have enough commands to test it
30+
megabytes_free="$(df -PBM $BACKUP_DIR | awk 'FNR==2{gsub(/[^0-9]/,"",$4);print $4}')"
31+
megabytes_need="$(du -sBM $PREFIX/state/pg/data | awk '{gsub(/[^0-9]/,"",$1);print $1}')"
32+
if [ "$megabytes_free" -le "$megabytes_need" ]; then
33+
cf_console echo "Not enough disk space to create DB backup:"
34+
cf_console echo "${megabytes_free}M available in $BACKUP_DIR"
35+
cf_console echo "${megabytes_need}M used by $PREFIX/state/pg/data"
36+
cf_console echo "Please free up some disk space before upgrading or disable upgrade by removing/renaming $PREFIX/state/pg/data prior to upgrade."
37+
exit 1
38+
fi
39+
fi
2640
cf_console echo "Attempting to migrate Mission Portal database. This can break stuff."
2741
cf_console echo "Copy will be created in $BACKUP_DIR dir."
2842
cf_console echo "It can be disabled by shutting down CFEngine and removing/renaming $PREFIX/state/pg/data prior to upgrade."

0 commit comments

Comments
 (0)