--- rdup-simple.orig 2010-06-21 05:17:06.000000000 -0700 +++ rdup-simple 2010-06-27 17:05:46.000000000 -0700 @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # updates a hardlinked backup # licensed under the GPL version 3 @@ -38,16 +38,17 @@ exit 2 fi - let i=1 + i=1 while [ $i -le $LOOKBACK ]; do - D=$(date $DATESTR --date "$i days ago") + adjust=$(printf %dd $i) + D=$(date -v-$adjust $DATESTR) if [ -d $TOPDIR/$D ]; then - if ! cp -plr $TOPDIR/$D/* $TOPDIR/$TODAY; then + if ! cp -plR $TOPDIR/$D/* $TOPDIR/$TODAY; then exit 2 fi exit 0 fi - let i=i+1 + i=$((i+1)) done exit 1 } @@ -121,7 +122,7 @@ exit 1 fi if [ ! -r "$OPTARG" ]; then - echo2 "Cannot read keyfile \`$OPTARG': failed" + echo2 "Cannot read keyfile \'$OPTARG': failed" exit 1 fi trans="$trans -Pmcrypt,-q,-f,$OPTARG" @@ -163,9 +164,9 @@ done shift $((OPTIND - 1)) -if [ "${1:0:1}" = "+" ]; then - DAYS=${1:1} - if [ $DAYS -lt 1 ] || [ $DAYS -gt 99 ]; then +if [ "${1%${1#?}}" = "+" ]; then + DAYS=${1#?} + if [ $DAYS -lt 1 ] || [ $DAYS -gt 99 ]; then echo2 "+N needs to be a number [1..99]" exit 1 fi @@ -187,7 +188,7 @@ while [ $i -lt $last ]; do DIRS="$DIRS $1" shift - ((i=$i+1)) + i=$((i+1)) done # rdup [options] source destination #dest="ssh://elektron.atoom.net/directory" @@ -197,8 +198,8 @@ #dest="ssh://miekg@elektron.atoom.net/directory" dest=$1 -if [ ${dest:0:6} = "ssh://" ]; then - rest=${dest/ssh:\/\//} +if [ "${dest%${dest#??????}}" = "ssh://" ]; then + rest=${dest#ssh://} u=${rest%%@*} if [ "$u" = "$rest" ]; then @@ -206,9 +207,9 @@ u= fi - rest=${rest/$u@/} + rest=${rest#$u@} h=$(echo $rest | cut -s -f1 -d/) - BACKUPDIR=${rest/$h/} + BACKUPDIR=${rest#$h} if [ -z "$u" ]; then ssh=" ssh -c blowfish -x $h" @@ -216,11 +217,11 @@ ssh=" ssh -c blowfish -x $u@$h" fi fi -if [ ${dest:0:7} = "file://" ]; then - rest=${dest/file:\/\//} +if [ "${dest%${dest#???????}}" = "file://" ]; then + rest=${dest#file://} BACKUPDIR=$rest fi -[ ${dest:0:1} = "/" ] && BACKUPDIR=$dest +[ "${dest%${dest#?}}" = "/" ] && BACKUPDIR=$dest # no hits above, assume relative filename [ -z "$BACKUPDIR" ] && BACKUPDIR=$PWD/$dest @@ -228,8 +229,8 @@ $link && copy_and_link $DAYS $BACKUPDIR # change all / to _ to make a valid filename -STAMP=$etc/timestamp.${HOSTNAME}.${dest//\//_} -LIST=$etc/list.${HOSTNAME}.${dest//\//_} +STAMP=$etc/timestamp.${HOSTNAME}.$(echo $dest | tr / _) +LIST=$etc/list.${HOSTNAME}.$(echo $dest | tr / _) [ ! -d $etc ] && mkdir $etc @@ -250,6 +251,7 @@ # path is set at the top if [ -z "$ssh" ]; then $PROGNAME $OPT_DRY -L +$DAYS /dev/null $BACKUPDIR +# rdup-ln -l $DAYS $BACKUPDIR purpose=$? else # You need to set your path so rdup-simple can be found