#!/bin/sh # propagate_hard_links # # This script works in conjunction with the backup directory structure # created by the rsync_snapshot series of scripts. It looks in the # "previous-backup" directory for files, and propogates all files to the # "current-backup" directory as hard links. # # This script is intended for use with "piggyback" backups, where only # changed files are saved in the backup directories, and so a manual # means of keeping hard links to previous backups is required. # # Copyright 2006 Jason Healy, Suffield Academy # BASE=$1 shift # names of the backup symlinks PREV="previous-backup" CURR="current-backup" # path check if [ -z "$BASE" ]; then echo "Usage: propagate_hard_links " echo "" echo " Where is a path to a snapshot directory containing" echo " '$PREV' and '$CURR' links." echo "" exit 1 fi # find links if [ ! -L "$BASE/$PREV" ]; then echo "Unable to find previous backup link '$PREV' in '$BASE'" exit 1 fi if [ ! -L "$BASE/$CURR" ]; then echo "Unable to find current backup link '$CURR' in '$BASE'" exit 1 fi # dereference symlinks # (you can use `ls -l "$link" | sed -e 's/.*-> //'` instead of readlink) prev=$(readlink "$BASE/$PREV") case "$prev" in /*) # absolute link; no changes required ;; *) # relative link; must prepend full path prev="$BASE/$prev" ;; esac curr=$(readlink "$BASE/$CURR") case "$curr" in /*) # absolute link; no changes required ;; *) # relative link; must prepend full path curr="$BASE/$curr" ;; esac # final sanity check if [ ! -d "$prev" ]; then echo "Unable to find previous target dir '$prev'" exit 1 fi if [ ! -d "$curr" ]; then echo "Unable to find current target dir '$curr'" exit 1 fi # now we're ready to move into the previous directory and propagate the # links forward into the current directory cd "$prev" # pax is an archiver. -r -w means to read and write (e.g., make a copy) # -l means to hard-link to existing files, and -u means to not replace # newer files with the same name pax -r -w -l -u . "$curr"