Rsnapshot is flawed, claims Espen.   I've stumbled upon a problem he does not directly mention: when a backup run fails, it won't be retried until (ana)cron decides to run the job again. This should not be a problem for hourly runs, but can become troublesome for the weeklies and monthlies. Even worse, cron runs might be correlated with backup failures: when anacron tends to run your backup job two minutes before you connect the external hard drive, you might be without any long-term backup while merrily retiring old hourlies.

I am convinced a better solution will consider all backup lines (including weekly and monthly runs) at each invocation (say, hourly). Here's a proposition: for each line, compare the time stamp of the most recent copy to the oldest copy in the next (more frequent) line. If the difference is sufficiently large, perform a migration.

In other words: if the oldest daily backup is more recent than the latest weekly by at least a week, call rsnapshot weekly to move that copy over.

Here's the script I use:

#!/bin/bash

TARGET=/backup/snapshots

[ -d $TARGET ] || exit 2

function invoke() {
  SERIES=$1
  PERIOD=$2
  PRED=$3
  if [ ! -e $TARGET/$PRED ]; then
    return
  fi
  if [ -e $TARGET/$SERIES.0 ]; then
    MTIME=`stat -c %Y $TARGET/$SERIES.0`
    PTIME=`stat -c %Y $PRED`
    if [ $((PTIME-MTIME)) -gt $PERIOD ]; then
      rsnapshot $1
    fi
  else
    rsnapshot $1
  fi


}

invoke monthly $((30*24*3600)) weekly.4
invoke weekly $((7*24*3600)) daily.6
invoke daily $((24*3600)) hourly.23
rsnapshot hourly

It goes into /etc/cron.hourly, and this is the only place rsnapshot is called -- no more fiddling around with half a dozen cron entries.

Edit: if e.g. rsnapshot weekly is invoked but daily.6 is absent, the oldest weekly snapshot is still deleted, so check for this.

11.35 am Kommentare deaktiviert für A Better Way to Invoke rsnapshot

von kirjoittaessani

Comments are closed.