From 81790064b4c2a18e52cf1e08a69aa0f38038f105 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 19 Oct 2015 20:56:09 -0700 Subject: [PATCH] Add backup-check script to detect bit rot --- home/.editorconfig | 3 +++ home/.zshrc | 3 +++ home/bin/backup-check | 53 +++++++++++++++++++++++++++++++++++++++++++ home/bin/sync-pics | 6 +++++ 4 files changed, 65 insertions(+) create mode 100755 home/bin/backup-check diff --git a/home/.editorconfig b/home/.editorconfig index 5532676..f7808e5 100644 --- a/home/.editorconfig +++ b/home/.editorconfig @@ -23,4 +23,7 @@ indent_size = 2 indent_style = space indent_size = 2 +[*.go] +indent_style = tab + # format:dosini diff --git a/home/.zshrc b/home/.zshrc index 5be6a1a..775cffd 100644 --- a/home/.zshrc +++ b/home/.zshrc @@ -26,6 +26,9 @@ export EDITOR="/usr/bin/vim" # Virtualenv export WORKON_HOME=~/.virtualenvs +# Go +export GOPATH="$HOME/go" + # Reload zshrc alias rezsh="source ${HOME}/.zshrc" diff --git a/home/bin/backup-check b/home/bin/backup-check new file mode 100755 index 0000000..7a9f05e --- /dev/null +++ b/home/bin/backup-check @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +"""backup-check: Periodically compare checksums of backups in multiple +locations. It's mainly to do a weekly check of all my backup locations and +identify bit rot before it's too late. + +Install via `crontab -e`: +0 2 * * 0 /home/noah/bin/backup-check + +--Kirsle +http://sh.kirsle.net/ +""" + +import codecs +import os.path +import subprocess + +# Directories to compare with each other. +DIRECTORIES = [ + "/mnt/Midnight/Images/Organized", + "/run/media/noah/Cyro/Pictures/Organized", + "/run/media/noah/Obelisk/Redundant/Images/Organized", + "/home/noah/Dropbox/Photos/Organized", + "/home/noah/ownCloud/Photos/Organized", +] +ERROR_OUT = "/home/noah/Desktop/Checksum Error.txt" + +def main(): + # First available disk becomes the common denominator. + master = None + for disk in DIRECTORIES: + if os.path.isdir(disk): + if master is None: + print("Master disk chosen as:", disk) + master = disk + + if disk != master: + # Do the comparison. + print("Compare {} <=> {}".format(master, disk)) + out = subprocess.check_output(["diff", "-aqr", master, disk]) + if len(out): + # Problem! + error(out) + break + +def error(out): + """Error, panic!""" + fh = codecs.open(ERROR_OUT, "w", "utf-8") + fh.write(out.decode("utf-8")) + fh.close() + +if __name__ == "__main__": + main() diff --git a/home/bin/sync-pics b/home/bin/sync-pics index 18f047c..f6bb510 100755 --- a/home/bin/sync-pics +++ b/home/bin/sync-pics @@ -46,6 +46,12 @@ TARGETS = OrderedDict([ path = "/home/noah/Dropbox Vault", rsync = "rsync -avu --delete {source}/.X/ \"{destination}/\"", )), + + # Owncloud backup. + ("Owncloud", dict( + path = "/home/noah/ownCloud/Photos/Organized", + rsync = "rsync -avu --delete --exclude .X {source}/ {destination}/", + )), ]) #######################################