Skip to content

Commit d0b269a

Browse files
committed
Check for free space before migrating
1 parent 26f10d7 commit d0b269a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

migrate.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,28 @@ assert_running_as_root() {
295295
fi
296296
}
297297

298+
assert_enough_disk_space() {
299+
local SANDSTORM_CONF="${SANDSTORM_CONF:-/opt/sandstorm/sandstorm.conf}"
300+
local SANDSTORM_DIR
301+
SANDSTORM_DIR=$(dirname "$SANDSTORM_CONF")
302+
303+
# df -k reports available space in 1KB blocks; convert to GB for the comparison.
304+
local AVAILABLE_KB
305+
AVAILABLE_KB=$(df -k "$SANDSTORM_DIR" | awk 'NR==2 {print $4}')
306+
307+
local REQUIRED_KB=$((1024 * 1024)) # 1 GB in KB
308+
309+
if [ "$AVAILABLE_KB" -lt "$REQUIRED_KB" ]; then
310+
local AVAILABLE_MB=$(( AVAILABLE_KB / 1024 ))
311+
fail "E_INSUFFICIENT_DISK_SPACE" \
312+
"Insufficient disk space on the Sandstorm volume ($SANDSTORM_DIR).
313+
Required: 1024 MB
314+
Available: ${AVAILABLE_MB} MB
315+
316+
Please free up disk space before running this migration."
317+
fi
318+
}
319+
298320
assert_user_has_backed_up() {
299321
echo ""
300322
echo "*** IMPORTANT: DATABASE UPGRADE WARNING ***"
@@ -466,6 +488,7 @@ assert_on_terminal
466488
assert_dependencies
467489
assert_sandstorm_installed
468490
assert_running_as_root
491+
assert_enough_disk_space
469492
assert_user_has_backed_up
470493
assert_valid_bundle_file
471494
download_latest_bundle_if_needed

0 commit comments

Comments
 (0)