# HG changeset patch # User Christian Arnold # Date 1329478677 -3600 # Node ID 782183ddd01212a24c4cc0153b5040cd5c6dbe89 # Parent 7d486f24b873162cf9ca3360e0c5a95bd5b59dd6 add rsync optinos --verbose and --progress in debug mode whitespace cosmetic diff -r 7d486f24b873 -r 782183ddd012 sync-to-usb.sh --- a/sync-to-usb.sh Fri Feb 17 10:43:36 2012 +0100 +++ b/sync-to-usb.sh Fri Feb 17 12:37:57 2012 +0100 @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh # # # Copyright (C) 2012 Christian Arnold @@ -47,8 +47,8 @@ debug() { if [ $DEBUG -gt 0 ]; then - echo "$@" >&2 - fi + echo "$@" >&2 + fi } check_mountpoint() { @@ -72,14 +72,14 @@ } open_cryptdev() { - TYPE=$1 - if [ ! $(blkid -U $2) ]; then - debug "ERROR: [$ME] can't get device path for UUID: $2" - exit 1 - fi - DEV=$(blkid -U $2) - CRYPTDEV="cbackup.$TYPE.$$" - KEYFILE=$3 + TYPE=$1 + if [ ! $(blkid -U $2) ]; then + debug "ERROR: [$ME] can't get device path for UUID: $2" + exit 1 + fi + DEV=$(blkid -U $2) + CRYPTDEV="cbackup.$TYPE.$$" + KEYFILE=$3 cryptsetup luksOpen $DEV $CRYPTDEV --key-file $KEYFILE 2>/dev/null if [ ! -h /dev/mapper/$CRYPTDEV ]; then debug "ERROR: [$ME] can't luksOpen cryptdev '$CRYPTDEV'" @@ -93,13 +93,13 @@ } mount_cryptdev() { - TYPE=$1 - CRYPTDEV="cbackup.$TYPE.$$" - MOUNTPOINT=$2 - MOUNTOPT="" - test "$TYPE" = "source" && MOUNTOPT="--read-only" + TYPE=$1 + CRYPTDEV="cbackup.$TYPE.$$" + MOUNTPOINT=$2 + MOUNTOPT="" + test "$TYPE" = "src" && MOUNTOPT="--read-only" if mount $MOUNTOPT /dev/mapper/$CRYPTDEV $MOUNTPOINT; then - debug "OK: [$ME] mount $CRYPTDEV to $MOUNTPOINT" + debug "OK: [$ME] mount $CRYPTDEV $MOUNTOPT to $MOUNTPOINT" [ $LOGGING -eq 1 ] && logger -p local0.notice -t $ME "OK: mount $CRYPTDEV to $MOUNTPOINT" else debug "ERROR: [$ME] can't mount $CRYPTDEV to $MOUNTPOINT" @@ -110,7 +110,7 @@ } umount_cryptdev() { - MOUNTPOINT=$1 + MOUNTPOINT=$1 if umount $MOUNTPOINT 2>/dev/null; then debug "OK: [$ME] umount $MOUNTPOINT" [ $LOGGING -eq 1 ] && logger -p local0.notice -t $ME "OK: umount $MOUNTPOINT" @@ -123,8 +123,8 @@ } close_cryptdev() { - TYPE=$1 - CRYPTDEV="cbackup.$TYPE.$$" + TYPE=$1 + CRYPTDEV="cbackup.$TYPE.$$" if [ -h /dev/mapper/$CRYPTDEV ]; then cryptsetup luksClose $CRYPTDEV if [ -h /dev/mapper/$CRYPTDEV ]; then @@ -140,24 +140,26 @@ } do_sync() { - SOURCE=$1 - DESTINATION=$2 - if rsync -Ha --numeric-ids --delete $SOURCE $DESTINATION; then - debug "OK: [$ME] sync is done from '$SOURCE' to '$DESTINATION'" + SOURCE=$1 + DESTINATION=$2 + VERBOSE="" + test $DEBUG -gt 0 && VERBOSE="--verbose --progress" + if rsync -Ha $VERBOSE --numeric-ids --delete $SOURCE $DESTINATION; then + debug "OK: [$ME] sync is done from '$SOURCE' to '$DESTINATION'" [ $LOGGING -eq 1 ] && logger -p local0.notice -t $ME "OK: sync is done from '$SOURCE' to '$DESTINATION'" - else - debug "ERROR: [$ME] sync error from '$SOURCE' to '$DESTINATION'" + else + debug "ERROR: [$ME] sync error from '$SOURCE' to '$DESTINATION'" [ $LOGGING -eq 1 ] && logger -p local0.err -t $ME "ERROR: sync error from '$SOURCE' to '$DESTINATION'" - exit 1 - fi - return 0 + exit 1 + fi + return 0 } cleanup() { check_mountpoint $SPATH || umount_cryptdev $SPATH check_mountpoint $DPATH || umount_cryptdev $DPATH - close_cryptdev source - close_cryptdev destination + close_cryptdev src + close_cryptdev dst } # MAIN @@ -165,8 +167,8 @@ trap cleanup INT EXIT if [ $# -ne 5 ]; then - usage - exit 1 + usage + exit 1 fi check_mountpoint $SPATH