#!/bin/bash # # $Header: /CVSROOT/public/scylla-charybdis/md5backup/bin/sc-move.sh,v 1.7 2004/07/05 18:15:42 tino Exp $ # # $Log: sc-move.sh,v $ # Revision 1.7 2004/07/05 18:15:42 tino # superfluous log output removed # # Revision 1.6 2004/07/05 18:11:24 tino # some more logging in bin/sc-*.sh # # Revision 1.5 2004/07/05 17:18:29 tino # working version # # Revision 1.4 2004/06/19 12:31:29 tino # minor improvements # # Revision 1.3 2004/06/18 23:51:16 tino # see ChangeLog # # Revision 1.2 2004/05/15 14:44:54 tino # updated # # Revision 1.1 2004/05/04 05:11:01 tino # sc-backup.sh: backup via scylla+charybis; dobackup.sh convenience script MOVETARG="127.0.0.1" MOVEPORT="999" MOVEPASS="Tunneled" MOVESRC="${1:-md5move}" MOVESPEED= [ -s sc-move.conf ] && . sc-move.conf [ -s "sc-move.$1.conf" ] && . "sc-move.$1.conf" if [ ! -d "$MOVESRC" ] then echo "wrong arg: $MOVESRC" exit 1 fi if [ ! -d "tmp" ] then echo "missing tmp directory" exit 1 fi TMP="tmp/$$.in" trap 'rm -f "$TMP"' 0 log() { loga="$1" shift printf "%s: $loga\n" "`date +'%Y-%m-%d %H:%M:%S'`" "$@" >> "tmp/log.$MOVESRC" } buildlist() { splitarg="" splittest=aa if split -a6 /dev/null then splitarg=-a6 splittest=aaaaaa fi n="`expr 100 + ${RANDOM:1:3}`" printf "building file list: %4d\n" "$n" find "$MOVESRC"/*/. -type f -print > "tmp/files.$MOVESRC" nf="`wc -l < "tmp/files.$MOVESRC"`" printf "number of files: %7d\n" $nf split $splitarg -l$n "tmp/files.$MOVESRC" "tmp/R$MOVESRC." rm -f "tmp/again.$MOVESRC" "tmp/files.$MOVESRC" log "%d files to upload (split %d)" "$nf" "$n" [ ! -s "tmp/R$MOVESRC.$splittest" ] } out() { echo -n " $* " } movefiles() { done=false let finish=0 let redo=0 # We proecess all "run" files from all sources. for a in tmp/R* do [ ! -f "$a" ] && continue mv -f "$a" "$TMP" || continue out "do $a" if bin/charybdis "$MOVETARG" "$MOVEPORT" "$MOVEPASS" - $MOVESPEED < "$TMP" then let finish="finish+`wc -l < "$TMP"`" out "ok $a"; echo # cat "$TMP" >> "tmp/ok" while read del do rm -f "$del" done < "$TMP" sed -n 's/\/[^.][^/]*$//p' "$TMP" | sort -u | while read dir do rmdir "$dir" 2>/dev/null done sed -n 's/\/[^.][^/]*\/[^.][^/]*$//p' "$TMP" | sort -u | while read dir do rmdir "$dir" 2>/dev/null done else let redo="redo+`wc -l < "$TMP"`" out "up $a"; echo cat "$TMP" >> "tmp/again.$MOVESRC" fi rm -f "$TMP" done=: done $done && log "%d uploaded, %d to be redone" $finish $redo $done } movefiles && exit 1 buildlist