From 09b10f47767e47529d7ad0ce28128a2cc709e718 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Dec 2005 10:27:39 +0100 Subject: [PATCH] Added 90% of functionality, added more configuration examples --- ccollect.sh | 47 +++++++++++++------ conf/defaults/intervalls/daily | 1 + conf/sources/share2/exclude | 3 ++ conf/sources/share2/intervalls/daily | 1 + conf/sources/share2/source | 1 + conf/sources/source-without-intervall/exclude | 1 + conf/sources/source-without-intervall/source | 1 + conf/sources/testshare/exclude | 3 ++ 8 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 conf/defaults/intervalls/daily create mode 100644 conf/sources/share2/exclude create mode 100644 conf/sources/share2/intervalls/daily create mode 100644 conf/sources/share2/source create mode 100644 conf/sources/source-without-intervall/exclude create mode 100644 conf/sources/source-without-intervall/source create mode 100644 conf/sources/testshare/exclude diff --git a/ccollect.sh b/ccollect.sh index bf30024..0ce1d4f 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -209,16 +209,14 @@ while [ "$i" -lt "$no_shares" ]; do done < "$c_exclude" fi - # - # TODO - # - # # check if maximum number of backups is reached, if so remove # - # STOPPED! - count=$(ls "$c_dest/${INTERVALL}.*" | wc -l) + # + # the created directories are named $INTERVALL.$DATE + # + count=$(ls -d "$c_dest/${INTERVALL}."?* 2>/dev/null | wc -l) echo "|-> $count backup(s) already exist, keeping $c_intervall backup(s)." if [ "$count" -ge "$c_intervall" ]; then @@ -226,26 +224,47 @@ while [ "$i" -lt "$no_shares" ]; do remove=$(echo $count - $substract | bc) echo "|-> Removing $remove backups..." - ls "$c_dest/${INTERVALL}.*" | sort -n | head -n $remove > "$TMP" + ls -d "$c_dest/${INTERVALL}."?* | sort -n | head -n $remove > "$TMP" while read to_remove; do - dir="$c_dest/$to_remove" + dir="$to_remove" echo "|-> Removing $dir ..." - rm -rf "$dir" + echo rm -rf "$dir" done < "$TMP" fi - + # # clone the old directory with hardlinks # + destination_date=$(date +%Y-%m-%d-%H:%M) + destination_dir="$c_dest/${INTERVALL}.${destination_date}/" + + last_dir=$(ls -d "$c_dest/${INTERVALL}."?* 2>/dev/null | sort -n | tail -n 1) + + # only copy if there exists a directory + if [ "$last_dir" ]; then + echo cp -al "$last_dir" "$destination_dir" + else + mkdir "$destination_dir" + fi + + if [ $? -ne 0 ]; then + errecho "Creating backup directory failed. Skipping backup." + continue + fi + # # the rsync part - # --delete --numeric-ids --relative --delete-excluded + # options stolen shameless from rsnapshot # - # STOPPED! - destination_dir=$(date +%Y-%m-%d) - echo rsync -a --delete $EXCLUDE $VERBOSE $EXCLUDE "$source" "$c_dest/${INTERVALL}.${destination_dir}" + echo rsync -a --delete --numeric-ids --relative --delete-excluded \ + $EXCLUDE $VERBOSE $EXCLUDE "$source" "$destination_dir" + + if [ $? -ne 0 ]; then + errecho "rsync failed, backup most likely broken" + continue + fi done # diff --git a/conf/defaults/intervalls/daily b/conf/defaults/intervalls/daily new file mode 100644 index 0000000..9902f17 --- /dev/null +++ b/conf/defaults/intervalls/daily @@ -0,0 +1 @@ +28 diff --git a/conf/sources/share2/exclude b/conf/sources/share2/exclude new file mode 100644 index 0000000..bbdbdf1 --- /dev/null +++ b/conf/sources/share2/exclude @@ -0,0 +1,3 @@ +openvpn-2.0.1.tar.gz +nicht_reinnehmen +etwas mit leerzeichenli diff --git a/conf/sources/share2/intervalls/daily b/conf/sources/share2/intervalls/daily new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/conf/sources/share2/intervalls/daily @@ -0,0 +1 @@ +2 diff --git a/conf/sources/share2/source b/conf/sources/share2/source new file mode 100644 index 0000000..597ddca --- /dev/null +++ b/conf/sources/share2/source @@ -0,0 +1 @@ +/home/nico/vpn diff --git a/conf/sources/source-without-intervall/exclude b/conf/sources/source-without-intervall/exclude new file mode 100644 index 0000000..5469661 --- /dev/null +++ b/conf/sources/source-without-intervall/exclude @@ -0,0 +1 @@ +manage diff --git a/conf/sources/source-without-intervall/source b/conf/sources/source-without-intervall/source new file mode 100644 index 0000000..a1849b9 --- /dev/null +++ b/conf/sources/source-without-intervall/source @@ -0,0 +1 @@ +nico@creme.schottelius.org:bin diff --git a/conf/sources/testshare/exclude b/conf/sources/testshare/exclude new file mode 100644 index 0000000..bbdbdf1 --- /dev/null +++ b/conf/sources/testshare/exclude @@ -0,0 +1,3 @@ +openvpn-2.0.1.tar.gz +nicht_reinnehmen +etwas mit leerzeichenli