On Thu, Jun 09, 2022 at 11:53:20AM -0400, Matt Barry wrote:
> On Wed, 2022-06-08 at 11:59 +0200, Marc Haber wrote:
> > On Wed, Jun 08, 2022 at 12:34:14AM -0400, Matt Barry wrote:
> > > tags -1 + confirmed patch
> > > thanks
> > 
> > How about zstd and the other hip compressors?
> 
> Heh.  I was thinking about whether to bother with this one.  A couple
> of factors:
> 
> * adding zstd in the same fashion will take ~ 2 minutes
> * there are, imo, no additional algorithms worth considering, so it
> isn't a bottomless well of feature requests
> * I guess the ideal for users would be a config item that controls the
> order of selection:
> 
>       BACKUP_COMPRESS=xz gz zstd  # eg. would never try bzip2
> 
> I can't imagine it getting more complicated than that..

Currently, the code looks like we are choosing the filename and the
method of compression: if bzip2 exists, we use that. Otherwise, if gzip
exists, we use that. Thankfully, we never documented this precedence,
our docs just say that the backup file is called
username.tar(.gz|.bz2).

Christoph suggested using tar's --auto-compress option which
automatically chooses the compress program depeding on the target file's
suffix.

How about doing the following:

- we introduce a new option --backup-suffix, accepting things like
  ".bz2" or "xz"
- we use that to generate the target file name, adding a period if the
  input doesnt start with one
- use tar --auto-compress to create the file

Unfortunately, if tar doesnt recognize the suffix, it'll happily
generate foo.tar.baz as a regular tar archive. Otoh, if a compressor is
selected that is not installed, tar will give a 127 exit code.

I'd recommend the following:

- invoke tar --create --auto-compress --file /tmp/foo.tar.suffix
  --directory / usr/sbin/deluser
- if exit code 127 (compressor known, but not installed):
  - print diagnostic
  - set suffix to ".gz" (gzip is essential and guaranteed to exist)
- if exit code != 127
  - invoke tar --create --file /tmp/foo.tar
    --directory / usr/sbin/deluser
  - check whether foo.tar and foo.tar.sufffix are identical (that
    happens when the tar file suffix does not match a known compressor)
  - if identical (unknown compressor given)
    - print diagnostic
    - set suffix to ".gz"

If there is any better way to find out whether tar has actually printed
a compressed file without creating more dependencies, please, use that.

Greetings
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany    |  lose things."    Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature |  How to make an American Quilt | Fax: *49 6224 1600421

Reply via email to