From 93608658a9cb6b75fd73168f4fefcc909eb41b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 5 Jan 2021 04:19:28 +0100 Subject: [PATCH] backup: throttle backup extracting if there is not enough disk space Instead of failing the restore process, pause data extracting, until already extracted data gets processed. This commit implements this for local tar extraction. Extracting data received from a VM is handled in qfile-(dom0-)unpacker, which also has similar feature, turned on in 6338b936e27359a06ba310114a65106fbb838a7d. Fixes QubesOS/qubes-issues#4791 --- qubesadmin/backup/restore.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qubesadmin/backup/restore.py b/qubesadmin/backup/restore.py index fc3aee1..f013047 100644 --- a/qubesadmin/backup/restore.py +++ b/qubesadmin/backup/restore.py @@ -1005,8 +1005,18 @@ class BackupRestore(object): else: backup_stdin = open(self.backup_location, 'rb') + block_size = os.statvfs(self.tmpdir).f_frsize + + # slow down the restore if there is too little space in the temp dir + checkpoint_command = \ + 'while [ $(stat -f --format=%a "{}") -lt {} ]; ' \ + 'do sleep 1; done' \ + .format(self.tmpdir, 500 * 1024 * 1024 // block_size) + tar1_command = ['tar', '-ixv', + '--checkpoint=10000', + '--checkpoint-action=exec=' + checkpoint_command, '--occurrence=1', '-C', self.tmpdir] + filelist