Skip to content

Instantly share code, notes, and snippets.

@za3k
Last active August 29, 2015 14:07
Show Gist options
  • Save za3k/f61f657b6ce501294c8a to your computer and use it in GitHub Desktop.
Save za3k/f61f657b6ce501294c8a to your computer and use it in GitHub Desktop.
RESTORE_DIR="/home/zachary/annex-documents-restored"
cat annex-unused-keys | tail -n +4 | head -n -5 | awk -e '{print $2}' | while read shasum; do
cd /shared
if git log --oneline -1 --stat -S"${shasum}" | grep "^ documents/" >/dev/null ; then
#echo "Object: ${shasum}"
document="$(git log --oneline -1 --stat -S"${shasum}" | head -n 2 | tail -n 1 | sed -e 's/|.*//' | sed -r -e 's/^ +//' | sed -r -e 's/ +$//')"
#echo "Document: ${document}"
source_file="$(git annex examinekey ${shasum} --format='/shared/.git/annex/objects/${hashdirmixed}${key}/${key}')"
#echo "File location: ${source_file}"
target="$RESTORE_DIR/$document"
if [ -f "$target" ]; then
if diff -q "${source_file}" "${target}"; then
echo "$document already restored"
else
echo "$document exists but is different than the recovery copy"
fi
else
if [ -f "${source_file}" ]; then
echo "$document restoring"
echo " ... copying from ${source_file} in git-annex"
mkdir -p "$(dirname "${target}")"
cp -a "${source_file}" "${target}"
echo " restored."
else
echo "$document cannot be restored"
fi
fi
fi
done
pushd /shared; git annex unused >~/annex-unused-keys; popd
bash annex-restore.sh | tee annex-restore.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment