Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the number of files deleted in a single tarsnap call to 500 #57

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions tarsnapper/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,20 @@ def expire(self, job):
self.log.info('Deleting %s', ' '.join(to_delete))

if not self.dryrun:
self.call('-d', '-f', *' -f '.join(to_delete).split(' '))
for name in to_delete:
self.archives.remove(name)
# group into batches of up to 500 files in a single delete call for
# improved efficiency: https://www.tarsnap.com/improve-speed.html#faster-delete
# 500 is a somewhat arbitrary batch size. The actual restriction is
# typically a bytes limit on the size of the command that the shell
# will accept, which can vary widely across OS flavors. Because
# it's a bytes limit, this is also dependent on the length of the
# backup filenames. So rather than deal with all this complexity,
# 500 was chosen as a reasonable balance between safety and speed.
batch_size = 500
for i in range(0, len(to_delete), batch_size):
batch = to_delete[i:i + batch_size]
self.call('-d', '-f', *' -f '.join(batch).split(' '))
for name in batch:
self.archives.remove(name)

def make(self, job):
now = datetime.utcnow()
Expand Down