summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-07-25 17:20:43 +0200
committerPierre Schmitz <pierre@archlinux.de>2011-07-25 17:20:43 +0200
commit579993610c0af810051f7ea514dadfa6b616c212 (patch)
treeb264a96b4fa22c8ebe4a7318d649988a9752278b
parentfb28c4fe687548541240894332ea75b4c4820167 (diff)
downloadrepo-tools-master.tar.gz
repo-tools-master.tar.xz
Add script to identify differences between db and filesHEADmaster
-rwxr-xr-xcheckdb32
1 files changed, 32 insertions, 0 deletions
diff --git a/checkdb b/checkdb
new file mode 100755
index 0000000..1736776
--- /dev/null
+++ b/checkdb
@@ -0,0 +1,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