1.7.0: detailed logfile

This commit is contained in:
Vincent Riquer 2012-07-27 15:34:52 +02:00
parent e02712d23d
commit 89ea22174c
2 changed files with 45 additions and 33 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
remote-backup (1.7) stable; urgency=low
* detailed logfile
-- Vincent Riquer <v.riquer@b2f-concept.com> Fri, 27 Jul 2012 15:33:55 +0200
remote-backup (1.6.3) stable; urgency=low remote-backup (1.6.3) stable; urgency=low
* Syntax requires bash >= 3.1 * Syntax requires bash >= 3.1

View File

@ -13,7 +13,7 @@
###BEGIN: generic tool checker ###BEGIN: generic tool checker
# FIXME: To reuse this function, be sure to edit this line (space separated # FIXME: To reuse this function, be sure to edit this line (space separated
# list). # list).
needed_tools="id echo mount rm mv cp touch rsync" needed_tools="id echo mount rm mv cp touch rsync snmptrap"
# #
# One shall not need edit anything below this line # One shall not need edit anything below this line
### ###
@ -111,7 +111,7 @@ doBackup() {
source "$config" source "$config"
backupIndex+=( "$NAME" ) backupIndex+=( "$NAME" )
echo "Debut de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${NAME}/ a $(date +"%H:%M, le %d/%m/%Y")" echo "$(date +"%Y-%m-%d:%H:%M:%S") ${REMOTE_LOCATION} to ${SNAPSHOT_RW}/${NAME}/"
if [[ "$REMOUNT" == "true" ]] if [[ "$REMOUNT" == "true" ]]
then then
@ -119,7 +119,7 @@ doBackup() {
mountMsg="$( $MOUNT -o remount,rw "$MOUNT_DEVICE" "$SNAPSHOT_RW" 2>&1 )" ; mountMsg="$( $MOUNT -o remount,rw "$MOUNT_DEVICE" "$SNAPSHOT_RW" 2>&1 )" ;
if (( $? )) if (( $? ))
then then
echo "snapshot: could not remount $SNAPSHOT_RW readwrite" >&2 echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tCould not remount $SNAPSHOT_RW readwrite" >&2
backupStatus+=( 4 ) backupStatus+=( 4 )
backupStatusInfo+=( "$MOUNT_DEVICE: $mountMsg" ) backupStatusInfo+=( "$MOUNT_DEVICE: $mountMsg" )
return 1 return 1
@ -128,6 +128,7 @@ doBackup() {
if [ ! -d "$SNAPSHOT_RW/$NAME" ] if [ ! -d "$SNAPSHOT_RW/$NAME" ]
then then
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tCreating directory $SNAPSHOT_RW/$NAME"
mkdir -p "$SNAPSHOT_RW/$NAME" mkdir -p "$SNAPSHOT_RW/$NAME"
fi fi
@ -144,6 +145,7 @@ doBackup() {
then then
backupStatus+=( 5 ) backupStatus+=( 5 )
backupStatusInfo+=( "Process $(<"$SNAPSHOT_RW/$NAME/.lock") still running" ) backupStatusInfo+=( "Process $(<"$SNAPSHOT_RW/$NAME/.lock") still running" )
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tProcess $(<"$SNAPSHOT_RW/$NAME/.lock") still running"
else else
echo $$ > "$SNAPSHOT_RW/$NAME/.lock" echo $$ > "$SNAPSHOT_RW/$NAME/.lock"
rotateBackup rotateBackup
@ -164,28 +166,30 @@ doBackup() {
$MOUNT -o remount,ro "$MOUNT_DEVICE" "$SNAPSHOT_RW" $MOUNT -o remount,ro "$MOUNT_DEVICE" "$SNAPSHOT_RW"
if (( $? )) if (( $? ))
then then
echo "snapshot: could not remount $SNAPSHOT_RW readonly" >&2 echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tCould not remount $SNAPSHOT_RW readonly" >&2
fi fi
fi fi
echo "Fin de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${NAME}/ a $(date +"%H:%M, le %d/%m/%Y")" echo -e "$(date +%Y-%m-%d:%H:%M:%S) ${REMOTE_LOCATION} to ${SNAPSHOT_RW}/${NAME} done."
echo '-----------------------------------------------------------------------' echo '-----------------------------------------------------------------------'
} }
rotateBackup() { rotateBackup() {
# rotating snapshots # rotating snapshots
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tRotate backups"
if [ -f "$SNAPSHOT_RW/$NAME/daily.0" ] if [ -f "$SNAPSHOT_RW/$NAME/daily.0" ]
then then
echo "Previous backup failed, skipping rotation." echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tPrevious backup failed, skipping rotation."
rm "$SNAPSHOT_RW/$NAME/daily.0" rm "$SNAPSHOT_RW/$NAME/daily.0"
elif [ -f "$SNAPSHOT_RW/$NAME/daily.0/unfinished.remote-backup" ] elif [ -f "$SNAPSHOT_RW/$NAME/daily.0/unfinished.remote-backup" ]
then then
echo "Previous backup interrupted, skipping rotation." echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tPrevious backup interrupted, skipping rotation."
rm "$SNAPSHOT_RW/$NAME/daily.0/unfinished.remote-backup" rm "$SNAPSHOT_RW/$NAME/daily.0/unfinished.remote-backup"
else else
# step 1: delete the oldest snapshot, if it exists: # step 1: delete the oldest snapshot, if it exists:
if [ -d "$SNAPSHOT_RW/$NAME/daily.${MAX_ROTATE}" ] if [ -d "$SNAPSHOT_RW/$NAME/daily.${MAX_ROTATE}" ]
then then
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tDeleting $SNAPSHOT_RW/$NAME/daily.${MAX_ROTATE}"
$RM -rf "$SNAPSHOT_RW/$NAME/daily.${MAX_ROTATE}" $RM -rf "$SNAPSHOT_RW/$NAME/daily.${MAX_ROTATE}"
fi fi
@ -194,7 +198,11 @@ rotateBackup() {
do do
if [ -d "$SNAPSHOT_RW/$NAME/daily.${backup_num}" ] if [ -d "$SNAPSHOT_RW/$NAME/daily.${backup_num}" ]
then then
$MV -f "$SNAPSHOT_RW/$NAME/daily.${backup_num}" \ echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tRename" \
"$SNAPSHOT_RW/$NAME/daily.${backup_num}" \
"to" \
"$SNAPSHOT_RW/$NAME/daily.$(( backup_num + 1 ))"
$MV -f "$SNAPSHOT_RW/$NAME/daily.${backup_num}" \
"$SNAPSHOT_RW/$NAME/daily.$(( backup_num + 1 ))" "$SNAPSHOT_RW/$NAME/daily.$(( backup_num + 1 ))"
fi fi
done done
@ -204,7 +212,13 @@ rotateBackup() {
runBackup() { runBackup() {
# step 3: rsync from the system, linking to latest snapshot if files are # step 3: rsync from the system, linking to latest snapshot if files are
# identical. # identical.
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tBuilding rsync command"
RSYNC_OPTS="-a --exclude-from=$EXCLUDES --bwlimit=$BWLIMIT" RSYNC_OPTS="-a --exclude-from=$EXCLUDES --bwlimit=$BWLIMIT"
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tBase options: $RSYNC_OPTS"
if [ -n "$ADDITIONAL_RSYNC_OPTS" ]
then
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tTarget-specific: $ADDITIONAL_RSYNC_OPTS"
fi
if [[ $2 == PROTOCOLMISMATCH ]] if [[ $2 == PROTOCOLMISMATCH ]]
then then
@ -213,18 +227,21 @@ runBackup() {
proto29=1 proto29=1
MAX_ROTATE=1 MAX_ROTATE=1
fi fi
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tLooking for older snapshots"
for old_backup in "$SNAPSHOT_RW/$NAME/emerg".*
do
if [ -d "$old_backup" ] && ! (( proto29 ))
then
RSYNC_OPTS="$RSYNC_OPTS --link-dest=$old_backup"
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\t\t$old_backup"
fi
done
for (( backup_num=1 ; backup_num <= MAX_ROTATE ; backup_num++ )) for (( backup_num=1 ; backup_num <= MAX_ROTATE ; backup_num++ ))
do do
if [ -d "$SNAPSHOT_RW/$NAME/daily.$backup_num" ] if [ -d "$SNAPSHOT_RW/$NAME/daily.$backup_num" ]
then then
RSYNC_OPTS="$RSYNC_OPTS --link-dest=$SNAPSHOT_RW/$NAME/daily.$backup_num" RSYNC_OPTS="$RSYNC_OPTS --link-dest=$SNAPSHOT_RW/$NAME/daily.$backup_num"
fi echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\t\tdaily.$backup_num"
done
for old_backup in "$SNAPSHOT_RW/$NAME/emerg".*
do
if [ -d "$old_backup" ]
then
RSYNC_OPTS="$RSYNC_OPTS --link-dest=$old_backup"
fi fi
done done
if (( TIMEOUT )) if (( TIMEOUT ))
@ -233,17 +250,19 @@ runBackup() {
else else
RSYNC_OPTS="$RSYNC_OPTS --timeout=1800" RSYNC_OPTS="$RSYNC_OPTS --timeout=1800"
fi fi
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tTimeout is ${TIMEOUT:-1800} seconds"
# Not root? use --fake-super # Not root? use --fake-super
if (( UID > 0 )) if (( UID > 0 ))
then then
echo "(info) running as user, using --fake-super." echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tRunning as user, using --fake-super."
RSYNC_OPTS="$RSYNC_OPTS --fake-super" RSYNC_OPTS="$RSYNC_OPTS --fake-super"
fi fi
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tComplete rsync command: $RSYNC $RSYNC_OPTS $ADDITIONAL_RSYNC_OPTS $REMOTE_LOCATION $SNAPSHOT_RW/$NAME/$1"
for (( try=1 ; try <= RETRY ; try++ )) for (( try=1 ; try <= RETRY ; try++ ))
do do
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\tRunning rsync #$try/$RETRY"
$RSYNC \ $RSYNC \
$RSYNC_OPTS \ $RSYNC_OPTS \
$ADDITIONAL_RSYNC_OPTS \ $ADDITIONAL_RSYNC_OPTS \
@ -263,18 +282,9 @@ runBackup() {
*) *)
if (( try == RETRY )) if (( try == RETRY ))
then then
cat <<-EOF echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tFailed, Giving up."
Trial $try / $RETRY failed, Giving up!
EOF
else else
cat <<-EOF echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tFailed. Sleeping $RETRY_DELAY..."
Trial $try / $RETRY failed.
Sleeping $RETRY_DELAY...
EOF
sleep $RETRY_DELAY sleep $RETRY_DELAY
fi fi
;; ;;
@ -290,11 +300,7 @@ runBackup() {
then then
failRsync PROTO_MISMATCH failRsync PROTO_MISMATCH
else else
cat <<-EOF echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t\tRsync protocol mismatch, trying with only one --link-dest"
Rsync protocol mismatch, trying with only one --link-dest
EOF
runBackup "$1" PROTOCOLMISMATCH runBackup "$1" PROTOCOLMISMATCH
fi fi
;; ;;