_hostrun () {
h=$1 cmd=$2
- ## Like hostrun, but without the complicated logging, but targetted at a
+ ## Like hostrun, but without the complicated logging, and targetted at a
## specific host.
if localp $h; then sh -c "$cmd"
}
###--------------------------------------------------------------------------
+### Database operations.
+
+INDEXDB=@pkglocalstatedir@/index.db
+
+insert_index () {
+ host=$1 fs=$2 date=$3 vol=$4
+
+ if [ -f "$INDEXDB" ]; then
+ sqlite3 "$INDEXDB" <<EOF
+INSERT INTO idx (host, fs, date, vol)
+ VALUES ('$host', '$fs', '$date', '$vol');
+EOF
+ fi
+}
+
+delete_index () {
+ host=$1 fs=$2 date=$3
+
+ if [ -f "$INDEXDB" ]; then
+ sqlite3 "$INDEXDB" <<EOF
+DELETE FROM idx WHERE
+ host = '$host' AND fs = '$fs' AND $date = '$date';
+EOF
+ fi
+}
+
+###--------------------------------------------------------------------------
### Snapshot handling.
## Snapshot protocol. Each snapshot type has a pair of functions snap_TYPE
### Actually taking backups of filesystems.
STOREDIR=@mntbkpdir@/store
+METADIR=@mntbkpdir@/meta
MAXLOG=14
HASH=sha256
+unset VOLUME
bkprc=0
echo "delete $date"
$verbose -n " expire $date..."
rm -rf $date $date.*
+ delete_index $host $fs $date
$verbose " done"
;;
esac
backup_precommit_hook $host $fs $date
mv new $date
mv new.fshash $date.fshash
+ insert_index $host $fs $date $VOLUME
backup_commit_hook $host $fs $date
mkdir hack
ln -s $date hack/last
$verbose " commit"
## Expire old backups.
+ case "${expire_policy+t},${default_policy+t}" in
+ ,t) expire_policy=$default_policy ;;
+ esac
case "${expire_policy+t},$dryrun" in
t,nil) run "expiry for $host:$fs" expire_backups ;;
t,t) expire_backups ;;
esac
+ clear_policy=t
## Report success.
case $dryrun in
exit 15
fi
+ ## Read the volume name if we don't have one already. Again, this allows
+ ## the configuration file to provide a volume name.
+ case "${VOLUME+t}${VOLUME-nil}" in
+ nil) VOLUME=$(cat $METADIR/volume) ;;
+ esac
+
## Back up each requested file system in turn.
for fs in "$@"; do
###--------------------------------------------------------------------------
### Configuration functions.
-host () { host=$1; like=; $verbose "host $host"; }
+host () {
+ host=$1
+ like=
+ case "${expire_policy+t},${default_policy+t}" in
+ t,) default_policy=$expire_policy ;;
+ esac
+ unset expire_policy
+ $verbose "host $host"
+}
+
snaptype () { snap=$1; shift; snapargs="$*"; retry=0; }
rsyncargs () { rsyncargs="$*"; }
like () { like="$*"; }
retry () { retry="$*"; }
retain () {
+ case $clear_policy in t) unset expire_policy; clear_policy=nil ;; esac
expire_policy="${expire_policy+$expire_policy
}$*"
}