summaryrefslogtreecommitdiffstats
path: root/checkdb
blob: 1736776210ed1dc463b8ac9b6a2b95d32d66bd7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

home="$(dirname "${0}")"
target="${home}/repo"
lock='/tmp/mirrorsync.lck'
tmp="$(mktemp -d)"

[ -f "${lock}" ] && exit 1
touch "${lock}"

trap "rm -rf '${lock}' '${tmp}'" EXIT INT TERM

find "${target}" -xtype f -name '*.db' | sort > "${tmp}/dbs"
find "${target}" -xtype f -name '*.files' | sed 's/.files/.db/g' | sort > "${tmp}/files"

if ! diff -q "${tmp}/dbs" "${tmp}/files" >/dev/null; then
	echo "there are db or files missing"
	diff -u "${tmp}/dbs" "${tmp}/files"
	exit 1
fi

for db in $(cat "${tmp}/dbs"); do
	mkdir "${tmp}/dbdir" "${tmp}/filesdir"
	bsdtar xf "${db}" -C "${tmp}/dbdir"
	bsdtar xf "${db/.db/.files}" --exclude '*/files' -C "${tmp}/filesdir"
	if ! diff -Nrq "${tmp}/dbdir" "${tmp}/filesdir" >/dev/null; then
		dbname="${db/${target}\//}"
		diff -Nura --label "${dbname}" "${tmp}/dbdir" --label "${dbname/.db/.files}" "${tmp}/filesdir"
		echo -e "\n\n"
	fi
	rm -rf "${tmp}/dbdir" "${tmp}/filesdir"
done