diff --git a/borg/repository.py b/borg/repository.py index 972baab09..87666a573 100644 --- a/borg/repository.py +++ b/borg/repository.py @@ -84,6 +84,12 @@ class Repository: def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is not None: + no_space_left_on_device = exc_type is OSError and exc_val.errno == errno.ENOSPC + # The ENOSPC could have originated somewhere else besides the Repository. The cleanup is always safe, unless + # EIO or FS corruption ensues, which is why we specifically check for ENOSPC. + if self._active_txn and no_space_left_on_device: + logger.warning('No space left on device, cleaning up partial transaction to free space.') + self.io.cleanup(self.io.get_segments_transaction_id()) self.rollback() self.close() @@ -543,7 +549,7 @@ class LoggedIO: return None def get_segments_transaction_id(self): - """Verify that the transaction id is consistent with the index transaction id + """Return last committed segment """ for segment, filename in self.segment_iterator(reverse=True): if self.is_committed_segment(segment): diff --git a/docs/internals.rst b/docs/internals.rst index 9d1bbd84c..1bd14bb1e 100644 --- a/docs/internals.rst +++ b/docs/internals.rst @@ -280,6 +280,7 @@ emptied to 25%, its size is shrinked. So operations on it have a variable complexity between constant and linear with low factor, and memory overhead varies between 33% and 300%. +.. _cache-memory-usage: Indexes / Caches memory usage ----------------------------- diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 81d358d4c..31d2e216b 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -11,11 +11,15 @@ The next section continues by showing how backups can be automated. Important note about free space ------------------------------- -Before you start creating backups, please make sure that there is **always** +Before you start creating backups, please make sure that there is *always* a good amount of free space on the filesystem that has your backup repository -(and also on ~/.cache). It is hard to tell how much, maybe 1-5%. +(and also on ~/.cache). A few GB should suffice for most hard-drive sized +repositories. See also :ref:`cache-memory-usage`. -If you run out of disk space, it can be hard or impossible to free space, +If |project_name| runs out of disk space, it tries to free as much space as it +can while aborting the current operation safely, which allows to free more space +by deleting/pruning archives. This mechanism is not bullet-proof though. +If you *really* run out of disk space, it can be hard or impossible to free space, because |project_name| needs free space to operate - even to delete backup archives. There is a ``--save-space`` option for some commands, but even with that |project_name| will need free space to operate.