Restore Backup with huge (sparse) files

Is there a way to restore sparse files in a backup? I need to restore a backup where there are huge sparse database files? So far I only read „strange“ discussions about how to implement sparse file support so that the „sparse-ness“ is exactly restored (which is not the point IMHO). I just want to restore files in a backup that are larger than the diskspace I can provide.
Also, to not get into this situation in the first place, it would be helpful if Restic aborted a backup where there are files that can not be restored :-/ (e.g. check whether they are sparse).

You could probably give the old PR Write sparse files in restorer by greatroar · Pull Request #2601 · restic/restic · GitHub a try. That’s just a hacky workaround, but as the repository format of restic hasn’t changed, that PR should still work.

As we don’t know how much space is available on restore, it’s pretty much impossible to tell beforehand whether a sparse file could be restored without sparseness or not.

This wont help you now, but if restoring sparse files is important to you, you may want to consider using Kopia instead of Restic to backup your files. Kopia supports sparse restores.

Thanks a lot, this version did do it. Why on earth is this PR not merged into main?

For anyone who faces the same problem and maybe can not use this version, here is a tip that might work: I added a small disk, just large enough to hold the real data of the files. Formatted the filesystem with ZFS with deduplication enabled, then restore the file there. Restic keeps on reading the same deduplicated block of nulls, hammers TBs of nulls into ZFS which then deduplicates the stream. After restoring the file then copy the file with any of the standard tools that support sparse files like „cp“ or „rsync“ to the original place (eg „cp —sparse=always“).

BTW, I would wish Restic would handle it exactly like rsync: „-S: turn sequences of nulls into sparse blocks“. Would even help to save disk space on any file.

Thanks, I will definitely give it a try!

We originally planned to restore sparse files such that the sparse parts after restoring are exactly those of the original file. That however complicates the whole process.

I’ll probably revive the mentioned PR in the form of a restore --sparse option.

3 Likes

As much as I love the idea of restoring everything as identically as possible, I wonder if it wouldn’t make more sense to borrow rsync’s --sparse command which seems to just turn sequences of nulls into sparse blocks rather than mirroring the original file exactly.

There might be edgecases where this is worse, but off-hand I can’t think of any at this moment, and it feels simpler than storing details about sparse blocks and restoring that.

That’s already implemented in restore: Add support for sparse files by MichaelEischer · Pull Request #3854 · restic/restic · GitHub .