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
|
2006-01-13 22:10:23 +00:00
|
|
|
# Last Modified: (See ls -l or git)
|
2005-11-17 11:33:49 +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
|
2006-01-22 10:13:22 +00:00
|
|
|
CPREEXEC="$CDEFAULTS/pre_exec"
|
|
|
|
CPOSTEXEC="$CDEFAULTS/post_exec"
|
|
|
|
|
2005-12-06 14:55:07 +00:00
|
|
|
TMP=$(mktemp /tmp/$(basename $0).XXXXXX)
|
2006-04-29 21:41:12 +00:00
|
|
|
VERSION=0.4.1
|
|
|
|
RELEASE="2006-XX-XX"
|
2006-01-24 21:36:28 +00:00
|
|
|
HALF_VERSION="ccollect $VERSION"
|
|
|
|
FULL_VERSION="ccollect $VERSION ($RELEASE)"
|
2006-04-29 21:46:29 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Date
|
|
|
|
# CDATE: how we use it for naming of the archives
|
|
|
|
# DDATE: how the user should see it in our output
|
|
|
|
#
|
2006-04-29 21:41:12 +00:00
|
|
|
CDATE="date +%Y-%m-%d-%H%M"
|
2006-05-12 13:41:49 +00:00
|
|
|
DDATE="date"
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2006-01-09 12:24:27 +00:00
|
|
|
#
|
|
|
|
# unset parallel execution
|
|
|
|
#
|
|
|
|
PARALLEL=""
|
|
|
|
|
2006-01-13 22:10:23 +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
|
|
|
|
2006-01-09 12:56:09 +00:00
|
|
|
add_name()
|
|
|
|
{
|
|
|
|
sed "s/^/\[$name\] /"
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2006-04-25 13:35:56 +00:00
|
|
|
echo "$(basename $0): <interval name> [args] <sources to backup>"
|
2005-12-06 12:45:37 +00:00
|
|
|
echo ""
|
2006-01-24 21:36:28 +00:00
|
|
|
echo " ccollect creates (pseudo) incremental backups"
|
2005-12-06 12:45:37 +00:00
|
|
|
echo ""
|
|
|
|
echo " -h, --help: Show this help screen"
|
2006-01-24 21:58:39 +00:00
|
|
|
echo " -p, --parallel: Parallelise backup processes"
|
2005-12-06 14:35:29 +00:00
|
|
|
echo " -a, --all: Backup all sources specified in $CSOURCES"
|
2006-01-24 21:58:39 +00:00
|
|
|
echo " -v, --verbose: Be very verbose (uses set -x)."
|
2005-12-06 12:45:37 +00:00
|
|
|
echo ""
|
2006-02-05 17:56:36 +00:00
|
|
|
echo " This is version $VERSION, released on ${RELEASE}"
|
2006-04-28 14:43:41 +00:00
|
|
|
echo " (the first version was written on 2005-12-05 by Nico Schottelius)."
|
2006-01-24 21:58:39 +00:00
|
|
|
echo ""
|
|
|
|
echo " Retrieve latest ccollect at http://linux.schottelius.org/ccollect/"
|
2005-12-06 12:45:37 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
2006-04-25 13:35:56 +00:00
|
|
|
# need at least interval and one source or --all
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
2005-12-06 15:36:28 +00:00
|
|
|
|
2005-12-08 11:18:44 +00:00
|
|
|
#
|
|
|
|
# check for configuraton directory
|
|
|
|
#
|
|
|
|
if [ ! -d "$CCOLLECT_CONF" ]; then
|
2006-01-22 11:37:04 +00:00
|
|
|
echo "No configuration found in \"$CCOLLECT_CONF\"" \
|
|
|
|
" (set \$CCOLLECT_CONF corectly?)"
|
2005-12-08 11:18:44 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2005-12-06 12:45:37 +00:00
|
|
|
#
|
|
|
|
# Filter arguments
|
|
|
|
#
|
2006-04-25 13:35:56 +00:00
|
|
|
INTERVAL=$1; shift
|
2005-12-06 12:45:37 +00:00
|
|
|
i=1
|
2006-04-29 10:58:57 +00:00
|
|
|
no_sources=0
|
2005-12-06 12:45:37 +00:00
|
|
|
|
|
|
|
while [ $i -le $# ]; do
|
|
|
|
eval arg=\$$i
|
2005-12-06 14:07:13 +00:00
|
|
|
|
|
|
|
if [ "$NO_MORE_ARGS" = 1 ]; then
|
2006-04-29 10:58:57 +00:00
|
|
|
eval source_${no_sources}=\"$arg\"
|
|
|
|
no_sources=$(($no_sources+1))
|
2005-12-06 14:07:13 +00:00
|
|
|
else
|
|
|
|
case $arg in
|
|
|
|
-a|--all)
|
|
|
|
ALL=1
|
|
|
|
;;
|
2005-12-08 15:14:46 +00:00
|
|
|
-v|--verbose)
|
|
|
|
VERBOSE=1
|
|
|
|
;;
|
2005-12-06 14:07:13 +00:00
|
|
|
-p|--parallel)
|
2006-01-13 15:14:41 +00:00
|
|
|
PARALLEL="1"
|
2005-12-06 14:07:13 +00:00
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
NO_MORE_ARGS=1
|
|
|
|
;;
|
|
|
|
*)
|
2006-04-29 10:58:57 +00:00
|
|
|
eval source_${no_sources}=\"$arg\"
|
|
|
|
no_sources=$(($no_sources+1))
|
2005-12-06 14:07:13 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2005-12-06 12:45:37 +00:00
|
|
|
|
2006-01-22 11:21:35 +00:00
|
|
|
i=$(($i+1))
|
2005-12-06 12:45:37 +00:00
|
|
|
done
|
|
|
|
|
2005-12-08 15:14:46 +00:00
|
|
|
#
|
|
|
|
# be really really really verbose
|
|
|
|
#
|
|
|
|
if [ "$VERBOSE" = 1 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
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
|
2006-04-29 10:58:57 +00:00
|
|
|
no_sources=0
|
2005-12-06 14:55:07 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# get entries from sources
|
|
|
|
#
|
|
|
|
cwd=$(pwd)
|
2006-01-09 12:56:09 +00:00
|
|
|
cd "$CSOURCES";
|
2005-12-06 14:55:07 +00:00
|
|
|
ls > "$TMP"
|
|
|
|
|
|
|
|
while read tmp; do
|
2006-04-29 10:58:57 +00:00
|
|
|
eval source_${no_sources}=\"$tmp\"
|
|
|
|
no_sources=$(($no_sources+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
|
|
|
|
#
|
2006-04-29 10:58:57 +00:00
|
|
|
if [ "$no_sources" -lt 1 ]; then
|
2005-12-06 14:35:29 +00:00
|
|
|
usage
|
2005-12-07 16:41:20 +00:00
|
|
|
else
|
2006-04-25 13:35:56 +00:00
|
|
|
echo "==> $HALF_VERSION: Beginning backup using interval $INTERVAL <=="
|
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
|
|
|
|
#
|
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
D_FILE_INTERVAL="$CDEFAULTS/intervals/$INTERVAL"
|
|
|
|
D_INTERVAL=$(cat "$D_FILE_INTERVAL" 2>/dev/null)
|
2005-12-07 16:41:20 +00:00
|
|
|
|
2006-01-22 10:13:22 +00:00
|
|
|
#
|
|
|
|
# Look for pre-exec command (general)
|
|
|
|
#
|
|
|
|
if [ -x "$CPREEXEC" ]; then
|
2006-01-22 11:37:04 +00:00
|
|
|
echo "Executing $CPREEXEC ..."
|
2006-01-22 10:13:22 +00:00
|
|
|
"$CPREEXEC"
|
2006-01-22 11:37:04 +00:00
|
|
|
echo "Finished ${CPREEXEC}."
|
2006-03-18 23:59:42 +00:00
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "$CPREEXEC failed, aborting backup."
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-01-22 10:13:22 +00:00
|
|
|
fi
|
|
|
|
|
2005-12-06 15:20:43 +00:00
|
|
|
#
|
|
|
|
# Let's do the backup
|
|
|
|
#
|
|
|
|
i=0
|
2006-04-29 10:58:57 +00:00
|
|
|
while [ "$i" -lt "$no_sources" ]; do
|
2005-11-17 11:33:49 +00:00
|
|
|
|
2005-11-17 15:52:44 +00:00
|
|
|
#
|
2006-04-29 10:58:57 +00:00
|
|
|
# Get current source
|
2005-11-17 15:52:44 +00:00
|
|
|
#
|
2006-04-29 10:58:57 +00:00
|
|
|
eval name=\$source_${i}
|
2006-01-22 11:21:35 +00:00
|
|
|
i=$(($i+1))
|
2006-01-13 16:07:20 +00:00
|
|
|
|
|
|
|
export name
|
|
|
|
|
2006-01-13 15:37:22 +00:00
|
|
|
#
|
|
|
|
# start ourself, if we want parallel execution
|
|
|
|
#
|
|
|
|
if [ "$PARALLEL" ]; then
|
2006-04-25 13:35:56 +00:00
|
|
|
"$0" "$INTERVAL" "$name" &
|
2006-01-13 15:37:22 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2006-01-13 16:07:20 +00:00
|
|
|
#
|
|
|
|
# Start subshell for easy log editing
|
|
|
|
#
|
|
|
|
(
|
|
|
|
#
|
|
|
|
# Stderr to stdout, so we can produce nice logs
|
|
|
|
#
|
|
|
|
exec 2>&1
|
|
|
|
|
2006-01-13 15:37:22 +00:00
|
|
|
#
|
|
|
|
# Standard locations
|
|
|
|
#
|
2005-12-06 15:20:43 +00:00
|
|
|
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-08 10:08:15 +00:00
|
|
|
c_verbose="$backup/verbose"
|
2006-01-22 09:40:40 +00:00
|
|
|
c_vverbose="$backup/very_verbose"
|
2006-01-09 12:24:27 +00:00
|
|
|
c_rsync_extra="$backup/rsync_options"
|
2006-01-24 20:46:49 +00:00
|
|
|
c_summary="$backup/summary"
|
2005-12-06 15:20:43 +00:00
|
|
|
|
2006-01-22 11:21:35 +00:00
|
|
|
c_pre_exec="$backup/pre_exec"
|
|
|
|
c_post_exec="$backup/post_exec"
|
|
|
|
|
2006-04-29 21:46:29 +00:00
|
|
|
begin=$($DDATE)
|
2006-01-25 22:37:52 +00:00
|
|
|
begin_s=$(date +%s)
|
|
|
|
|
|
|
|
echo "$begin Beginning to backup"
|
2006-01-13 16:07:20 +00:00
|
|
|
|
2005-12-06 15:36:28 +00:00
|
|
|
#
|
|
|
|
# Standard configuration checks
|
|
|
|
#
|
2005-12-08 09:57:36 +00:00
|
|
|
if [ ! -e "$backup" ]; then
|
2006-01-13 16:07:20 +00:00
|
|
|
echo "Source does not exist."
|
2006-01-13 16:39:17 +00:00
|
|
|
exit 1
|
2005-12-08 09:57:36 +00:00
|
|
|
fi
|
2005-11-17 15:52:44 +00:00
|
|
|
if [ ! -d "$backup" ]; then
|
2006-01-13 16:07:20 +00:00
|
|
|
echo "\"$name\" is not a cconfig-directory. Skipping."
|
2006-01-13 16:39:17 +00:00
|
|
|
exit 1
|
2005-11-17 15:52:44 +00:00
|
|
|
fi
|
2005-12-06 15:20:43 +00:00
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
2006-04-25 13:35:56 +00:00
|
|
|
# interval definition: First try source specific, fallback to default
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
2006-04-25 13:35:56 +00:00
|
|
|
c_interval="$(cat "$backup/intervals/$INTERVAL" 2>/dev/null)"
|
2005-12-07 16:41:20 +00:00
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
if [ -z "$c_interval" ]; then
|
|
|
|
c_interval=$D_INTERVAL
|
2005-12-07 16:41:20 +00:00
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
if [ -z "$c_interval" ]; then
|
|
|
|
echo "Default and source specific interval missing. Skipping."
|
2006-01-13 16:39:17 +00:00
|
|
|
exit 1
|
2005-12-07 16:41:20 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
2006-01-24 20:46:49 +00:00
|
|
|
# unset possible options
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
|
|
|
EXCLUDE=""
|
2006-01-09 12:24:27 +00:00
|
|
|
RSYNC_EXTRA=""
|
2006-01-24 20:46:49 +00:00
|
|
|
SUMMARY=""
|
|
|
|
VERBOSE=""
|
|
|
|
VVERBOSE=""
|
2005-12-07 16:41:20 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# next configuration checks
|
|
|
|
#
|
2005-11-17 15:52:44 +00:00
|
|
|
if [ ! -f "$c_source" ]; then
|
2006-01-13 16:39:17 +00:00
|
|
|
echo "Source description $c_source is not a file. Skipping."
|
|
|
|
exit 1
|
2005-11-17 15:52:44 +00:00
|
|
|
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
|
2006-01-13 22:10:23 +00:00
|
|
|
echo "Skipping: Source $c_source is not readable"
|
2006-01-13 16:39:17 +00:00
|
|
|
exit 1
|
2005-12-06 11:50:36 +00:00
|
|
|
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
|
2006-01-13 16:39:17 +00:00
|
|
|
echo "Destination $c_dest does not link to a directory. Skipping"
|
|
|
|
exit 1
|
2005-11-17 15:52:44 +00:00
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-01-22 11:21:35 +00:00
|
|
|
#
|
|
|
|
# pre_exec
|
|
|
|
#
|
|
|
|
if [ -x "$c_pre_exec" ]; then
|
2006-01-22 11:37:04 +00:00
|
|
|
echo "Executing $c_pre_exec ..."
|
2006-03-19 00:01:16 +00:00
|
|
|
"$c_pre_exec"
|
2006-01-22 11:37:04 +00:00
|
|
|
echo "Finished ${c_pre_exec}."
|
2006-03-19 00:02:28 +00:00
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "$c_pre_exec failed, aborting backup."
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-01-22 11:21:35 +00:00
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2005-12-08 10:08:15 +00:00
|
|
|
# exclude
|
2005-12-06 11:50:36 +00:00
|
|
|
if [ -f "$c_exclude" ]; then
|
2005-12-08 10:28:16 +00:00
|
|
|
EXCLUDE="--exclude-from=$c_exclude"
|
2005-12-06 11:50:36 +00:00
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-01-09 12:24:27 +00:00
|
|
|
# extra options for rsync
|
|
|
|
if [ -f "$c_rsync_extra" ]; then
|
|
|
|
RSYNC_EXTRA="$(cat "$c_rsync_extra")"
|
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-01-24 20:46:49 +00:00
|
|
|
# Output a summary
|
|
|
|
if [ -f "$c_summary" ]; then
|
|
|
|
SUMMARY="--stats"
|
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-04-25 13:19:53 +00:00
|
|
|
# Verbosity for rsync
|
2006-03-19 00:10:58 +00:00
|
|
|
if [ -f "$c_verbose" ]; then
|
|
|
|
VERBOSE="-v"
|
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-01-22 09:46:58 +00:00
|
|
|
# MORE verbosity, includes standard verbosity
|
2006-01-22 09:40:40 +00:00
|
|
|
if [ -f "$c_vverbose" ]; then
|
2006-01-22 09:46:58 +00:00
|
|
|
VERBOSE="-v"
|
2006-01-22 09:40:40 +00:00
|
|
|
VVERBOSE="-v"
|
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
2005-12-07 17:36:25 +00:00
|
|
|
# check if maximum number of backups is reached, if so remove
|
2005-12-07 16:41:20 +00:00
|
|
|
#
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
# the created directories are named $INTERVAL.$DA
|
|
|
|
count=$(ls -d "$c_dest/${INTERVAL}."?* 2>/dev/null | wc -l)
|
2006-02-05 23:25:30 +00:00
|
|
|
echo -n "Currently $count backup(s) exist(s),"
|
2006-04-25 13:35:56 +00:00
|
|
|
echo " total keeping $c_interval backup(s)."
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
if [ "$count" -ge "$c_interval" ]; then
|
|
|
|
substract=$(echo $c_interval - 1 | bc)
|
2005-12-07 17:36:25 +00:00
|
|
|
remove=$(echo $count - $substract | bc)
|
2006-01-13 16:39:17 +00:00
|
|
|
echo "Removing $remove backup(s)..."
|
2005-12-07 17:36:25 +00:00
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
ls -d "$c_dest/${INTERVAL}."?* | sort -n | head -n $remove > "$TMP"
|
2005-12-07 17:36:25 +00:00
|
|
|
while read to_remove; do
|
2005-12-08 09:27:39 +00:00
|
|
|
dir="$to_remove"
|
2006-01-13 16:39:17 +00:00
|
|
|
echo "Removing $dir ..."
|
2006-01-22 09:40:40 +00:00
|
|
|
rm $VVERBOSE -rf "$dir"
|
2005-12-07 17:36:25 +00:00
|
|
|
done < "$TMP"
|
|
|
|
fi
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2005-12-06 16:08:38 +00:00
|
|
|
#
|
|
|
|
# clone the old directory with hardlinks
|
|
|
|
#
|
|
|
|
|
2006-04-29 21:41:12 +00:00
|
|
|
destination_date=$($CDATE)
|
2006-04-25 13:35:56 +00:00
|
|
|
destination_dir="$c_dest/${INTERVAL}.${destination_date}.$$"
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-04-25 13:35:56 +00:00
|
|
|
last_dir=$(ls -d "$c_dest/${INTERVAL}."?* 2>/dev/null | sort -n | tail -n 1)
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2005-12-08 13:15:45 +00:00
|
|
|
# give some info
|
2006-01-13 16:39:17 +00:00
|
|
|
echo "Beginning to backup, this may take some time..."
|
2005-12-08 09:27:39 +00:00
|
|
|
|
2006-03-19 00:10:58 +00:00
|
|
|
echo "Creating $destination_dir ..."
|
|
|
|
mkdir $VVERBOSE "$destination_dir"
|
|
|
|
|
2005-12-08 09:29:19 +00:00
|
|
|
# only copy if a directory exists
|
2005-12-08 09:51:03 +00:00
|
|
|
if [ "$last_dir" ]; then
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Hard linking..."
|
2006-03-19 00:10:58 +00:00
|
|
|
cd "$last_dir"
|
2006-04-28 14:43:41 +00:00
|
|
|
pax -rwl -p e $VVERBOSE . "$destination_dir"
|
2006-03-19 00:10:58 +00:00
|
|
|
# old, gnu cp specific
|
|
|
|
# cp -al $VVERBOSE "$last_dir" "$destination_dir"
|
2005-12-08 09:27:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
2006-04-29 21:46:29 +00:00
|
|
|
echo -n "$($DDATE) Creating/cloning backup directory failed."
|
2006-02-07 20:22:39 +00:00
|
|
|
echo " Skipping backup."
|
2006-01-13 16:39:17 +00:00
|
|
|
exit 1
|
2005-12-08 09:27:39 +00:00
|
|
|
fi
|
|
|
|
|
2005-12-06 16:08:38 +00:00
|
|
|
#
|
|
|
|
# the rsync part
|
2006-01-13 15:37:22 +00:00
|
|
|
# options partly stolen from rsnapshot
|
2005-12-06 16:08:38 +00:00
|
|
|
#
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Transferring files..."
|
2006-01-13 15:14:41 +00:00
|
|
|
|
2006-01-24 20:46:49 +00:00
|
|
|
rsync -a $VERBOSE $RSYNC_EXTRA $EXCLUDE $SUMMARY \
|
2006-01-13 15:37:22 +00:00
|
|
|
--delete --numeric-ids --relative --delete-excluded \
|
2006-01-13 16:07:20 +00:00
|
|
|
"$source" "$destination_dir"
|
2006-01-13 15:37:22 +00:00
|
|
|
|
2006-01-13 16:07:20 +00:00
|
|
|
if [ "$?" -ne 0 ]; then
|
2006-02-04 10:06:24 +00:00
|
|
|
echo "rsync reported an error. The backup may be broken (see rsync errors)"
|
2005-12-08 09:27:39 +00:00
|
|
|
fi
|
2006-01-13 16:07:20 +00:00
|
|
|
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Finished backup"
|
2006-01-22 11:37:04 +00:00
|
|
|
|
2006-01-22 11:21:35 +00:00
|
|
|
#
|
|
|
|
# post_exec
|
|
|
|
#
|
|
|
|
if [ -x "$c_post_exec" ]; then
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Executing $c_post_exec ..."
|
2006-01-22 11:37:04 +00:00
|
|
|
"$c_post_exec"
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Finished ${c_post_exec}."
|
2006-03-19 00:13:38 +00:00
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "$c_post_exec failed."
|
|
|
|
fi
|
2006-01-22 11:21:35 +00:00
|
|
|
fi
|
2006-01-13 16:07:20 +00:00
|
|
|
|
2006-01-25 22:37:52 +00:00
|
|
|
end_s=$(date +%s)
|
|
|
|
|
|
|
|
full_seconds=$(echo "$end_s - $begin_s" | bc -l)
|
|
|
|
hours=$(echo $full_seconds / 3600 | bc)
|
|
|
|
seconds=$(echo "$full_seconds - ($hours * 3600)" | bc)
|
|
|
|
minutes=$(echo $seconds / 60 | bc)
|
|
|
|
seconds=$(echo "$seconds - ($minutes * 60)" | bc)
|
|
|
|
|
2006-04-28 22:30:02 +00:00
|
|
|
echo "Backup lasted: ${hours}:${minutes}:${seconds} (h:m:s)"
|
2006-01-25 22:37:52 +00:00
|
|
|
|
2006-01-13 16:07:20 +00:00
|
|
|
) | add_name
|
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
|
|
|
|
#
|
2006-01-09 12:56:09 +00:00
|
|
|
if [ "$PARALLEL" ]; then
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Waiting for child jobs to complete..."
|
2005-12-06 16:08:38 +00:00
|
|
|
wait
|
|
|
|
fi
|
|
|
|
|
2006-01-22 10:13:22 +00:00
|
|
|
#
|
|
|
|
# Look for post-exec command (general)
|
|
|
|
#
|
2006-01-22 11:37:04 +00:00
|
|
|
if [ -x "$CPOSTEXEC" ]; then
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Executing $CPOSTEXEC ..."
|
2006-01-22 11:37:04 +00:00
|
|
|
"$CPOSTEXEC"
|
2006-04-29 21:46:29 +00:00
|
|
|
echo "$($DDATE) Finished ${CPOSTEXEC}."
|
2006-04-25 13:28:54 +00:00
|
|
|
|
2006-03-19 00:13:38 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "$CPOSTEXEC failed."
|
|
|
|
fi
|
2006-01-22 10:13:22 +00:00
|
|
|
fi
|
|
|
|
|
2005-12-06 14:55:07 +00:00
|
|
|
rm -f "$TMP"
|
2006-01-09 12:56:09 +00:00
|
|
|
echo "==> Finished $WE <=="
|