Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article7 min readViews1

File Restored, Label Gone: Checking xattr in GNU tar Archives

Reproducible GNU tar 1.35 A/B test: file bytes match, but a standard archive loses user xattr. We show a safe testbed, --xattrs parameters, and acceptance criteria.

Comments 0

An archive box with a document and an attached blue metal tag on a light table
In this article

A standard GNU tar archive can restore file bytes while failing to restore extended attributes. If an application or storage policy requires them, create and extract archives with explicit --xattrs, restrict the namespace to what is needed, and verify the label after test restoration. A matching SHA-256 confirms file content but not xattr.

Why a Matching SHA-256 Does Not Close the Question

An extended attribute, or xattr, is a 'name–value' pair associated with a file system object separately from its content. In Linux, attributes are divided into namespaces; for a safe educational test, only the user.* namespace is used. This extended attribute structure is described in the xattr(7) manual page.

A checksum is calculated from file bytes. Therefore, two restored copies may share the same SHA-256 even if one retains user.backup_state and the other does not. These are distinct backup properties and must be verified separately.

What Exactly Was Verified

The test was run on December 4, 2026, in an isolated directory with a controlled path template on Linux 6.18.64 with GNU tar 1.35, Bash 5.2.37, and Python 3.12.16. The fixed script ran twice and completed with exit code 0 both times. It does not access networks, services, or production data.

  • A short training file report.txt is created.
  • Python assigns user.backup_state=checked to it, then immediately reads the value back.
  • One archive is created with standard tar, the second with --xattrs and a user.* filter.
  • Both archives are unpacked into separate new directories; then xattr and SHA-256 are checked separately.

Safe A/B Test

The script writes and deletes data only within the directory returned by mktemp. Variables are defined before use, and trap removes the test environment on normal exit and on error. Run it as a standalone file in a test environment with a file system that supports user xattr.

#!/usr/bin/env bash set -euo pipefail lab_root="${TMPDIR:-/tmp}" lab_dir="$(mktemp -d "$lab_root/xattr-tar.XXXXXX")" cleanup() { case "$lab_dir" in "$lab_root"/xattr-tar.*) rm -rf -- "$lab_dir" ;; *) printf 'cleanup stopped: %s\n' "$lab_dir" >&2; return 1 ;; esac } trap cleanup EXIT source_dir="$lab_dir/source" plain_restore="$lab_dir/plain-restore" xattr_restore="$lab_dir/xattr-restore" plain_archive="$lab_dir/plain.tar" xattr_archive="$lab_dir/xattr.tar" mkdir -p -- "$source_dir" "$plain_restore" "$xattr_restore" printf '%s\n' 'backup payload' > "$source_dir/report.txt" python3 - "$source_dir/report.txt" <<'PY' import errno import os import sys path = sys.argv[1] os.setxattr(path, b"user.backup_state", b"checked") print(os.getxattr(path, b"user.backup_state").decode()) PY tar --create --file="$plain_archive" --directory="$source_dir" . tar --create --xattrs --xattrs-include='user.*' --file="$xattr_archive" --directory="$source_dir" . tar --extract --file="$plain_archive" --directory="$plain_restore" tar --extract --xattrs --xattrs-include='user.*' --file="$xattr_archive" --directory="$xattr_restore" python3 - "$plain_restore/report.txt" "$xattr_restore/report.txt" <<'PY' import errno import os import sys plain_path, xattr_path = sys.argv[1:] try: os.getxattr(plain_path, b"user.backup_state") except OSError as error: if error.errno != errno.ENODATA: raise print(f"plain=user.backup_state missing errno={error.errno}") else: raise AssertionError("plain archive unexpectedly restored user.backup_state") value = os.getxattr(xattr_path, b"user.backup_state") print(f"xattrs=user.backup_state {value.decode()}") assert value == b"checked" PY sha256sum "$source_dir/report.txt" "$plain_restore/report.txt" "$xattr_restore/report.txt"

Save the text as xattr-tar-lab.sh, verify it before running, and execute it as a non-privileged user:

bash xattr-tar-lab.sh

The observed output from two runs matched:

checked plain=user.backup_state missing errno=61 xattrs=user.backup_state checked 77c8166c510ab9bad0a1b1f7a207ef84664aeb9b02daad9c8525030401cb4076 …/source/report.txt 77c8166c510ab9bad0a1b1f7a207ef84664aeb9b02daad9c8525030401cb4076 …/plain-restore/report.txt 77c8166c510ab9bad0a1b1f7a207ef84664aeb9b02daad9c8525030401cb4076 …/xattr-restore/report.txt

Recovery

SHA-256 of content

user.backup_state

Output

Standard tar

Matches

Missing, errno=61

Bytes returned, xattrs not

tar --xattrs

Match

checked

Bytes and verified xattr returned

The errno=61 observation is specific to this Linux test environment: the attribute was not found. In automation, do not transfer numeric codes to another OS without verification; it is more important to distinguish between the expected absence of an attribute and a read error caused by other reasons.

Comparison of two restores: file content matches by SHA-256, but user xattr is preserved only when using tar --xattrs
Training A/B test of GNU tar 1.35: a standard archive returns bytes without user xattr, while explicit --xattrs preserves both properties.

What GNU tar parameters do

GNU tar 1.35 manual states that extended attributes are not preserved by default. The --xattrs parameter enables their processing, while --xattrs-include='user.*' restricts the selected namespace. In the test, these parameters are specified both during archive creation and extraction.

The os.setxattr and os.getxattr functions are used as a verified method to write and read values; their Linux availability is documented in Python 3.12. In a workflow, another verified tool may be used, but it must read the specific attribute name after restoration.

How to Move the Check to a Real Backup

  • Compile a list of the xattrs that are actually needed and determine which service or policy uses them. Do not include all namespaces "just in case".
  • Create a copy of a small representative set using the same GNU tar version and the same parameters as the backup job.
  • Extract the archive into a new empty test directory on the target file system, not over live data.
  • Compare the SHA-256 hashes of the expected files and read each required xattr name against its expected value.
  • Save the tar version, creation and extraction parameters, check output, and exit codes. Any missing or unexpected value halts acceptance of the copy.

If the archive is moved to another server or an object storage, check not only the archive itself but also the final file system after extraction. xattr support, mount policies, and process permissions on the target side may differ.

Result Boundaries

  • The test covers only the user.backup_state attribute from the user.* namespace and does not confirm the preservation of POSIX ACLs, SELinux labels, Linux capabilities, or security.* and trusted.* namespaces.
  • A matching xattr does not prove the completeness of the file set, the consistency of the database dump, or the application's operability.
  • A matching SHA-256 hash does not confirm the archive's authenticity if the checksum could have been replaced along with it.
  • The result applies to GNU tar 1.35 and the Linux test stand; a different tar implementation, file system, or OS requires separate verification.
  • The archive with the required metadata still needs protection against unauthorized reading and modification.

The xattr check complements, but does not replace, comparing the archive with the original directory and SHA-256 integrity verification. These checks answer different questions.

Readiness criterion: the test restore on the target file system completed without error, the expected files have preserved checksums, and every mandatory xattr name was read with the expected value. Only then can the verified portion of metadata be considered recoverable.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.