Quick question about running prune

I was wondering, let’s suppose a large initial backup takes a while, and is interrupted before it finishes. Then prune is run – no snapshots are deleted, because there aren’t any snapshots yet – will it delete the packs that aren’t (yet) referenced by any index/snapshot? In other words, will it undo the progress of the incomplete initial backup?

I would test this myself but am a little nervous to spend all that time if someone here already knows the answer. :slight_smile: Thanks for any insight!

Yes, it’ll remove all data. At that point, restic prune does not (and can not) know which data is still needed. There’s no snapshot referencing any data, and no indication that a backup is still in progress when there’s no lock file in the repo (or just a stale one, because the upload process was interrupted and does not run any more)…

1 Like

Got it, thanks for the clarification!

One quick follow-up question. From this answer I gather that rebuild-index can help by adding references to the unused data.

If I run rebuild-index before a snapshot is completed, will prune still delete the uploaded data? (assuming the snapshot is not yet finished – and backing up is paused for some reason)

Ah, not exactly: running rebuild-index will make sure that all data which is saved in the repo will be contained in an index file, so on the next run of backup, restic is aware of all the data that is in the repo. Normally, it should not matter and you should not need to run rebuild-index after an aborted upload, but if you have a really tiny upstream bandwidth and would like to avoid uploading even a couple of megabytes of data, then rebuild-index is a good thing here. During backup, restic will regularly upload so-called intermediate index files which cover all the data that has been uploaded so far. So without running rebuild-index after a failed backup restic will only re-upload the data that has been uploaded since the last intermediate index, which is at most 15 minutes (if I remember correctly).

Yes, it will still delete the data. After running rebuild-index, restic is aware that there’s data in the repo, but the data is still not referenced by a snapshot. So prune thinks the data is not needed any more and removes it.

2 Likes

Gotcha, that makes sense, thank you for the detailed explanation! Now I understand the difference between running rebuild-index, and not running it and simply resuming the backup.

My upload is < 1 Mbps at home so it sounds like I will benefit from rebuild-index. :slight_smile:

Just a little bit, at most you’re uploading the data uploaded in the last 15 minutes again, which should not be too bad. If you only have small bandwidth, rebuild-index may take much longer (because it looks at all files in the repo).

1 Like

Hm, good point. Danke!