From d21a9b6df4cd3a47e540c3cca8203b8f0f53a029 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 12 Apr 2015 10:45:32 +0200 Subject: add new scripts Signed-off-by: Florian Pritz --- ocr-scan | 20 +++++++++++++++ zfs-backup.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100755 ocr-scan create mode 100755 zfs-backup.sh diff --git a/ocr-scan b/ocr-scan new file mode 100755 index 0000000..5e7423f --- /dev/null +++ b/ocr-scan @@ -0,0 +1,20 @@ +#!/bin/bash + +jpeg_quality=70 +jpeg_size=1500x1500 + +time=$(date +%Y-%m-%d_%H%M%S) +scanimage --resolution 300 -b -x 215 -y 297 +i=1 +while [[ -e "out$i.pnm" ]]; do + img="out$i.pnm" + newname="$(printf "%s_%03d" "$time" "$i")" + unpaper "$img" "unpaper-$img" + tesseract "unpaper-$img" "$newname.txt" + convert "$img" -normalize -resize $jpeg_size -quality $jpeg_quality "$newname.jpg" && rm "$img" "unpaper-$img" + ((i++)) +done + +if [[ $1 = "--pdf" ]]; then + convert "${time}"_*.jpg -resize $jpeg_size -compress jpeg -quality $jpeg_quality -density 72x72 -repage 595x842 "${time}.pdf" && rm "${time}"_*.jpg +fi diff --git a/zfs-backup.sh b/zfs-backup.sh new file mode 100755 index 0000000..40dc4f6 --- /dev/null +++ b/zfs-backup.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +## example host config +# set_vars root karif +# +# run_ssh $src /root/backup.pl start +# +# run_ssh backup@$host "cd /home/backup/mysql-dumps; /home/backup/create-mysql-dumps" +# run_ssh backup@$host "cd /home/backup/psql-dumps; /home/backup/create-psql-dumps" +# backup_rsync "$src:/home/backup/mysql-dumps/" "$dst/mysql-dumps/" +# backup_rsync "$src:/home/backup/psql-dumps/" "$dst/psql-dumps/" +# run_ssh backup@$host "rm -f /home/backup/mysql-dumps/*.sql.gz" +# run_ssh backup@$host "rm -f /home/backup/psql-dumps/*.dump" +# +# backup_rsync --filter=". /mnt/backup/filters/karif_root_filter" "$src:/mnt/snapshots/vg0-root/" "$dst/root/" +# backup_rsync --filter=". /mnt/backup/filters/karif_home_filter" "$src:/mnt/snapshots/vg0-home/" "$dst/home/" +# backup_rsync "$src:/boot/" "$dst/boot/" +# +# run_ssh $src /root/backup.sh stop +# +# create_and_clean_snapshots "$dst_fs" + + + +set -e + +backup_rsync() { + local dir="${@: -1}" + mkdir -p "$dir" + rsync --rsh="/usr/bin/ssh -i /root/.ssh/id_rsa-backup" --delete --numeric-ids --delete-excluded --max-delete=100000 -axEAXHv "$@" +} + +run_ssh() { + ssh -i /root/.ssh/id_rsa-backup "$@" +} + +set_vars() { + user="$1" + host="$2" + src="$user@$host" + dst_fs="$backup_fs_base/$host" + dst="$(zfs get mountpoint -o value -H "$dst_fs")" +} + +create_snapshots() { + local dst_fs=$1 + + if [[ "$(date +%d)" = "01" ]]; then + /root/zfs_create_dated_snapshot.sh "$dst_fs" monthly + fi + if [[ "$(date +%u)" = "7" ]]; then + /root/zfs_create_dated_snapshot.sh "$dst_fs" weekly + fi + /root/zfs_create_dated_snapshot.sh "$dst_fs" daily +} + +clean_snapshots() { + local dst_fs=$1 + + /root/zfs_snapshot_cleanup.sh "$dst_fs" daily 10 + /root/zfs_snapshot_cleanup.sh "$dst_fs" weekly 4 + /root/zfs_snapshot_cleanup.sh "$dst_fs" monthly 2 +} + +create_and_clean_snapshots() { + local dst_fs=$1 + create_snapshots "$dst_fs" + clean_snapshots "$dst_fs" +} + +backup_fs_base="data/backup_zfs/backups" + +if (($#<1)); then + echo "usage: ${0##*/} " + exit 1 +fi + +source "${0%/*}/host-configs/$1" -- cgit v1.2.3-24-g4f1b