1

I want to create a tar.gz file of a directory which will be owned by a certain user and group (and not by root, who is creating the archive).

Basically, I want to combine the following to one single step:

tar -cvz -f temp-backup.tar.gz temp/
chown absonegative:absonegative temp-backup.tar.gz

Is that possible in one single pass? I want to avoid that there is a (albeit very small) period in which the file exists as root:root, as my current backup solution has problems with that (I am trying to fix that as well).

Note that I want to retain the ownership of the files inside the archive, as is already covered if you execute tar as root. I only want to alter the ownership of the result.

1
  • @Rinzwind they don't have a duplication problem, they just want to combine the two commands into one :P
    – Thomas Ward
    Feb 5, 2019 at 17:33

1 Answer 1

0

To combine into one step you can do something along the lines of

tar -cvzf - temp/ | su absonegative -c "dd of=temp-backup.tar.gz"

This assumes that the default group of the absonegative account is also absonegative

3
  • I did not know about dd. That's what I need here. I will try it out and let you know. Thank you Doug! Feb 5, 2019 at 17:48
  • What does su: must be run from a terminal mean in this context? I get that when doing the above. Feb 5, 2019 at 17:52
  • There are quite a few hits on this error message if you'll put a little research into it. In the meantime, you can try changing everything to the right of the | to read sudo -u absonegative dd of=temp-backup.tar.gz
    – doneal24
    Feb 5, 2019 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.