example dirinfo script

Miek Gieben <[email protected]> Tue, 17 May 2005 18:51:45 +0200
Newsgroups gmane.comp.sysutils.backup.hdup.general
Message-ID <[email protected]>
--7ZAtKRhVyVSsbBD2
Content-Type: multipart/mixed; boundary="mYCpIKhGyMATD0i+"
Content-Disposition: inline


--mYCpIKhGyMATD0i+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello,

the attached script parses your hdup.conf and writes a file out
with a the directory info it can find. The script can be used=20
so fill the caps the current hdup2/gnu tar combinations leaves.
(also see some earlier mails on that).

The information is stored in your archive directory in
<host>/<date>/<date>.dirinfo and all entries are like this:

755|root|root|/var/var/www

(see man find - look under printf)

The script isn't tested much, only developed under Linux and used
some bash3.0 structures (the regular expressions). And it uses Gnu
find to do the hard stuff....
Appart from that, it seems to do the trick.

I'm planning to take a loooong vacation this year and in that time I
hope to work on patching tar and hdup2 and release a 2.0.8 version.
This is gonna be sometime in july, until that time  I welcome any
patches and comments on this script (it's going to be included
anyhow).

Oh, a dirinfo restore functionality isn't hard to add I guess. Using
this script as a post-run during backups/restore makes the whole
thing pretty transparent I guess,

--
grtz,
  - Miek

http://www.miek.nl                      http://www.nlnetlabs.nl
PGP Key ID: 0xB18453A1
fingerprint: 002B B079 0DDA 7D44 2B5C  CAB0 C3B7 F943 B184 53A1


--mYCpIKhGyMATD0i+
Content-Type: application/x-sh
Content-Disposition: attachment; filename="dirinfo.sh"
Content-Transfer-Encoding: quoted-printable

#!/bin/sh=0A=0A# a simple shell script to walk the directories=0A# hdup bac=
ks up.=0A# (C) Miek Gieben, licensed under the GPL version 2=0A=0A# SYNOPSI=
S=0A# dirinfo.sh -c config <hostname> =0A=0A# TODO=0A# include/exclude=0A# =
=2Enobackup=0A=0Aget_parameters() {=0A	# parse a bla =3D foo contruct and r=
eturn foo=0A#	echo $@=0A	if [[ $@ =3D~ '(.*) *=3D *(.*)' ]] =0A	then=0A	#	e=
cho $BASH_REMATCH=0A	#	echo ${BASH_REMATCH[1]}=0A	#	echo ${BASH_REMATCH[2]}=
=0A		param=3D${BASH_REMATCH[2]}=0A	fi=0A}=0A=0Aprintf=3D"%m|%u|%g|%h%p\n"=
=0Acflag=3D=0Ahost=3D=0Aconfig=3D/etc/hdup/hdup.conf=0Awhile getopts c: arg=
=0Ado=0A	case $arg in=0A	c) 	cflag=3D1=0A		config=3D"$OPTARG"=0A		;;=0A	?)=
=0A		echo "Usage: dirinfo.sh [-c config] hostname"=0A		exit 1=0A		;;=0A	esa=
c;=0Adone=0Ashift $(($OPTIND - 1))=0A=0Ahost=3D$1=0Aif [ -z $host ]; then=
=0A	echo "Usage: dirinfo.sh [-c config] hostname"=0A	exit 1=0Afi=0A=0A# ret=
rieve the archive dir=0Adate=3D`date +%Y-%m-%d`	 # americon/iso/etc todo=0A=
archivedir=3D=0Adir=3D=0Adatespec=3D=0Ahostflag=3D=0Awhile read line =0Ado=
=0A	[[ $line =3D~ '^\#' ]] && continue=0A=0A	get_parameters $line=0A=0A	# a=
rchive dir=0A	if [[ $line =3D~ '^archive dir' ]] =0A	then=0A		archivedir=3D=
${param}=0A	fi=0A	# date spec=0A	if [[ $line =3D~ '^date spec' ]] =0A	then=
=0A		datespec=3D${param}=0A	fi=0A=0A	# host statement=0A	if [[ $line =3D~ "=
\[$host\]" ]]=0A	then =0A		hostflag=3D1=0A	fi=0A=0A	# check for another hos=
t statement=0A	if [[ $line =3D~ "\[.*\]" ]]=0A	then =0A		if [[ ! $line =3D~=
 "\[$host\]" ]]=0A		then=0A			hostflag=3D=0A		fi=0A	fi=0A=0A	if [[ $line =
=3D~ '^dir' ]] && [ ! -z $hostflag ]=0A	then =0A		#echo $host found!=0A		di=
r=3D${param}=0A	fi=0A=0Adone < $config=0A=0A# no double slashes logic here.=
=2E.=0Adirinfofile=3D"$archivedir/$host/$date/$date.dirinfo"=0Aif [ -z $dir=
 ] =0Athen=0A	echo "Host $host not found in config file."=0A	exit 1=0Afi=0A=
=0Aif [ -z $archivedir ] =0Athen=0A	echo "Archivedir not found in config fi=
le."=0A	exit 1=0Afi=0A=0A#echo $archivedir=0A#echo $dir=0Adir=3D"/var/www /=
home/miek/bin"=0A=0Aecho "Compiling into....: $dirinfofile"=0Arm -f $dirinf=
ofile=0Afor i in $dir=0Ado=0A	echo "Adding............: $i"=0A	`find $i -ty=
pe d -printf $printf >> $dirinfofile`=0Adone=0A
--mYCpIKhGyMATD0i+--

--7ZAtKRhVyVSsbBD2
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFCiiEhw7f5Q7GEU6ERAmvQAJ9ME7+4iAt7dgv1qrTThzoZ2CWLqwCffw4s
8QXyT3QTJms8iHLcguzfU28=
=+tDw
-----END PGP SIGNATURE-----

--7ZAtKRhVyVSsbBD2--