Custom script examples
AutoRPO's built-in checks tell you a restored server starts and its services, databases and apps answer. Only you know what your data should look like. These four scripts check that. Copy one into a VM's Script box, set the level to Health checks and a custom script, and change the settings at the top to suit your server.
Each was tested on 12–13 Nov 2026 through AutoRPO itself: restored copies of a Debian 13 server running PostgreSQL 17 and a small shop app, once healthy and once broken. Every script passed on the healthy copy and failed on the broken one. On the broken copy AutoRPO's built-in checks all passed, and the app's health page still said "ok".
They run as root on the isolated, throwaway copy. Nothing they do reaches your production server.
Orders are recent #
Catches a backup of a server that had quietly stopped working: a database replica that stopped syncing, or an app that stopped saving orders. It compares the newest order with the backup's time, so orders the copy takes after it starts don't count.
| Healthy copy | Broken copy |
|---|---|
| Pass: Newest order is 0.0 hours older than the backup | Fail: Newest order is 72.3 hours older than the backup (limit 2) |
#!/bin/sh
# name: Orders are recent
# version: 1
# description: The newest order taken before the backup is no more than 2 hours older than the backup.
# timeout: 60
# Catches a backup of a server that had quietly stopped working: a replica that stopped syncing, or an app that
# stopped saving orders. Orders added after the copy started don't count.
MAX_HOURS=2
DB=shop
result() { echo "AUTORPO-RESULT: {\"version\": 1, \"checks\": [{\"name\": \"Orders are recent\", \"status\": \"$1\", \"detail\": \"$2\"}]}"; }
case "$AUTORPO_BACKUP_TIME" in
[0-9][0-9][0-9][0-9]-*) ;;
*) result skip "No backup time given"; exit 0 ;;
esac
hours=$(runuser -u postgres -- psql -XAtq -d "$DB" -c "
SELECT round(extract(epoch FROM '$AUTORPO_BACKUP_TIME'::timestamptz - max(created_at)) / 3600, 1)
FROM orders WHERE created_at <= '$AUTORPO_BACKUP_TIME'::timestamptz") || { result fail "Couldn't query the $DB database"; exit 1; }
if [ -z "$hours" ]; then
result fail "No orders before the backup"; exit 1
elif awk "BEGIN { exit !($hours > $MAX_HOURS) }"; then
result fail "Newest order is $hours hours older than the backup (limit $MAX_HOURS)"; exit 1
fi
result pass "Newest order is $hours hours older than the backup"
Key tables have enough rows #
AutoRPO fails a table that had rows at the last passed test and has none now. This catches one that's lost part of its rows, using minimums you choose, because only you know how big your tables should be. Each table is its own result row.
| Healthy copy | Broken copy |
|---|---|
| Pass: Table orders: 1014 rows (at least 900) Pass: Table customers: 100 rows (at least 95) |
Fail: Table orders: 603 rows, fewer than the 900 expected Pass: Table customers: 100 rows (at least 95) |
#!/bin/sh
# name: Key tables have enough rows
# version: 1
# description: Each listed table has at least the number of rows you set.
# timeout: 120
# AutoRPO flags a table that's become empty. This catches one that's lost part of its rows, using minimums you
# choose, because only you know how big your tables should be. One result row per table.
DB=shop
MINIMUMS="orders:900 customers:95"
checks=""; failed=0
add() { checks="$checks${checks:+, }{\"name\": \"$1\", \"status\": \"$2\", \"detail\": \"$3\"}"; }
for pair in $MINIMUMS; do
table=${pair%%:*}; min=${pair#*:}
n=$(runuser -u postgres -- psql -XAtq -d "$DB" -c "SELECT count(*) FROM $table" 2>/dev/null)
if [ -z "$n" ]; then
add "Table $table" fail "Couldn't count its rows"; failed=1
elif [ "$n" -lt "$min" ]; then
add "Table $table" fail "$n rows, fewer than the $min expected"; failed=1
else
add "Table $table" pass "$n rows (at least $min)"
fi
done
echo "AUTORPO-RESULT: {\"version\": 1, \"checks\": [$checks]}"
exit $failed
Data files match the manifest #
Catches data files that were deleted, truncated or changed. It needs a nightly job on the production server that records a checksum of each file (shown in the script), so the backup carries a list to check the copy against. It suits folders whose files don't change once written, such as scans, exports, archives and uploads.
| Healthy copy | Broken copy |
|---|---|
| Pass: Manifest: Written 2026-11-12 Pass: Data files: All 50 present and unchanged |
Pass: Manifest: Written 2026-11-12 Fail: Files missing: file3.bin file7.bin Fail: Files changed or truncated: file12.bin |
#!/bin/sh
# name: Data files match the manifest
# version: 2
# description: Every file listed in the nightly manifest is present, not empty, and unchanged.
# timeout: 300
# Needs a nightly job on the production server that records a checksum of each file, for example in /etc/cron.d:
# 30 1 * * * root cd /srv/data && find . -type f ! -name 'SHA256SUMS*' -printf '%P\0' | sort -z | xargs -0 sha256sum > SHA256SUMS.new && mv SHA256SUMS.new SHA256SUMS
# Suits folders whose files don't change once written: scans, exports, archives, uploads.
DIR=/srv/data
MANIFEST=SHA256SUMS
MAX_AGE_DAYS=2
checks=""; failed=0
add() { checks="$checks${checks:+, }{\"name\": \"$1\", \"status\": \"$2\", \"detail\": \"$3\"}"; }
finish() { echo "AUTORPO-RESULT: {\"version\": 1, \"checks\": [$checks]}"; exit $failed; }
cd "$DIR" 2>/dev/null || { add "Data folder" fail "$DIR isn't there"; failed=1; finish; }
if [ ! -s "$MANIFEST" ]; then add "Manifest" fail "No $MANIFEST in $DIR"; failed=1; finish; fi
if [ -n "$(find "$MANIFEST" -mmin +$((MAX_AGE_DAYS * 1440)))" ]; then
add "Manifest" fail "$MANIFEST is more than $MAX_AGE_DAYS days old: is the nightly job still running?"; failed=1
else
add "Manifest" pass "Written $(date -r "$MANIFEST" +%Y-%m-%d)"
fi
bad=$(sha256sum -c "$MANIFEST" 2>/dev/null | grep -v ': OK$')
list() { echo "$bad" | sed -n "s/: $1\$//p" | head -5 | paste -sd ' ' -; }
missing=$(list 'FAILED open or read'); changed=$(list 'FAILED')
if [ -n "$missing" ]; then add "Files missing" fail "$missing"; failed=1; fi
if [ -n "$changed" ]; then add "Files changed or truncated" fail "$changed"; failed=1; fi
[ -z "$bad" ] && add "Data files" pass "All $(wc -l < "$MANIFEST") present and unchanged"
finish
The app's API answers #
A server can start with every service running while the app behind it can't find its data. This asks the app two read-only questions, on the copy itself: is its health page ok, and does it return a record that should always be there. Pick a record your app has had for years, such as the first customer or order. On the broken copy the health page still said ok, but the record was gone.
| Healthy copy | Broken copy |
|---|---|
| Pass: Health page: HTTP 200 Pass: Known record: /api/orders/1 returned HTTP 200 |
Pass: Health page: HTTP 200 Fail: Known record: /api/orders/1 returned HTTP 404 |
#!/bin/sh
# name: The app's API answers
# version: 1
# description: The app's health page says ok and its API returns a record that should always be there.
# timeout: 30
# Read-only: two GET requests to the app on the copy itself. Nothing is created or changed.
API=http://127.0.0.1:8090
RECORD=/api/orders/1
checks=""; failed=0
add() { checks="$checks${checks:+, }{\"name\": \"$1\", \"status\": \"$2\", \"detail\": \"$3\"}"; }
code=$(curl -s -o /dev/null -m 10 -w '%{http_code}' "$API/healthz")
if [ "$code" = 200 ]; then add "Health page" pass "HTTP 200"
else add "Health page" fail "HTTP $code"; failed=1; fi
code=$(curl -s -o /dev/null -m 10 -w '%{http_code}' "$API$RECORD")
if [ "$code" = 200 ]; then add "Known record" pass "$RECORD returned HTTP 200"
else add "Known record" fail "$RECORD returned HTTP $code"; failed=1; fi
echo "AUTORPO-RESULT: {\"version\": 1, \"checks\": [$checks]}"
exit $failed
Writing your own #
- Start from the example closest to what you need; the format is in Custom scripts.
- Test the script on a restored copy first:
sh script.sh; echo $?. - Keep checks read-only: look things up, don't create or change records. Use short timeouts: 5 minutes at most
(
# timeout:1 to 300), and keep scripts under 16 KB. - Report one result per thing you check, with a detail that says what was found, not only that it failed.