248 points · by goranmoomin · 4y ago · 157 comments
My brother the archaelogical archivist of ancient (~2000 years BCE) mesopotamian artifacts has a lot to say about archival formats. His raw material is mostly fired clay tablets. Those archives keep working, partially, even if broken. That's good, because many of them are in fact broken when found.
But their ordering and other metadata about where they were found is written in archaeologists' notebooks, and many of those notebooks are now over a century old. Paper deteriorates. If a lost flake of paper from a page in the notebook rendered the whole notebook useless, that would be a disastrous outcome for that archive.
A decade ago I suggested digitizing the notebooks and storing the bits on CD-ROMs. He laughed, saying "we don't know enough about the long-term viability of CD-ROMs and their readers."
Now, when they get around it it, they're digitizing the notebooks and storing them on PDFs on backed-up RAID10 volumes. But they're also printing them on acid-free paper and putting them with the originals in the vaults where they store old books.
My point: planning for centuries long archiving is difficult. Formats with redundancy, at least with forward error correction codes, are very helpful. Formats that can be rendered useless by a few bit-flips, not so much.
Most more complex file formats suffer from variant formats. Some, like Markdown and RTF just have multiple versions. Some like TIFF and PDF are envelope formats, so the possible contents of the envelope change over time, introducing incompatibility. Then there is bit-rot as formats go out of use, e.g. .DOC (as opposed to .DOCX).
My own objectives are simple compared to your brother's. I want to preserve simple formatted text files until about 40 year from now, in a way that is likely to allow cut and paste. I started accumulating them about 20 years back. Note that this is before Markdown (which is in any case poor for recording formatting). LaTeX was around and seemed ok in terms of expected lifetime, but is poor for cut and paste because the rendering of a chunk of text depends on instructions which are not local to it. I settled for RTF, which this carries significant long term risk for both compatibility and availability, but is documented well enough that migrating out may be possible.
That's just formatted text. Images have been worse, particularly if you are handling meta-data such as camera characteristics, satellite orientation, etc.
My thought process is that the majority of modern hardware/software RAID solutions don’t do error correction properly. And even assuming something that does actually do checksumming and such semi-properly is employed, I think if we are talking tens or hundreds of years from now, it’ll be nearly impossible to find a compatible hardware card should the ones in use die.
I’m aware it already sucks trying to build a project six months in the future, let alone six or sixty years, but perhaps something purely software-based that does care a ton about integrity, like ZFS, would be the best bet in terms of long-term compatibility of a hard-drive storage solution.
So long as the drives can still be plugged into a system, any system, and even if OpenZFS eventually drops backwards compatibility with the version used to create the pool, it’ll likely still be possible to virtualize whatever version of Linux/BSD/Illumos is compatible with that particular version of ZFS and then import the pool.
However, more than just error correction, we should really try to make formats that are resilient to data corruption. For example, zip files seem much more resilient than gzipped tarballs because each file is compressed separately.
Digital copies are really not that durable, we just sometimes confuse ease of copying with durability. This sometimes helps, but only if you can have distributed copies.
I actually have a personal digitization project for some stuff I've inherited, and it's glad to get a little validation for my strategy.
Basically my plan is to scan the documents/photos, create some kind of printed book with the most important/interesting ones and an index, and have a M-DISC with all the scans in the back.
Thomas Jefferson: "Let us save what remains: not by vaults and locks which fence them from the public eye and use in consigning them to the waste of time, but by such a multiplication of copies, as shall place them beyond the reach of accident."
For read-only long-term filesystem-like archives, use squashfs with whatever compression option is convenient. The cool thing about squashfs is you can efficiently list the contents and extract single files. This is why it's an ultimate best option for long-term filesystem-esque archives.
https://en.m.wikipedia.org/wiki/SquashFS
For everything else, or if you want (very) fast compression/decompression and/or general high-ratio compression, use .zstd.
https://github.com/facebook/zstd
I've used this combination professionally to great effect. You're welcome :)
Incidentally, the author of the head article also disapproves of the format (not compression) design of zstd[1] on the same corruption-resistance grounds (although they e.g. prohibit concatenability), even though to me the format[2] seems much less crufty than xz.
[1] https://lists.gnu.org/archive/html/lzip-bug/2016-10/msg00002...
I wholeheartedly agree! That use-case is not currently covered by any widely known OSS project AFAIK.
I call it SITO and it's based on a stream of messagepack objects. If folks are interested in such a thing, I can post what I have currently of the spec, and I'd love to get some feedback on it.
I agree that TAR is problematic, compression is problematic, and there needs to be a mind towards ECC from the get-go.
I could really use some technical discussion to hammer out some of the design decisions that I'm iffy about, and also hone in on what is essential for the spec. For example, how to handle seek-indexing, and whether I should use named fields vs fixed schema, or allow both.
Like zip/7z (with external error recovery), or maybe RAR (with error-recovery records)
Fast compression or decompression is almost entirely meaningless in that context, and compression ratio is also only of secondary importance.
This is why PDF is still considered the best format for long-term archiving of documents, even though there might be things that compress better (djvu/jp2)
Personally I use 7zip for compression and par2[0] for parity.
0) error-correction (not just detection!)
1) end-to-end encryption
2) deduplication
3) compression
4) cross-platform implementations
5) (at least one) user interface
6) open source
Both Borg [0] and Restic [1] have long standing open issues for error-correction, but seem to consider it off strategy. I find that decision kind of strange, since to me the whole purpose of a backup solution is to restore your system to a correct state after any kind of incident.My current solution is an assembly of shell scripts that combine borg with par2, but I'm rather unhappy with it. For one, I trust my home-brewn solution rather faintly (i.e. similar to `don't roll your own crypto` I think there should be an adagium `don't roll your own back-up solutions`). In addition I think an error-correcting mechanism should be available also for the less technology-savvy.
I mean I can guess it works pretty well for single-bit flips, but how about burst errors, how long can those be? Usually you want to have protection from at least 1 or 2 filesystem blocks, which can be 4 or 8k or even more, depending on the file system. How about repeating error patterns, data deletions, etc.?
What’s the story look like around reading files out of squashfs archives stored in an S3 compatible storage system? Can what you mention above be done with byte range requests versus retrieving the entire object?
"DwarFS compression is an order of magnitude better than SquashFS compression, it's 6 times faster to build the file system, it's typically faster to access files on DwarFS and it uses less CPU resources."
Went ahead and submitted, I think it deserves its own discussion:
Some comment here says that the author of the article disapproves zstd with similar arguments as for xz. Have not verified the claim.
>Xz does not provide any data recovery means
For the common use case of compression a tar archive, this is a critical flaw. One small area of corruption will render the remainder of the archive unreadable.
I don’t know how we found ourselves with the best formats for data recovery/robustness fading into obscurity - i.e lzip and to lesser extent bzip2. The only compressed format left in common use that handles corruption is the hardware compression in LTO tape drives
Because monotonically increasing technological progress is a commonly-believed fairy tale. Nowadays, capabilities are lost as often as they're gained. Either because the people who designed the successor are being opinionated or just focusing on something else.
You can test by intentionally corrupting a .zstd file that was created with checksums enabled and then watch as zstd happily proceeds to decompress it, without any sort of warning. This is the stuff of nightmares.
After all these years, RAR remains the best option for archiving.
echo 'a b c' > test
zstd test
zstdcat test.zst
sed -i s/a/b/g test.zst # corrupt the file on purpose
zstdcat test.zstIt can also compress more than xz with tweaks, though I don't know the compute/memory tradeoffs.
[0] https://archlinux.org/news/now-using-zstandard-instead-of-xz...
Edit to fix typo.
The problem is that xz has kind of horrible performance when you crank it up to the high settings. On the medium settings, you can get the same ratio for much, much less CPU (round-trip) by switching to zstd.
YMMV, use your own corpus and CPU to test it.
$ time xz -9k m4-1.4.19.tar
real 0m2.928s
user 0m2.871s
sys 0m0.056s
$ time zstd -19 m4-1.4.19.tar
real 0m3.411s
user 0m3.380s
sys 0m0.032s
$ ls -l m4-1.4.19.tar*
-rw-rw-r-- 1 john john 14837760 Jul 24 14:40 m4-1.4.19.tar
-rw-rw-r-- 1 john john 1674612 Jul 24 14:40 m4-1.4.19.tar.xz
-rw-rw-r-- 1 john john 1726155 Jul 24 14:40 m4-1.4.19.tar.zst
In this test, XZ was both faster and had better compression than Zstd.I've never tried lzop or met someone who advocated to use it. Needs research, perhaps. Until then I'm healthily skeptical.
I've also used it especially when resources are constrained (low performance CPU, ram, or when executable size really matters)
For a couple of years now I have switched to zstd. It is both fast and well compressed by default in that use case, no need to remember any options.
No, I have NOT done any deeper analysis except a couple of comparisons which I haven't even documented. But they ended up in slight favor of zstd, so I switched. But nothing dramatic making me say forget lzop.
Edit: NOT
Is there a way to extract the files without mounting the filesystem?
I believe 7z can do that as well.
I have never really seen it in the Linux world. There are several alternatives installed in most distros, all except zstd discussed in the article.
Regardless, this is a pretty old article and if you search for it you will find a number of discussions that have already happened about it that all have a bunch of comments.
https://news.ycombinator.com/item?id=20103255
To support resilience, you don’t need an alternative to xz, you need hashes and forward error correction. Specifically, compress your file using xz for high compression ratio, optionally encrypt it, then take a SHA-256 hash to be used for detecting errors, then generate parity files using PAR[1] or zfec[2] to be used for correcting errors.
https://parchive.github.io/doc/Parity_Volume_Set_Specificati...
I don't use par2 right now for backups due to the extra hastle, although I might use par3. It might end up a waste of space, though, since I haven't had an issue with corrupted files in at least 20 years (would be great for optical media that can get scratched).
For the longest term archiving I'm not sure any kind of compression is a good idea, I'd think along the lines of uncompressed copy + parity info in a simple container where all files are contiguous (maybe a raw zip file without compression).
Just use a file system that does proper integrity checking/resilvering. Also use TLS to transfer data over the network.
Storage with integrity checking would be the solution to bitrot, but TFA also seems concerned with "how do you unarchive/recover a random file you found?" which seems a somewhat valid concern.
And xz does have support for integrity checking, so it seems reasonable to have a discussion on whether that is a good support, rather than on whether it should be there at all.
Archives need not only a way to check their integrity but also error correction, which xz does not have.
However, you can easily combine xz with par2, which does provide error correction.
Self-referentially incorruptible data is the standard to beat here, moving the concern to a different layer doesn't increase the efficiency or integrity of the data itself.
It is arguably less efficient, as you now rely on some lower layer of protection in addition to whatever is built into the standard itself.
It is less flexible - a properly protected archive format could be scrawled on to the side of a hill, or more reasonably onto an archive medium (BD-disk), and should be able to survive any file-system change, upgrade, etc. Self-repairing hard drives with multiple redundancies are nice, but not cheap, and not wide-spread.
It also does nothing for actually protecting the data - I don't care how advanced the lower level storage format is, if you overwrite data e.g. with random zeros (conceivable due a badly behaving program with too much memory access, e.g. a misbehaving virus, or a bad program or kernal driver someone ran with root access, also conceivable due to EM interference or solar radiation causing a program to misbehave), the file system will dutifully overwrite the correct data with incorrect data, including updating whatever relevant checks it has for the file. The only way around this is to maintain a historical archive of all writes ever made, and that should be evidently both absurdly impractical (how do you maintain the integrity of this archive? With a self-referentially incorruptible data archive perhaps?) and expensive.
Compared to a single file, which can be backed up, agnostic to the filesystem/hardware/transport/major world-ending events, which can be simply read/recovered, far into the future. There's a pretty clear winner here.
I respectfully disagree. By putting it in the layer below, there is the ability to do repairs.
For example, consider storing XZ files on a Ceph storage cluster. Ceph supports Reed-Solomon coding. This means that if data corruption occurs, Ceph is capable of automatically repairing the data corruption by recomputing the original file and writing it back to disk once more.
Even if XZ were able to recover from some forms of data corruption, is it realistic that such repairs propagate back to the underlying data store? Likely not.
If you can't read the data in question though, you cannot do the repairs, it doesn't matter if you do Reed-Solomon coding or not. You are thinking about coding for the underlying hardware, which is what the data corruption you are talking about is designed to fix - it does not solve the problem for writes coming from above.
To do that, you actually have to decode the data in question and perform a reed-solomon encoding on the actual file inside of the archive, and this only gets worse e.g. if you have nested archives.
If the data is self-referentially repairable, however, it doens't matter if the file gets overwritten with e.g. a cat gif, the format will work around that. The filesystem on the other hand will have written the cat gif to the file and updated the Reed Solomon encoding for your file, assuming (incorrectly) the file writes were valid.
I suppose you could mandate that for any file to be written to your filesystem it must first be completely decompressed, and then store some encoding information alongside the archive, but this would be inefficient to the extreme, since merely copying a file onto the system would mean you have to decompress the file and then checksum it.
At any rate, even if you did decompress the file in question, you have failed to separate the layers like you want to, since now you have mandated the XZ and LZMA algorithms also be baked directly into the filesystem itself.
Better not to needlessly couple the filesystem to some compression algorithm, let the compression system handle its own error correction.
Say you have a file `m4-1.4.19.tar.xz` in your source archive collection. The version I just downloaded from ftp.gnu.org has the SHA-256 checksum `63aede5c6d33b6d9b13511cd0be2cac046f2e70fd0a07aa9573a04a82783af96`. The GNU site doesn't have checksums for archives, but it does have a PGP signature file, so it's possible to (1) verify the archive signature and (2) store the checksum of the file.
If that file is later corrupted, the corruption will be detected via the SHA-256 checksum. There's no reason to worry about whether the file itself has an embedded CRC-whatever, or the behavior with regards to variable-length integer fields. If a bit gets flipped then the checksum won't match, and that copy of the file will be discarded (= replaced with a fresh copy from replicated storage) before it ever hits the XZ code.
If this is how the lzip format was designed -- optimized for a use case that doesn't exist -- it's no wonder it sees basically no adoption in favor of more pragmatic formats like XZ or Zstd.
"Repairing" corrupt archives, as in to get as much as usable data from that archive is a pretty useful thing and I have done it multiple times. For example, an archive can have hundreds of files inside and if you can recover any of them that's better than nothing. It is also one of the reason I still use WinRAR occasionally due to its great recovery record (RR) feature.
>replaced with a fresh copy from replicated storage
Lots of times you don't have other copy.
If you have only one copy of some important file and you discover it no longer matches the stored checksum, then that's not a question of archival, but of data recovery. There's no plausible mechanism by which a file might suffer a few bitflips and be saved by careful application of a CRC -- bitrot often zeros out entire sectors.
A CRC, no, absolutely not. But this is exactly what PAR2 recovery records do, they do it well, and they (or their equivalents) need to be easier to enable in more places.
Setting up a replication and durability scheme is a major pain in the ass. Passing the `--add-recovery-record` switch on the command line is very, very easy, and it is good enough for many cases where "best effort" protection against corruption is all that is needed.
Why shouldn't we try to squeeze the highest rate of data recovery out of the unlikely event that we're left with the only remaining copy if it costs nothing extra (just the choice of one archiver over another)?
Should you choose xz for future archival purposes? No.
Should Debian make an active effort to switch away from xz now? Probably not, as their primary concern is distribution, not archival, and xz is good enough.
Internet connection is so much better now and almost 100% of downloads completed successfully.
The file had been built in Europe and after installing it to a US system we wondered why it did not work.
Haven't seen anything like that for many years so it took us a while to even consider the option that it could be corrupted.
(No, we did not spend any time to check whether corruption showed any interesting pattern like a single bit flip, a block of zeros or anything like that. Transferring it again just did it.)
Error correction and redundancy is essential, which is why I use par2 and dvdisaster on all my archives.
* At the sector level in physical media (tapes, disk drives, flash). The file will be largely intact, but 4- or 8-KiB chunks of it will be zero'd out.
* At the bit level, when copying goes wrong. Usually this is bad RAM, sometimes a bad network device, very occasionally a bad CPU. You'll see patterns like "every 64th byte has had its high bit set to 1".
In both cases, the only practical option is to have multiple copies of the file, plus some checksum to decide whether a copy is "good". Files on disk can be restored from backup, bad copies over the network can be detected by software and re-transmitted.
Well, or FEC blocks (eg, par2). Might be insufficient for the every 64th byte case, but probably enough for a few zeroes sectors.
XZ or not doesn't matter here. Even if you have a completely uncompressed tar file, if you only have one copy of it and lose access to that copy (whether bitrot, or disaster, or software error) then you've lost the data.
Right now, I've personally settled on using the 7z format: https://en.wikipedia.org/wiki/7z
The decompression speeds feel good, the compression ratios also seem better than ZIP and somehow it still feels like a widely supported format, with the 7-Zip program in particular being nice to use: https://en.wikipedia.org/wiki/7-Zip
Of course, various archivers on *nix systems also seem to support it, so so far everything feels good. Though of course having the chance of an archive getting corrupt and no longer being properly able to decompress it and read all of those files, versus just using the filesystem and having something like that perhaps occur to a single file still sometimes bothers me.
Then again, on a certain level, I guess nothing is permanent and at least it's possible to occasionally test the archives for any errors and look into restoring them from backups, should something like that ever occur. Might just have to automate those tests, though.
Yet, for the most part, going with an exceedingly boring option like that seems like a good idea, though the space could definitely use more projects and new algorithms for even better compression ratios, so at the very least it's nice to see attempts to do so!
Sounds like SQlite, yet again: https://www2.sqlite.org/sqlar.html
Who would you be contracting to build a file format?
bsdiff is a generic binary differ that is widely available. Courgette is optimized for executables and has an uncommon build system, but claims to produce files ~85% smaller than bsdiff.
[0] https://www.daemonology.net/bsdiff/
[1] https://www.chromium.org/developers/design-documents/softwar...
Be careful what you wish for! If you care about smaller above all else, there are much better compression schemes nowadays.
NNCP is on the range of practical, and beats LZMA: https://bellard.org/nncp/
If you really want to go crazy, large language models like BLOOM can be repurposed for compression; the Chinchilla paper lists a 0.3 bit-per-byte compression ratio on GitHub code.
Of course, the cost is in GPU hardware, or in time.
But the tradeoff between availability and integrity is different for data transmission than for data archiving. When transmitting data, usually the most important consideration is to avoid undetected errors (false negatives for corruption), because a retransmission can be requested if an error is detected. Archiving, on the other hand, usually implies that if a file is reported as corrupt, "retransmission" is not possible. Obtaining another copy of the file may be difficult or impossible. Therefore accuracy (freedom from mistakes) in the detection of errors becomes the most important consideration.
Part of the issue with archival is transmission. I transmit these files over the internet (github->cloudflare->server) and I haven't seen a single failure of a file to unxz after transmission. This implies that I should see issues... but I really haven't.So using xz may work well for you and using it is not a big deal, but that does not make the format reliable for long term archival and as a sibling wrote, you probably could use lzip instead for the same benefits (and actually saving a few bytes because there are no extraneous headers) but none of the problems discussed in the article.
tar c -C ./build $(BINARY) | gzip -9 - > $(PKG_NAME_GZ)
tar c -C ./build $(BINARY) | xz -z -9e - > $(PKG_NAME)I don't know exactly whether other formats are better for seeking and streaming, but since the baseline is tar, ZPAQ (in the 2.0 spec) is already better as it supports deduplication and files can even be updated append-only, and the compression is not an afterthought wrapped around it but well integrated.
In any case, I don't really bother with compression for my own archival needs. Storage is cheap, and encrypted data is kinda hard to reasonably compress anyway.
OTOH, a limitation of the spec cannot be worked around by any new implementation.
(OT - isn't it generally recommended to compress before encrypting? Encrypting is CPU-intensive so the less you have to encrypt the better, also length can be a side-channel, and don't some encryption methods leak the existence of patterns in the source data which compression will eliminate?)
It is definitely worth it to use a modern compression format. I regularly take backups of one service I run. Originally I used gzip, and then on someone's recommendation I tried zstd. Here are the results:
gzip compression time: 204s
zstd compression time: 19.1s
gzip decompression time: 28.2s
zstd decompression time: 6.4s
gzip compressed size: 3.0GB
zstd compressed size: 1.7GB
I ain't ever going back to gzip, especially when it wastes so much disk space and CPU cycles.> sane world [..] Solaris
...I think we're living in a different world. (:
You are not getting compatibility out of xz, not even with itself, if you cared about maximum compatibility you'd be using zip (understood and supported by all major OS at this point), and it sounds like if you just cared about compression ratio you'd use lzip...
If it was speed, I could see zstd (or maybe bzip2? not sure how it stacks up), or just compatibility with linux/embedded folks, gzip. The use case for XZ seems actually pretty marginally small, its like holding onto .rar files or some obscure file splitting tool...
lzip might get there eventually, but it's not there now. xz has enough usage behind it that I'm not concerned.
bzip2 has enough usage but the compression ratio is worse. zstd has neither the usage nor the ratio.
Compression or not, you can always use an additional tool to produce and store extra parity data which can be used to both correct and repair bit errors, which seems like the correct answer for digital archival.
So I have no idea about all this low level stuff, I just know that zstd is overall better for sysadmins.
But next time I'm doing any sort of scripting that involves compression I'll take a look at squashfs now due to this thread.
While I haven't done intensive research on this, it occurs to me that plastic lasts a long time. Vinyl records are a format that seems fit for long-term archiving. The format is so obvious that it could be reverse engineered by any future civilization.
So at least they'll know something about our taste in music.
Maintainers are free to do whatever they want, even if it doesn't make any sense at all.
Debian uses external cryptographic verification for its packages and apt archives so it does not need additional robustness in the compression format.
Most users of xz probably won't read it and will keep using it. And it's probably fine for most use cases, though lzip would most likely be better in every scenario if available.