Many preparations for 0.6
This commit is contained in:
parent
ca6c8f60f8
commit
624e5b419b
1 changed files with 77 additions and 80 deletions
157
ccollect.sh
157
ccollect.sh
|
@ -321,10 +321,10 @@ while [ "$i" -lt "$no_sources" ]; do
|
||||||
# destination _must_ be a directory
|
# destination _must_ be a directory
|
||||||
#
|
#
|
||||||
if [ ! -d "${c_dest}" ]; then
|
if [ ! -d "${c_dest}" ]; then
|
||||||
_exit_err "Destination ${c_dest} neither links to nor is a directory. Skipping."
|
_exit_err "Destination ${c_dest} is not a directory. Skipping."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# NEW
|
# NEW method as of 0.6:
|
||||||
# - insert ccollect default parameters
|
# - insert ccollect default parameters
|
||||||
# - insert options
|
# - insert options
|
||||||
# - insert user options
|
# - insert user options
|
||||||
|
@ -333,7 +333,9 @@ while [ "$i" -lt "$no_sources" ]; do
|
||||||
# rsync standard options
|
# rsync standard options
|
||||||
#
|
#
|
||||||
|
|
||||||
ouropts="-a --delete --numeric-ids --relative --delete-excluded"
|
set -- "$@" "--archive" "--delete" "--numeric-ids" "--relative" \
|
||||||
|
"--delete-excluded" "--sparse"
|
||||||
|
|
||||||
#
|
#
|
||||||
# exclude list
|
# exclude list
|
||||||
#
|
#
|
||||||
|
@ -366,44 +368,54 @@ while [ "$i" -lt "$no_sources" ]; do
|
||||||
done < "${c_rsync_extra}"
|
done < "${c_rsync_extra}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# #
|
#
|
||||||
# # show if we shall remove partial backup, and whether the last one
|
# Check for incomplete backups
|
||||||
# # is incomplete or not
|
#
|
||||||
# #
|
(
|
||||||
# # FIXME: test general for incomplete and decide only for warn|delete based on option?
|
set -x
|
||||||
# # FIXME: Define which is the last dir before? Or put this thing into
|
cd "${c_dest}"
|
||||||
# # a while loop? Is it senseful to remove _ALL_ backups if non is complete?
|
ls
|
||||||
# if [ -f "$c_incomplete" ]; then
|
ls "${INTERVAL}"*/.ccollect-* > "${TMP}"
|
||||||
# echo "Searching for incomplete backups..."
|
cat "${TMP}"
|
||||||
# last_dir=$(ls -d "$c_dest/${INTERVAL}."?* 2>/dev/null | sort -n | tail -n 1)
|
|
||||||
#
|
while read broken; do
|
||||||
# # check whether the last backup was incomplete
|
realbroken=$(echo $broken | sed 's/.ccollect-*/')
|
||||||
# # STOPPED HERE
|
echo "Broken backup"
|
||||||
# # todo: implement rm -rf, implement warning on non-cleaning
|
done
|
||||||
# # implement the marknig and normal removing
|
)
|
||||||
# if [ "$last_dir" ]; then
|
sleep 10
|
||||||
# incomplete=$(cd "$last_dir" && ls .ccollect-????-??-)
|
while read incomplete; do
|
||||||
# if [ "$incomplete" ]; then
|
echo "${incomplete} is incomplete"
|
||||||
# "Removing incomplete backup $last_dir ..."
|
done < "${TMP}"
|
||||||
# echo rm -rf $VVERBOSE "$last_dir"
|
|
||||||
# fi
|
last_dir=$(ls -d "$c_dest/${INTERVAL}."?* 2>/dev/null | sort -n | tail -n 1)
|
||||||
# fi
|
|
||||||
# fi
|
|
||||||
#
|
|
||||||
#
|
#
|
||||||
# check if maximum number of backups is reached, if so remove
|
# check if maximum number of backups is reached, if so remove
|
||||||
#
|
#
|
||||||
|
|
||||||
# FIXME: really do fuzzy matching here?
|
#
|
||||||
# or simply declare "everything of that directory (which is a directory) is
|
# Check for backup directory to clone from
|
||||||
# a ccollect-backiup directory"?
|
#
|
||||||
# the created directories are named $INTERVAL-$DATE-$TIME.$PID
|
found_old=0
|
||||||
|
(
|
||||||
|
# can we use ls? or will it produce broken results?
|
||||||
|
#cd "${c_dest}" && ls -dp1 | grep "^${INTERVAL}\..*/\$" | wc -l | sed 's/^ *//g')
|
||||||
|
cd "${c_dest}" && ls -dp1 "${INTERVAL}".* > "${TMP}"
|
||||||
|
)
|
||||||
|
while read old; do
|
||||||
|
echo "Found ${old}"
|
||||||
|
done < "${TMP}"
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check for backups on other intervals, if we did not find any
|
||||||
|
#
|
||||||
|
|
||||||
count=$(cd "${c_dest}" && ls -p1 | grep "^${INTERVAL}\..*/\$" | wc -l | sed 's/^ *//g')
|
count=$(cd "${c_dest}" && ls -p1 | grep "^${INTERVAL}\..*/\$" | wc -l | sed 's/^ *//g')
|
||||||
# FIXME: check return value
|
# FIXME: check return value
|
||||||
echo -n "Currently ${count} backup(s) exist(s),"
|
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}"
|
||||||
echo " total keeping ${c_interval} backup(s)."
|
|
||||||
|
|
||||||
# STOPPED!
|
|
||||||
if [ "${count}" -ge "${c_interval}" ]; then
|
if [ "${count}" -ge "${c_interval}" ]; then
|
||||||
substract=$((${c_interval} - 1))
|
substract=$((${c_interval} - 1))
|
||||||
remove=$(($count - $substract))
|
remove=$(($count - $substract))
|
||||||
|
@ -422,8 +434,6 @@ while [ "$i" -lt "$no_sources" ]; do
|
||||||
# clone the old directory with hardlinks
|
# clone the old directory with hardlinks
|
||||||
#
|
#
|
||||||
|
|
||||||
# FIXME: STOPPED
|
|
||||||
|
|
||||||
destination_date=$($CDATE)
|
destination_date=$($CDATE)
|
||||||
destination_dir="$c_dest/${INTERVAL}.${destination_date}.$$"
|
destination_dir="$c_dest/${INTERVAL}.${destination_date}.$$"
|
||||||
|
|
||||||
|
@ -462,55 +472,42 @@ while [ "$i" -lt "$no_sources" ]; do
|
||||||
# 0.5.3!
|
# 0.5.3!
|
||||||
#
|
#
|
||||||
|
|
||||||
# Clone from previous backup, if existing
|
set -x
|
||||||
if [ "$last_dir" ]; then
|
rsync "$@" "$source" "$abs_destination_dir"; ret=$?
|
||||||
|
# abs_last_dir="$(cd "$last_dir" && pwd -P)"
|
||||||
#
|
# if [ -z "$abs_last_dir" ]; then
|
||||||
# This directory MUST be absolute, because rsync does chdir()
|
# echo "Changing to the last backup directory failed. Skipping."
|
||||||
# before beginning backup!
|
# exit 1
|
||||||
#
|
# fi
|
||||||
|
# rsync_hardlink="--link-dest=$abs_last_dir"
|
||||||
abs_last_dir="$(cd "$last_dir" && pwd -P)"
|
|
||||||
if [ -z "$abs_last_dir" ]; then
|
|
||||||
echo "Changing to the last backup directory failed. Skipping."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rsync_hardlink="--link-dest=$abs_last_dir"
|
|
||||||
rsync $ouropts "$rsync_hardlink" $useropts "$source" "$abs_destination_dir"
|
|
||||||
else
|
|
||||||
rsync $ouropts $useropts "$source" "$abs_destination_dir"
|
|
||||||
fi
|
|
||||||
|
|
||||||
ret=$?
|
|
||||||
|
|
||||||
echo "Rsync return code: $ret."
|
|
||||||
|
|
||||||
|
set +x
|
||||||
if [ "$ret" -ne 0 ]; then
|
if [ "$ret" -ne 0 ]; then
|
||||||
echo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
|
echo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# FIXME: remove marking here
|
# remove marking here
|
||||||
# rm -f $c_marker
|
|
||||||
#
|
#
|
||||||
|
rm -f "${abs_destination_dir}/${c_marker}"
|
||||||
|
|
||||||
|
_techo "Finished backup (rsync return code: $ret)."
|
||||||
|
|
||||||
echo "$($DDATE) Finished backup"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# post_exec
|
# post_exec
|
||||||
#
|
#
|
||||||
if [ -x "$c_post_exec" ]; then
|
if [ -x "${c_post_exec}" ]; then
|
||||||
echo "$($DDATE) Executing $c_post_exec ..."
|
_techo "Executing ${c_post_exec} ..."
|
||||||
"$c_post_exec"
|
"${c_post_exec}"; ret=$?
|
||||||
ret=$?
|
_techo "Finished ${c_post_exec}."
|
||||||
echo "$($DDATE) Finished ${c_post_exec}."
|
|
||||||
|
|
||||||
if [ $ret -ne 0 ]; then
|
if [ ${ret} -ne 0 ]; then
|
||||||
echo "$c_post_exec failed."
|
_exit_err "${c_post_exec} failed."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Calculation
|
||||||
end_s=$(date +%s)
|
end_s=$(date +%s)
|
||||||
|
|
||||||
full_seconds=$((${end_s} - ${begin_s}))
|
full_seconds=$((${end_s} - ${begin_s}))
|
||||||
|
@ -519,7 +516,7 @@ while [ "$i" -lt "$no_sources" ]; do
|
||||||
minutes=$(($seconds / 60))
|
minutes=$(($seconds / 60))
|
||||||
seconds=$((${seconds} - (${minutes} * 60)))
|
seconds=$((${seconds} - (${minutes} * 60)))
|
||||||
|
|
||||||
echo "Backup lasted: ${hours}:${minutes}:${seconds} (h:m:s)"
|
_techo "Backup lasted: ${hours}:${minutes}:${seconds} (h:m:s)"
|
||||||
|
|
||||||
) | add_name
|
) | add_name
|
||||||
done
|
done
|
||||||
|
@ -527,24 +524,24 @@ done
|
||||||
#
|
#
|
||||||
# Be a good parent and wait for our children, if they are running wild parallel
|
# Be a good parent and wait for our children, if they are running wild parallel
|
||||||
#
|
#
|
||||||
if [ "$PARALLEL" ]; then
|
if [ "${PARALLEL}" ]; then
|
||||||
echo "$($DDATE) Waiting for child jobs to complete..."
|
_techo "Waiting for child jobs to complete..."
|
||||||
wait
|
wait
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Look for post-exec command (general)
|
# Look for post-exec command (general)
|
||||||
#
|
#
|
||||||
if [ -x "$CPOSTEXEC" ]; then
|
if [ -x "${CPOSTEXEC}" ]; then
|
||||||
echo "$($DDATE) Executing $CPOSTEXEC ..."
|
_techo "Executing ${CPOSTEXEC} ..."
|
||||||
"$CPOSTEXEC"
|
"${CPOSTEXEC}"
|
||||||
ret=$?
|
ret=$?
|
||||||
echo "$($DDATE) Finished ${CPOSTEXEC}."
|
_techo "Finished ${CPOSTEXEC}."
|
||||||
|
|
||||||
if [ $ret -ne 0 ]; then
|
if [ ${ret} -ne 0 ]; then
|
||||||
echo "$CPOSTEXEC failed."
|
echo "${CPOSTEXEC} failed."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$TMP"
|
rm -f "${TMP}"
|
||||||
echo "==> Finished $WE <=="
|
_techo "Finished ${WE}"
|
||||||
|
|
Loading…
Reference in a new issue