2005-11-17 11:33:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Nico Schottelius
|
|
|
|
# written for SyGroup (www.sygroup.ch)
|
|
|
|
# Date: Mon Nov 14 11:45:11 CET 2005
|
|
|
|
# Last Modified:
|
|
|
|
|
|
|
|
|
2005-12-06 14:07:13 +00:00
|
|
|
#
|
|
|
|
# temporary as long as inofficial
|
|
|
|
#
|
2005-11-17 15:52:44 +00:00
|
|
|
CCOLLECT_CONF=$HOME/crsnapshot/conf
|
2005-12-06 14:07:13 +00:00
|
|
|
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-12-06 14:07:13 +00:00
|
|
|
#
|
2005-12-06 14:55:07 +00:00
|
|
|
# where to find our configuration and temporary file
|
2005-12-06 14:07:13 +00:00
|
|
|
#
|
2005-11-17 15:52:44 +00:00
|
|
|
CCOLLECT_CONF=${CCOLLECT_CONF:-/etc/ccollect}
|
2005-12-06 15:20:43 +00:00
|
|
|
CSOURCES=$CCOLLECT_CONF/sources
|
|
|
|
CDEFAULTS=$CCOLLECT_CONF/defaults
|
2005-12-06 14:55:07 +00:00
|
|
|
TMP=$(mktemp /tmp/$(basename $0).XXXXXX)
|
2005-12-07 16:41:20 +00:00
|
|
|
WE=$(basename $0)
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-12-06 14:55:07 +00:00
|
|
|
#
|
|
|
|
# catch signals
|
|
|
|
#
|
|
|
|
trap "rm -f \"$TMP\"" 1 2 15
|
2005-11-17 11:33:49 +00:00
|
|
|
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-12-06 15:20:43 +00:00
|
|
|
#
|
|
|
|
# errors!
|
|
|
|
#
|
|
|
|
errecho()
|
|
|
|
{
|
|
|
|
echo "Error: $@" >&2
|
|
|
|
}
|
|
|
|
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-11-17 15:52:44 +00:00
|
|
|
#
|
2005-12-06 12:45:37 +00:00
|
|
|
# Tell how to use us
|
2005-11-17 15:52:44 +00:00
|
|
|
#
|
2005-12-06 12:45:37 +00:00
|
|
|
usage()
|
|
|
|
{
|
2005-12-07 16:41:20 +00:00
|
|
|
echo "$WE: <intervall name> [args] <sources to backup>"
|
2005-12-06 12:45:37 +00:00
|
|
|
echo ""
|
|
|
|
echo " Nico Schottelius (nico-linux-ccollect schottelius.org) - 2005-12-06"
|
|
|
|
echo ""
|
|
|
|
echo " Backup data pseudo incremental"
|
|
|
|
echo ""
|
|
|
|
echo " -h, --help: Show this help screen"
|
|
|
|
echo " -p, --parallel: Parellize backup process"
|
2005-12-06 14:35:29 +00:00
|
|
|
echo " -a, --all: Backup all sources specified in $CSOURCES"
|
2005-12-06 12:45:37 +00:00
|
|
|
echo ""
|
2005-12-06 15:36:28 +00:00
|
|
|
echo " Retrieve latest ccollect at http://linux.schottelius.org/ccollect/."
|
2005-12-06 12:45:37 +00:00
|
|
|
echo ""
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
|
|
|
# need at least intervall and one source or --all
|
|
|
|
#
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-12-06 12:45:37 +00:00
|
|
|
#
|
|
|
|
# Filter arguments
|
|
|
|
#
|
2005-12-07 16:41:20 +00:00
|
|
|
|
|
|
|
INTERVALL=$1; shift
|
|
|
|
|
2005-12-06 12:45:37 +00:00
|
|
|
i=1
|
|
|
|
no_shares=0
|
|
|
|
|
|
|
|
while [ $i -le $# ]; do
|
|
|
|
eval arg=\$$i
|
2005-12-06 14:07:13 +00:00
|
|
|
|
|
|
|
if [ "$NO_MORE_ARGS" = 1 ]; then
|
2005-12-06 12:45:37 +00:00
|
|
|
eval share_${no_shares}="$arg"
|
2005-12-07 16:41:20 +00:00
|
|
|
no_shares=$[$no_shares+1]
|
2005-12-06 14:07:13 +00:00
|
|
|
else
|
|
|
|
case $arg in
|
|
|
|
-a|--all)
|
|
|
|
ALL=1
|
|
|
|
;;
|
|
|
|
-p|--parallel)
|
|
|
|
PARALLEL=1
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
NO_MORE_ARGS=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
eval share_${no_shares}="$arg"
|
2005-12-07 16:41:20 +00:00
|
|
|
no_shares=$[$no_shares+1]
|
2005-12-06 14:07:13 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2005-12-06 12:45:37 +00:00
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
i=$[$i+1]
|
2005-12-06 12:45:37 +00:00
|
|
|
done
|
|
|
|
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-12-06 14:35:29 +00:00
|
|
|
#
|
|
|
|
# Look, if we should take ALL sources
|
|
|
|
#
|
|
|
|
if [ "$ALL" = 1 ]; then
|
|
|
|
# reset everything specified before
|
|
|
|
no_shares=0
|
2005-12-06 14:55:07 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# get entries from sources
|
|
|
|
#
|
|
|
|
cwd=$(pwd)
|
|
|
|
cd $CSOURCES;
|
|
|
|
ls > "$TMP"
|
|
|
|
|
|
|
|
while read tmp; do
|
|
|
|
eval share_${no_shares}=\"$tmp\"
|
2005-12-07 16:41:20 +00:00
|
|
|
no_shares=$[$no_shares+1]
|
2005-12-06 14:55:07 +00:00
|
|
|
done < "$TMP"
|
2005-12-06 14:35:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Need at least ONE source to backup
|
|
|
|
#
|
|
|
|
if [ "$no_shares" -lt 1 ]; then
|
|
|
|
usage
|
2005-12-07 16:41:20 +00:00
|
|
|
else
|
|
|
|
echo "$WE: Beginning backup using intervall $INTERVALL"
|
2005-12-06 14:35:29 +00:00
|
|
|
fi
|
2005-12-06 14:07:13 +00:00
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
|
|
|
# check default configuration
|
|
|
|
#
|
|
|
|
|
|
|
|
D_FILE_INTERVALL="$CDEFAULTS/intervalls/$INTERVALL"
|
|
|
|
D_INTERVALL=$(cat $D_FILE_INTERVALL 2>/dev/null)
|
|
|
|
|
2005-12-06 15:20:43 +00:00
|
|
|
#
|
|
|
|
# Let's do the backup
|
|
|
|
#
|
|
|
|
i=0
|
|
|
|
while [ "$i" -lt "$no_shares" ]; do
|
2005-11-17 11:33:49 +00:00
|
|
|
|
2005-11-17 15:52:44 +00:00
|
|
|
#
|
|
|
|
# Standard locations
|
|
|
|
#
|
2005-12-06 15:20:43 +00:00
|
|
|
eval name=\$share_${i}
|
|
|
|
backup="$CSOURCES/$name"
|
2005-11-17 15:52:44 +00:00
|
|
|
c_source="$backup/source"
|
|
|
|
c_dest="$backup/destination"
|
|
|
|
c_exclude="$backup/exclude"
|
2005-12-06 15:20:43 +00:00
|
|
|
|
|
|
|
echo "Beginning to backup \"$name\" ..."
|
2005-12-07 16:41:20 +00:00
|
|
|
i=$[$i+1]
|
2005-11-17 15:52:44 +00:00
|
|
|
|
2005-12-06 15:36:28 +00:00
|
|
|
#
|
|
|
|
# Standard configuration checks
|
|
|
|
#
|
2005-11-17 15:52:44 +00:00
|
|
|
if [ ! -d "$backup" ]; then
|
2005-12-06 15:20:43 +00:00
|
|
|
errecho "\"$name\" is not a cconfig-directory. Skipping."
|
2005-11-17 15:52:44 +00:00
|
|
|
continue
|
|
|
|
fi
|
2005-12-06 15:20:43 +00:00
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
|
|
|
# intervall definiition
|
|
|
|
#
|
|
|
|
c_intervall="$(cat "$backup/intervalls/$INTERVALL" 2>/dev/null)"
|
|
|
|
|
|
|
|
if [ -z "$c_intervall" ]; then
|
|
|
|
c_intervall=$D_INTERVALL
|
|
|
|
|
|
|
|
if [ -z "$c_intervall" ]; then
|
|
|
|
errecho "Default and source specific intervall missing. Skipping."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# standard rsync options
|
|
|
|
#
|
|
|
|
VERBOSE=""
|
|
|
|
EXCLUDE=""
|
|
|
|
|
|
|
|
#
|
|
|
|
# next configuration checks
|
|
|
|
#
|
2005-11-17 15:52:44 +00:00
|
|
|
if [ ! -f "$c_source" ]; then
|
2005-12-06 15:20:43 +00:00
|
|
|
echo "Source description $c_source is not a file. Skipping."
|
2005-11-17 15:52:44 +00:00
|
|
|
continue
|
|
|
|
else
|
2005-12-06 15:20:43 +00:00
|
|
|
source=$(cat "$c_source")
|
2005-12-06 11:50:36 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Skipping: Source $c_source is not readable"
|
|
|
|
continue
|
|
|
|
fi
|
2005-11-17 15:52:44 +00:00
|
|
|
fi
|
2005-12-06 15:20:43 +00:00
|
|
|
|
2005-11-17 15:52:44 +00:00
|
|
|
if [ ! -d "$c_dest" ]; then
|
2005-12-06 15:36:28 +00:00
|
|
|
errecho "Destination $c_dest does not link to a directory. Skipping"
|
2005-11-17 15:52:44 +00:00
|
|
|
continue
|
|
|
|
fi
|
2005-12-06 11:50:36 +00:00
|
|
|
|
|
|
|
if [ -f "$c_exclude" ]; then
|
2005-12-06 15:36:28 +00:00
|
|
|
errecho "Destination $c_dest does not link to a directory. Skipping."
|
2005-12-06 11:50:36 +00:00
|
|
|
continue
|
2005-12-06 16:08:38 +00:00
|
|
|
|
|
|
|
while read tmp; do
|
|
|
|
EXCLUDE="$EXCLUDE --exclude \"$tmp\""
|
|
|
|
done < "$c_exclude"
|
2005-12-06 11:50:36 +00:00
|
|
|
fi
|
2005-12-07 16:41:20 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# TODO
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# check if maximum number of backups is reached
|
|
|
|
#
|
2005-12-06 16:08:38 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# clone the old directory with hardlinks
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# the rsync part
|
|
|
|
#
|
2005-12-07 16:41:20 +00:00
|
|
|
echo rsync --delete $VERBOSE $EXCLUDE $source $c_dest
|
2005-11-17 15:52:44 +00:00
|
|
|
done
|
2005-12-06 14:55:07 +00:00
|
|
|
|
2005-12-06 16:08:38 +00:00
|
|
|
#
|
|
|
|
# Be a good parent and wait for our children, if they are running wild parallel
|
|
|
|
#
|
|
|
|
if [ "$PARALLEL" = 1 ]; then
|
|
|
|
wait
|
|
|
|
fi
|
|
|
|
|
2005-12-06 14:55:07 +00:00
|
|
|
rm -f "$TMP"
|