Check disk space before restoring backup archives
What does this MR do and why?
Tar-based restores currently start unpacking without checking available disk space. This MR adds a pre-flight check that exits with status 1 before extraction or data restoration if the backup directory has less than three times the selected archive size available. It also stops with a clear error if the archive size or filesystem statistics cannot be read.
The check uses space available to the restore process on the extraction filesystem. BACKUP_SKIP_STORAGE_CHECK=true explicitly bypasses it with a warning; values such as false and 0 keep it enabled. The check applies to full restore operations, including restores of incremental archives. Backup creation, verification, and restores that use already extracted backups retain their existing behavior.
The three-times threshold is an estimate. It does not account for other filesystems or guarantee enough space for decompressed data, so this change mitigates the linked issue without fixing every possible hang after ENOSPC.
References
Related to #591737 (closed)
Screenshots or screen recordings
Not applicable: this change affects the backup restore command and has no UI changes.
How to set up and validate locally
-
Check out this branch in a configured GDK environment.
-
Run the affected specs:
bundle exec rspec -r ./spec/spec_helper \ spec/lib/backup/options_spec.rb \ spec/lib/backup/restore/unpack_spec.rb \ spec/lib/backup/manager_spec.rb \ spec/tasks/gitlab/backup_rake_spec.rbThe specs use small temporary files and controlled filesystem statistics to validate:
- Space below the threshold stops the restore before tar, component restoration, or cleanup. Space at or above the threshold allows extraction.
- The selected archive and filesystem fragment size determine the calculation.
- Boolean parsing, explicit bypass, and filesystem, archive-size, and tar errors preserve the expected behavior.
- A rejected restore releases the PID file; existing archive-selection errors and CREATE/VERIFY behavior remain covered.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.