B
B
BlagoYar Silence2021-06-02 21:49:19
linux
BlagoYar Silence, 2021-06-02 21:49:19

Which is better to use gz or bz2 archive type?

I want to make a backup of the system (Debian 10)
What is better to use to save rights, etc.?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
R
rPman, 2021-06-02
@rPman

In linux, it has historically developed to use tar for archiving, this is probably the most versatile tool, it will allow you to save everything plus even what is not needed.
* to save permissions, you need the -p switch
* to save extended attributes, you need the --xattrs switch
* to detect and save information about leaky files sparse the -S switch
* symbolic links will be saved as links by default, the behavior can be changed in different ways by options (for example, store as a file or, for example, when unpacking, try to create a hardlink instead of a symlink, etc.)
You can then pack the resulting tar archive or better in the process, the -a switch will automatically determine the archiver by extension, whatever. Nobody prevents you from creating an archive without saving it, simply by sending it to nowhere at the time of creation:
tar -cjf /dev/stdout . | wc -c
it will compress bzip2 (key j) of the current directory with subdirectories and send it to the wc command, which will simply calculate its size in bytes and display it on the screen. Repeat the command, changing the j key to J (this is xz), z (this is gzip), etc. and compare the resulting sizes (I advise you to try zstd)
ps as an alternative, you can archive not files, but the entire partition, using the partclone set of utilities (supports everything, even something like ntfs), you can create a copy of the partition in which sectors marked as free will not be saved, while the speed of the utility is comparable to dd (and this is generally just sector-by-sector copying) and in most cases allows you to change the size of the partition to which all this will be restored (rarely with ntfs, but there may be problems when reducing)
pps there are still file system features, for example, btrfs has the ability to get as a file, the difference between the specified snapshots created at different times, and apply it later, at least on a different machine... can also be considered a backup tool

D
Denis Yuriev, 2021-06-02
@dyuriev

In this case (full backups), gzip and bzip2 press a tar file, which is already an uncompressed "archive" of your files with all the attributes (depending on how you set the flags)
So in terms of file permissions and attributes, they are absolutely identical
Subjectively better than gzip
Why can bzip2 is better

  1. bzip2 outperforms gzip by a couple of percent in terms of compression, yes, of course

Why is gzip better?
  1. It is faster in compression (4-6 times faster in synthetic tests on mixed content
  2. The degree of compression has almost no effect on the speed of decompression, there is even an inverse relationship - the stronger the compression, the faster the decompression. Faster than bzip2 for unpacking by 6-10 times.
  3. It is possible to increase the compression/decompression speed by a multiple of the number of cores by using its fully compatible multi-threaded "fork" - pigz instead of gzip (not really a fork, but you get a fully compatible gzip archive as a result).
  4. You can speed up the compression / decompression by another 2-3 times if you get tired and build pigz with zlib-ng / zlib-cf / zlib-intel instead of vanilla zlib 1.2. *

Yes, bzip2 is also multi-threaded, and xz also supports streams in the latest versions out of the box, but their unpacking speed is terrible, and when you need to deploy a backup urgently, you will swear and curse everything and everything
PS: I've played with "effective" compression tools and at the moment I'm waiting for the archive with 200GB of information to be unpacked in order to pull out one single file, so I really went through my sick and relevant question

E
Eugene TI, 2021-06-03
@justhabrauser

Well, in general, total:
1.1. gzip presses faster, bz2 presses harder (all by default). But you have to choose one.
1.2. xz hits the hardest, but you might not wait until retirement.
1.3.. zstd decompresses roughly like gzip (both speed and compression), but decompresses an order of magnitude faster than gzip. But not everywhere is.
2. what is "better" in the characteristics of compressors is missing as a class (although the word best is present in the mana).
3. Compressors have nothing to do with rights.

V
Valdemar Smorman, 2021-06-02
@smorman

.gz
IMHO...

L
Lynn "Coffee Man", 2021-06-02
@Lynn

Neither will retain rights and all that

X
xotkot, 2021-06-02
@xotkot

to save rights, you can harness rsync or tar, and xz is better for compression,
as an example https://wiki.archlinux.org/title/Rsync#Full_system...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question