Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When using the tar utility to store files in backups one loses the extended ACLs.

Is there some commonly used and not hackish solution (like: create a script that will recrate the ACLs from scratch) to preserve the ACLs?

share|improve this question
    
See also this duplicate question. –  Totor Apr 22 '13 at 15:16
add comment

7 Answers

Actually, I believe the question was not about the (standard) file permission bits, but extended ACL information (see setfacl(1) or acl(5)).

To my knowledge, the unmodified GNU tar ignores ACL information. (The man page for GNU tar 1.15.1 as shipped with RHEL 5.2 mentions switches --acls and --no-acls, but I haven't gotten them to work.)

However, the star program is able to back up and restore ACLs, if you select the exustar format:

star -c -p -acl artype=exustar -f archive.tar  files...
star -x -acl -f archive.tar

Star home page: http://cdrecord.berlios.de/new/private/star.html Star is available in ubuntu, at least.

share|improve this answer
    
This looks like what I seek, I will have to take a look on that. Now I need to buy some more hours per day ;) –  silk Sep 6 '10 at 10:29
    
star is not available on Debian and does not seem to be maintained by a "team". The project is still alive and maintained after 30+ years though. Try bsdtar if you want something else. –  Totor Apr 22 '13 at 15:35
add comment

If you're looking for a simple-to-use yet powerful solution, I'd recommend rdiff-backup.

Basically, it makes a copy of a source directory to a destination directory but it also saves additional information so you can go back in time to whenever you want.

And, of course, it preserves symlinks, special files, hardlinks, permissions, uid/gid ownership and modification times.

share|improve this answer
add comment

From the tar Man Page.

-p, --same-permissions, --preserve-permissions
             ignore umask when extracting files (the default for root)

It is not actually the act of archiving that alters the access permissions(ACLs), but the act of unpacking them. Tar is very often used to distribute files from one user to another, and so it is thought convenient to apply a users umask when they unpack.

To preserve the files previous permissions, simply ad a p for to your options. For example

Straight tar:

tar xvp some-file

bz.tar:

tar xvjp some-file

gz.tar:

tar xvzp some-file
share|improve this answer
2  
-1: -p does not preserve extended ACLs, so this answer is wrong. I recommend testing solutions before posting answers :) –  silk Sep 6 '10 at 10:09
    
this does not work. –  maniat1k Feb 20 '13 at 11:58
    
Furthermore tar automatically figures out what to extract. There is no need to pass 'j' or 'z'. –  Good Person Dec 11 '13 at 14:46
add comment

I'm looking for a solution as well so far I found this:

first do a getfactl from my folder

getfacl -R /a_folder > folder.acl

then do a regular tar

tar -czvf folder.tar.gz /a_folder

when I extract it

tar -xvf folder.tar.gz

do a setfacl for the permissions.

setfacl --restore=folder.acl

this works for me.

share|improve this answer
add comment

I suggest you to use bsdtar.

bsdtar backups extended ACL by default, it uses the same syntax as GNU tar, and the archives it produces are readable by GNU tar.

The package and command name (under Debian based distributions) is bsdtar.

bsdtar cf archive.tar /my/folder/using/extd_acl 
bsdtar xf archive.tar 

The 2nd (extract) command restores ACLs.

share|improve this answer
    
I can't get it to work, even though I'm sure it worked some time ago. Filed a bug, code.google.com/p/libarchive/issues/detail?id=329 . –  Ambroz Bizjak Jul 27 '13 at 18:30
add comment
rsync with the -A and/or -X options.
share|improve this answer
add comment

Using tar

To create:

tar --acls -cpf backup.tar some-dir-or-file

To untar:

tar --acls -xpf backup.tar
share|improve this answer
2  
tar: unrecognized option '--acls' does not work. –  maniat1k Feb 20 '13 at 12:04
    
Fedora has non-standard GNU Tar patches that include --acls –  user55149 Dec 22 '13 at 10:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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