I want use tar(GNU tar 1.30) to backup files with immutable attribute set by "chattr +i" in Linux. Command lines below:
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?