Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Looks promising ...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Looks promising ...
Authored by: kmue on Apr 15, '04 06:00:09AM
... but the directories are never created. In step 4 you meant perhaps $PARBAK as source? Here is my attempt (still it does not create directories):

#!/bin/sh
# ----------------------------------------------------------------------
# incremental-set-backup script (9 backups spanning 2 drives)
# ----------------------------------------------------------------------
# this script calls upon 'rsync' to do daily backups to another partition,
# then uses 'cpio' to move old sets to an external drive.  two full sized
# backups will be made and 7 incremental sets will be produced.  with  
# the use of cron, this will provide 9 days worth of consecutive backups. 
# ----------------------------------------------------------------------

# -----------------------------------------------------------------------
# CONFIG
# -----------------------------------------------------------------------
SOURCE=/Volumes/Data/Users/example
PREFIX=test
EXTBAK=/Volumes/Data/Backup
PARBAK=/Volumes/Applications/Backup
NUMBAK=7

# -----------------------------------------------------------------------
# getopts
# -----------------------------------------------------------------------
while getopts :n opt; do
	case "$opt" in
		n)	NODO=1;;
		*)	echo >&2 "Usage: $0 [-n]"; exit 1;;
	esac
done

# -----------------------------------------------------------------------
# SUBROUTINES
# -----------------------------------------------------------------------
me=$(basename $0)
tell() { echo "`/bin/date '+%Y%d%m %H:%M:%S'` $me: $1"; }

# -----------------------------------------------------------------------
exec() {
# -----------------------------------------------------------------------
	tmp=/tmp/$me.exec.tmp
	if [ "$NODO" ]; then
		tell "exec: $*"
	else
		tell "exec: $*"
		eval "$*" > $tmp 2>&1
		if [ "$?" != 0 ]; then
			[ -s "$tmp" ] && tell "`/bin/cat $tmp`"; /bin/rm -f $tmp
		fi
	fi
}

# -----------------------------------------------------------------------
# MAIN
# -----------------------------------------------------------------------

# check to be sure script is run as root
#if [ $(id -u) != 0 ]; then
#	echo "Sorry, must be root. Exiting..."; exit 1
#fi

TARGET=$PREFIX/$(basename $SOURCE)

# create the backup directories
mkdir -p $EXTBAK/$PREFIX
mkdir -p $PARBAK/$PREFIX

# incremental sets of /Users/ to EXTBAK using 'rsync' and 'cpio', 
# eventually making 2 full sets and 7 incremental sets

# process broken down into 5 easy steps.
# step 1: use 'rm' to delete the oldest set, if it exists:
[ -d $EXTBAK/$TARGET.7 ] && exec rm -rf $EXTBAK/$TARGET.7

# step 2: use 'mv' to move the middle sets back by one, if they exist
t=$NUMBAK; let s=(t - 1)
while [ $t -gt 1 ]; do
	if [ -d $EXTBAK/$TARGET.$s ]; then
		exec mv $EXTBAK/$TARGET.$s $EXTBAK/$TARGET.$t
	fi
	let t=(t - 1); let s=(t - 1)
done

# step 3: use 'cpio' to make a hard-link-only copy (except for dirs) of 
# the previous set, if it exists.  this will give 2 full sized backups 
# (Users & $TARGET.0) and enable incremental sets to be made on the 2nd  
# harddrive instead of full copies
if [ -d $EXTBAK/$TARGET.0 ]; then
	exec cd $EXTBAK/$TARGET.0 && find . -print | cpio -pdl $EXTBAK/$TARGET.1
fi

# step 4: use 'cpio' to make a copy of your main backup to EXTBAK if it exists
# 'cpio -pdl' will be used since it will make links "only when possible"
if [ -d $PARBAK/$TARGET ]; then
	exec "cd $PARBAK/$TARGET.0 && find . -print | cpio -pdl $EXTBAK/$TARGET.0"
fi

# step 5: use 'rsync' on /Users/ to create your main backup ('rsync' behaves
# like 'cp --remove-destination' by default, so when the destination exists,
# it is unlinked first)
exec rsync -va --delete $SOURCE $PARBAK/$PREFIX

# step 5: use 'touch' to update the mtime of $EXTBAK/Users to reflect
# the set's time
exec touch $EXTBAK/$TARGET

# voila...you got your bak


[ Reply to This | # ]
Looks promising ...
Authored by: bluehz on Apr 15, '04 08:26:01AM

I don't think its a very good idea to use cpio in a Mac environment. cpio is not mac resource /HFS aware.



[ Reply to This | # ]