Local and remote back up behave differently

David Highley dhighley at highley-recommended.com
Sun Aug 25 14:38:41 MDT 2013


I have run out of ideas on why the local and remote back ups done with
the script below behave differently. The local always seems to be a
complete back up while the remotes are delta back ups except on Mondays.

Cron line example:
/root/bin/backups /export/home redwood "--exclude='*.sock' --exclude='*cache*' --exclude=/export/home/*/.gvfs"


#!/bin/bash

# Script for one week incremental rsync back up scheme.

if [ $# -lt 2 ]; then
    echo "Usage: $name source server [ filters, --exclude ]" >&2
    exit 1
fi

trap cleanup 2 3 6 9 10 12 13 15 16 17 18 19 20 23 24 30 31

# Get our script name, the source directory to be transfered,
# server to send to, and optional filtering, --exclude.
name=`basename $0`
base=`basename $1`
source=$1
server=$2
if [ $# -eq 3 ]; then
    filters=$3
fi

# Day of week, 1 to 7.
day=`/bin/date '+%u'`

# Set the options to be used, using -X is not useful with selinux.
# Archive with hard links all attributes and relative paths.
# Run verbose, can create a cron log message to big for email.
# Day of week, 1 to 7; where Monday is 1.
#if [ ${day} -eq 7 ]; then do a full backup
if [ ${day} -eq 7 ]; then
    options='-qaHAR' 
else
    options='-qauHAR'
fi

# Signal handler for abort clean up of lock file.
cleanup()
{
    echo "Caught Signal removing lock file /tmp/${name}.${base}.${server}" >&2
    rm -f /tmp/${name}.${base}.${server}
    exit 0
}

if [ ! -d "${source}" ]; then
    echo "Source ${source} not found."
    exit 2
fi

# Get this systems hostname and
# check if we are backing up to the
# system the script is running on.
ItIsI=`uname -n`
if [ "${server}" = "${ItIsI}" ]; then
    if [ -d /backups ]; then
        dest="/backups/${server}" 
        options+=" --backup-dir=${source}.${day}" 
    else
        echo "Directory /backups does not exist."
        exit 3
    fi
else
    # Set a time out in case the server goes away.
    # We are using hostname for the rsync module parameter.
    dest="${server}::${ItIsI}" 
    options+=" --contimeout=300 --backup-dir=${source}.${day}" 
    # Test if we can talk to back up server.
    ping -c 1 ${server} >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "Could not ping server ${server}" >&2
        exit 4
    fi
fi

# Use flock file to prevent overlap per source, ${1}.
flock -xn /tmp/${name}.${base}.${server} \
    -c "rsync ${options} ${filters} --ignore-errors --delete-excluded --delete --delete-during ${source} ${dest}"

rm -f /tmp/${name}.${base}.${server}

exit 0



More information about the rsync mailing list