03 / ACCOUNTS, SERVICES AND JOBS · LESSON 11

Review the latest backup job

Choose the latest job deterministically and distinguish failure, staleness and missing coverage.

16 min · learn at your pace

The latest success can hide the latest failure

A backup dashboard that looks only for successful jobs may keep showing yesterday’s green result after today’s failure. Select the latest job first, then interpret its outcome. This preserves an unsuccessful recent attempt rather than silently falling back to an older success.

The supplied timestamps are integer seconds on a single collection timeline ending at second 10000. No platform-specific date command is needed. Successful jobs at most 3600 seconds old are fresh; older ones are stale. A failed latest job is failed regardless of its age.

Make ties and gaps explicit

When two jobs have the same second, choose the greatest job ID in LC_ALL=C lexical order. Numeric-looking IDs must still be compared as identifiers: lexically 2 sorts after 10. Prefixing both strings inside an awk comparison avoids unintended numeric coercion.

Start from the required asset list, not from jobs, so assets with no observations receive a missing result. Ignore jobs for assets outside that list. Keep the selected job ID and age in the report so someone can review the decision. These exports describe scheduled activity; the script does not install a scheduler or run a backup against a real machine.

Try an example.sh
awk -F '\t' 'NR>1 {printf "%s age=%d\n",$1,10000-$3}' jobs.tsv
YOUR TURN

Put it into practice.

assets.txt lists required unique asset IDs, one per line. jobs.tsv has validated unique job_id<TAB>asset_id<TAB>second<TAB>result rows, with second an integer 0–10000 and result ok or failed. Select each asset’s greatest second, breaking ties by greatest job ID in LC_ALL=C lexical order. Print asset_id<TAB>job_id<TAB>age_seconds<TAB>review sorted by asset ID. A failed latest job is failed; an ok latest job aged >3600 is stale, otherwise ok. No job gives -<TAB>-<TAB>missing. Ignore jobs for unlisted assets.

See an explained solution
One way to solve it.sh
export LC_ALL=C
printf 'asset_id\tjob_id\tage_seconds\treview\n'
awk -F '\t' 'FILENAME==ARGV[1] {assets[$0]=1;next}
FNR>1 && ($2 in assets) {asset=$2;if(!(asset in second) || $3>second[asset] || ($3==second[asset] && ("x" $1)>("x" id[asset]))){second[asset]=$3;id[asset]=$1;result[asset]=$4}}
END {for(asset in assets){if(!(asset in second)){printf "%s\t-\t-\tmissing\n",asset;continue}age=10000-second[asset];state=(result[asset]=="failed"?"failed":(age>3600?"stale":"ok"));printf "%s\t%s\t%d\t%s\n",asset,id[asset],age,state}}
' assets.txt jobs.tsv | sort

The selection step cannot hide a newer failed job behind an older success. Explicit tie-breaking makes equal-time records deterministic, while an asset-first report retains missing backup coverage and the exact freshness boundary.