forked from ungleich-public/ccollect
Added new requirement bc, added more beautiful output
This commit is contained in:
parent
cc275b5c5c
commit
735b0e3c11
2 changed files with 26 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
ccollect.sh, Nico Schottelius, 2005-12-06
|
ccollect.sh, Nico Schottelius, 2005-12-06 (updated: 2005-12-07)
|
||||||
Requirements
|
Requirements
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -9,3 +9,4 @@ You need at least:
|
||||||
- cp with support for hard links
|
- cp with support for hard links
|
||||||
- ssh if you want to use rsync over ssh
|
- ssh if you want to use rsync over ssh
|
||||||
- a bourne shell (/bin/sh) compatible shell
|
- a bourne shell (/bin/sh) compatible shell
|
||||||
|
- bc
|
||||||
|
|
30
ccollect.sh
30
ccollect.sh
|
@ -31,7 +31,7 @@ trap "rm -f \"$TMP\"" 1 2 15
|
||||||
#
|
#
|
||||||
errecho()
|
errecho()
|
||||||
{
|
{
|
||||||
echo "Error: $@" >&2
|
echo "|E> Error: $@" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ fi
|
||||||
if [ "$no_shares" -lt 1 ]; then
|
if [ "$no_shares" -lt 1 ]; then
|
||||||
usage
|
usage
|
||||||
else
|
else
|
||||||
echo "$WE: Beginning backup using intervall $INTERVALL"
|
echo "/o> $WE: Beginning backup using intervall $INTERVALL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -153,7 +153,7 @@ while [ "$i" -lt "$no_shares" ]; do
|
||||||
c_dest="$backup/destination"
|
c_dest="$backup/destination"
|
||||||
c_exclude="$backup/exclude"
|
c_exclude="$backup/exclude"
|
||||||
|
|
||||||
echo "Beginning to backup \"$name\" ..."
|
echo "|=> Beginning to backup \"$name\" ..."
|
||||||
i=$[$i+1]
|
i=$[$i+1]
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -188,12 +188,12 @@ while [ "$i" -lt "$no_shares" ]; do
|
||||||
# next configuration checks
|
# next configuration checks
|
||||||
#
|
#
|
||||||
if [ ! -f "$c_source" ]; then
|
if [ ! -f "$c_source" ]; then
|
||||||
echo "Source description $c_source is not a file. Skipping."
|
echo "|-> Source description $c_source is not a file. Skipping."
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
source=$(cat "$c_source")
|
source=$(cat "$c_source")
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Skipping: Source $c_source is not readable"
|
echo "|-> Skipping: Source $c_source is not readable"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -214,15 +214,32 @@ while [ "$i" -lt "$no_shares" ]; do
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# check if maximum number of backups is reached
|
# check if maximum number of backups is reached, if so remove
|
||||||
#
|
#
|
||||||
|
|
||||||
|
count=$(ls "$c_dest" | wc -l)
|
||||||
|
echo "|-> $count backup(s) already exist, keeping $c_intervall backup(s)."
|
||||||
|
|
||||||
|
if [ "$count" -ge "$c_intervall" ]; then
|
||||||
|
substract=$(echo $c_intervall - 1 | bc)
|
||||||
|
remove=$(echo $count - $substract | bc)
|
||||||
|
echo "|-> Removing $remove backups..."
|
||||||
|
|
||||||
|
ls "$c_dest" | sort -n | head -n $remove > "$TMP"
|
||||||
|
while read to_remove; do
|
||||||
|
dir="$c_dest/$to_remove"
|
||||||
|
echo "|-> Removing $dir ..."
|
||||||
|
rm -rf "$dir"
|
||||||
|
done < "$TMP"
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# clone the old directory with hardlinks
|
# clone the old directory with hardlinks
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# the rsync part
|
# the rsync part
|
||||||
|
# --delete --numeric-ids --relative --delete-excluded
|
||||||
#
|
#
|
||||||
echo rsync -a --delete $EXCLUDE $VERBOSE $EXCLUDE $source $c_dest
|
echo rsync -a --delete $EXCLUDE $VERBOSE $EXCLUDE $source $c_dest
|
||||||
done
|
done
|
||||||
|
@ -235,3 +252,4 @@ if [ "$PARALLEL" = 1 ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$TMP"
|
rm -f "$TMP"
|
||||||
|
echo "\o> finished."
|
||||||
|
|
Loading…
Reference in a new issue