Hi,

I am using Kernel 5.15.* Linux, tested both ext4 and btrfs using GNU tar 1.30 
or latest 1.35.

tar 1.35 is compiled from source. The configure line is: ./configure 
--enable-acl --enable-backup-scripts --with-posix-acls --with-selinux 
--with-xattrs

I want use tar to backup files with immutable attribute set by "chattr +i" in 
Linux. Command lines below(on ext4):

mdx@e5450:~$ touch test.txt
mdx@e5450:~$ sudo chattr +i test.txt
mdx@e5450:~$ lsattr test.txt
----i---------e---- test.txt
mdx@e5450:~$ sudo tar --acls --selinux --xattrs --xattrs-include='*' -cpvvzf 
test.tar.gz test.txt
-rw-r--r--  mdx/mdx           0 2024-03-01 16:30 test.txt
mdx@e5450:~$ mkdir test
mdx@e5450:~$ sudo tar --acls --selinux --xattrs --xattrs-include='*' -xpvvzf 
test.tar.gz -C test
-rw-r--r--  mdx/mdx           0 2024-03-01 16:30 test.txt
mdx@e5450:~$ lsattr test/test.txt
--------------e---- test/test.txt
mdx@e5450:~$


You see, the immutable attribute is gone after extracting.


I can use bsdtar 3.3.3 archive test.txt, the immutable attribute will be 
preserved. Detail below:

mdx@e5450:~$ sudo bsdtar -cvvzf test.btar.gz test.txt
a -rw-r--r--  1 mdx    mdx         0 Mar  1 16:30 test.txt
mdx@e5450:~$ mkdir btest
mdx@e5450:~$ sudo bsdtar -xvvzf test.btar.gz -C btest
x -rw-r--r--  0 mdx    mdx         0 Mar  1 16:30 test.txt
mdx@e5450:~$ lsattr btest/test.txt
----i---------e---- btest/test.txt

Is it possible preserve file immutable attribute set by "chattr +i" when using 
GNU tar in Linux? Or add this function into GNU tar?

Reply via email to