Building a Backup Set With tar
Goal
With tar, create a full backup and an incremental backup, and work through exclusion rules, permission preservation, and splitting.
Why it matters
A single tar option changes the restore result. If you include absolute paths without -C, you cannot choose the restore location; if you do not choose, to fit the target server, whether owners are carried over by name or by number (--numeric-owner), owners end up as the wrong accounts; and if you restore without --selinux, the service does not start at all on an SELinux system. And because the snapshot file of --listed-incremental holds the state of the incremental chain, you must keep that file too — if you lose it, the next incremental effectively becomes a full backup.
The final incident happens where split archives are joined back together. Splitting is one line, but joining must meet all three conditions, "every piece, intact, in the original order", and whichever of the three breaks, on the surface it looks the same: "it won't decompress". The hash list the backup server left is the only standard that tells the three apart.
Steps
- Under
/root/bk/src, create the following:app/main.py,app/conf.yaml,data/records.csv,logs/app.log,logs/old.log. Put at least one line in each file, but fill onlydata/records.csvto 200KB or more, with content that does not compress well. In step 7 you split the archive into 64KB pieces, and a file that repeats the same characters shrinks to a few KB when compressed, so you get just one piece. - Create a full backup as
/root/bk/full.tar.gz. Paths inside the archive must start withsrc/(no absolute paths). - Write the number of archive entries as a single line of digits in
/root/bk/count.txt. - Create incremental backups. The snapshot file is
/root/bk/snap.snar. First create/root/bk/inc0.tar.gz, then addsrc/app/new.py, deletesrc/logs/old.log, and create/root/bk/inc1.tar.gz. The entry count ofinc1must be smaller than that ofinc0, and restoring the two incrementals in order in incremental mode must leavenew.pypresent andold.logabsent. - Create a backup that excludes
logs/, as/root/bk/nolog.tar.gz.logsmust not appear in the listing. - Change the permission of
/root/bk/src/app/conf.yamlto640, create a full backup again (/root/bk/perm.tar.gz), and restore it to/root/bk/restore-perm/with permissions preserved. Write the permission of the restored file as a single line of digits in/root/bk/perm.txt. It must be640. - Split
/root/bk/full.tar.gzinto 64KB pieces, save them with the prefix/root/bk/split/full.part(each piece is 65536 bytes, and only the last piece is smaller), then join them back to create/root/bk/rejoined.tar.gz. Its sha256 must match the original. - Incident: raise
incident bk-parts-broken, work out for each set why the archives joined from the pieces of the three sets received offsite (web,db,cfg) will not decompress, then rebuild the three archives in/srv/offsite/rejoined/exactly as the backup server made them. The report is/root/incident/bk-parts-broken/report.txt(candidate codes are in the step description).
Notes
- The paths inside the archive are decided by where you move to and what you include before calling tar. After including, list the contents (
-t) and look at the shape of the paths first. - An incremental is just a matter of passing the same snapshot file every time. A deleted file remains in the incremental as "dropped from the directory listing".
- The suffix at the end of a split piece's name is its order. Whether the rejoined result is the original byte sequence can be confirmed only with a hash.
- Common mistake 1: if you delete the snapshot file every time in step 4, every run remains a full backup.
- Common mistake 2: if you leave out the permission-preserving option when restoring in step 6, the umask is applied and the value differs.
- Incident tools:
incident listshows the list, andincident show <이름>(name) shows the ticket (a colleague's report) again. Raising the same incident again returns it to its original broken state. - Write the report to
/root/incident/<이름>/report.txt(name is the incident name): one line<이름>: <원인 코드>(name: cause code) per target, plusevidence: <관찰한 출력 한 줄>(one line of output you observed). The evidence line is checked against the output actually seen in the incident. - Grading does not look only at the report. The actual state of what you restored, such as hashes, ownership, and modes, must be right, and workarounds that only erase the symptom fail.
Create the backup source
Under /root/bk/src, create the following: app/main.py, app/conf.yaml, data/records.csv, logs/app.log, logs/old.log. Put at least one line in each file, but fill only data/records.csv to 200KB or more, with content that does not compress well. In step 7 you split the archive into 64KB pieces, and a file that repeats the same characters shrinks to a few KB when compressed, so you get just one piece (the grader actually compresses that file and checks the size).
Mixing subdirectories and logs gives the exclusion rule in a later step something to act on. Data made by turning random bytes into characters (base64) hardly compresses at all.
Full backup
Create a full backup as /root/bk/full.tar.gz. Paths inside the archive must start with src/ (no absolute paths).
There is an option that keeps absolute paths out of the archive. That is what lets you choose the restore location.
Check the listing
Write the number of archive entries as a single line of digits in /root/bk/count.txt.
There is an option that shows the contents without extracting. Count the entries and write the count to the file.
Two incremental backups
Create incremental backups. The snapshot file is /root/bk/snap.snar. First create /root/bk/inc0.tar.gz, then make two changes to the source (add src/app/new.py, and delete src/logs/old.log as log rotation would) and create /root/bk/inc1.tar.gz. The entry count of inc1 must be smaller than that of inc0, and restoring the two incrementals in order in incremental mode must leave new.py present and old.log absent (the grader actually extracts them).
The snapshot file holds the state. If you keep using the same snapshot file, the incremental chain continues. A deleted file remains in the incremental not as content but as "dropped from the directory listing"; this is where the reason to restore in order in bk-restore comes from.
Apply an exclusion rule
Create a backup that excludes logs/, as /root/bk/nolog.tar.gz. logs must not appear in the listing.
You can specify exclusion patterns multiple times or read them from a file. That entry must not appear in the resulting listing.
Check permission preservation
Change the permission of /root/bk/src/app/conf.yaml to 640, create a full backup again (/root/bk/perm.tar.gz), and restore it to /root/bk/restore-perm/ with permissions preserved. Write the permission of the restored file as a single line of digits in /root/bk/perm.txt. It must be 640.
There is an option that restores permissions and owners exactly. Do not guess: read the actual permissions of the restored file and compare them with the original.
Split and rejoin the archive
Split /root/bk/full.tar.gz into 64KB pieces, save them with the prefix /root/bk/split/full.part (each piece is 64KiB, that is 65536 bytes, and only the last piece is smaller), then join them back to create /root/bk/rejoined.tar.gz. Its sha256 must match the original.
There is a tool that splits a file given a piece size, and the suffix at the end of each piece's name determines the order. Joining back is concatenation (cat), and whether the joining order is the original order can be confirmed only with a hash.
Incident: after joining the pieces received offsite, none of the three archives decompress
Running incident bk-parts-broken raises the incident (read the ticket first). Symptom: /srv/offsite/rejoined/<세트>-1104.tar.gz (set), made by concatenating the pieces of the three sets web, db, and cfg received from offsite site A (/srv/offsite/incoming/<세트>/), all fail the compression check. Find the cause for each set and rebuild the three archives in rejoined/ as exactly the byte sequence the backup server made. Only read the site B copy (/srv/offsite/site-b); do not modify it. In /root/incident/bk-parts-broken/report.txt, write three lines, web: <코드>, db: <코드>, and cfg: <코드> (code), plus evidence: <관찰한 출력 한 줄> (one line of output you observed). Each set's code is one of the following: glob-order (the order the pieces were joined in differs from the original order), missing-part (one piece is missing), text-mode (bytes changed due to a text-mode transfer), truncated-part (one piece was cut off midway and is short).
Direction: "the joined result is wrong" means either a piece itself is wrong, or the pieces are right but the way of joining is wrong. For each set, tell these two apart first. Tools: sha256sum -c (checking against a hash list), ls and stat (sizes), sort's version sort, gzip -t, cmp. Concretely: the SHA256SUMS that came with each set has the hashes of both the whole archive and every single piece. Look at whether each piece is OK, FAILED, or missing, and for a set whose pieces are all OK, look at the order in which the shell's glob expands those names.