You need to tar a directory that the application writes to constantly. `tar` keeps exiting with 1. How do you handle it?
IntermediateScenarioScenarios: backups, log rotation and housekeeping
Answer
Situation read → GNU tar exits 1 when a file changed while it was being read; exit 2 is a fatal error. Under set -e, exit 1 aborts the backup.
What I'd do →
- Treat 1 as a warning, above 1 as failure:
rc=0 tar --warning=no-file-changed -czf "$tmp" -C / srv/app/data || rc=$? (( rc <= 1 )) || die "tar failed with $rc" (( rc == 1 )) && log WARN "files changed during backup" - For consistency, snapshot first: LVM or ZFS snapshot, EBS snapshot, or the application's own backup command (databases must never be backed up by copying live files).
- Or pause writes briefly (maintenance mode) for small datasets.
Why → A file that changes mid-read may be inconsistent; for logs that is fine, for database files it is corruption.
Interview tip → Mention snapshots as the real fix for consistency, not tar flags.
More on Scenarios: backups, log rotation and housekeeping
Design a nightly backup of `/etc` and application data to S3 with retention.IntermediateWrite the core of a Postgres backup that streams `pg_dump` through gzip to S3 and never uploads an empty dump.IntermediateBackups have "succeeded" every night for a year, but the first real restore failed. How do you make backups trustworthy?Advanced`/var` is 100% full because an app's logs were never rotated, and the app now fails to start. What do you do now, and what do you set up after?BeginnerShould you use `copytruncate` or a `postrotate` signal for an application's logs? How do you decide?Intermediate`/srv/app/releases` has 300 old release directories. Write a cleanup that keeps the newest 5 and never deletes the current release.Beginner