source: MondoRescue/branches/stable/mondo/mondo/mondo-makefilelist@ 541

Last change on this file since 541 was 541, checked in by bcornec, 18 years ago

Stable is reverted to r436 (2.0.7) to put it in line with 2.0.8 and start from there over

  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1#!/bin/sh
2#
3# $Id: mondo-makefilelist 541 2006-05-13 18:47:23Z bcornec $
4
5#
6# mondo-makefilelist
7# ...an off-shoot of mondo-archive
8#
9# 12/09/2003
10# - changed 'find -newer' to 'find -cnewer' for differential backup
11#
12# 01/02/2003
13# - only add _existant_ dirs&files to EXCLUDE_THESE_PLEASE
14#
15# 12/20/2002
16# - exclude /media/cdrom,cdrecorder,floppy
17#
18# 11/18/2002
19# - exclude tmp.mondo.* and mondo.scratch.* using
20# sensible wildcards (finally!)
21#
22# 11/07/2002
23# - changed gawk to awk for Debian users *sigh*
24#
25# 10/29/2002
26# - replaced convoluted grep with wc (KP)
27#
28# 04/01 - 07/31
29# - exclude /root/images/mindi
30# - backup differential datestamp, just in case
31# - changed $i to $j (Karsten)
32# - exclude pagefile.sys (WinXP virtual memory file) from backup
33#
34# 03/01 - 03/31
35# - added -E patch to exclude files and/or dirs properly (Andy Glass)
36# - remove ' from either side of line 46's find() command
37# - patch from Andy Glass to make Mondo more SUN-friendly when
38# handling /etc/fstab and "-" entries
39#
40# 02/01 - 02/28
41# - added a patch from KirkJT to support pathnames containing spaces
42# - do not allow user to exclude /dev/* from filelist, just mountlist
43# - exclude .autofsck from each partition's root dir
44# - fixed -D (differential) bug
45#
46# 01/29/2002
47# - separated from mondo-archive, which was then ported to C
48######################################################################
49
50
51
52
53DATEFILE=/var/cache/mondo-archive/last-backup
54
55FatalError() {
56 echo "$1" >> $LOGFILE
57 echo "$1" >> /dev/stderr
58 exit 1
59}
60
61
62
63
64MakeFilelist() {
65 local excluded i exlist call bkpaths output paths_to_exclude j
66 bkpaths=$1
67 output=$2
68 paths_to_exclude=$3
69 mkdir -p /var/cache/mondo-archive
70# Mikael Hultgren - 03/07/2002
71 call="find $bkpaths"
72# end patch
73 for i in $paths_to_exclude ; do
74 j=`echo /"$i/" | awk -F "/" '{ for(i=1;i<NF;i++) { if (length($i)>=1) {printf "/%s",$i;};}; print ""; }'`
75 j=$(echo $j | sed 's/\\_/ /g')
76 call="$call -path '$j' -prune -o"
77 done
78# Conor Daly - 12/09/2003
79# change '-newer' to '-cnewer'
80 [ "$USE_DIFFERENTIAL" = "yes" ] && call="$call -cnewer $DATEFILE -a"
81 call="$call -print"
82 echo "call to find = $call" >> $LOGFILE
83 eval $call > $TMP/filelist 2> $TMP/find.log
84# cp $TMP/filelist /tmp/filelist
85 res=`grep -v "Permission denied" $TMP/find.log`
86 if [ "$res" != "" ] ; then
87 cat $TMP/find.log | tee -a $LOGFILE
88 fi
89# include various directory _paths_ (not contents of dirs: that comes later)
90 for i in $paths_to_exclude ; do
91 echo "$i" >> $TMP/filelist ; # backup the dirpath, NOT contents
92 done
93 for i in $paths_to_exclude $bkpaths ; do
94 echo "$i" | cut -d'/' -f1 >> $TMP/filelist
95 echo "$i" | cut -d'/' -f1,2 >> $TMP/filelist
96 echo "$i" | cut -d'/' -f1,2,3 >> $TMP/filelist
97 echo "$i" | cut -d'/' -f1,2,3,4 >> $TMP/filelist
98 echo "$i" | cut -d'/' -f1,2,3,4,5 >> $TMP/filelist
99 echo "$i" | cut -d'/' -f1,2,3,4,5,6 >> $TMP/filelist
100 echo "$i" | cut -d'/' -f1,2,3,4,5,6,7 >> $TMP/filelist
101 done
102# exclude lost+found folders, Win9x hibernation file and Win9x swap file
103 sort $TMP/filelist -u | \
104grep -v "/win386\.swp" | grep -v "/vmmhiber\.w9x" | \
105grep -v "/hiberfil\.sys" | grep -v "/win386.swp" | grep -v "/pagefile\.sys" | \
106grep -v "/tmp\.mondo\.[0-9]+*" | grep -v "/mondo\.scratch\.[0-9]+*" > $output
107
108# Patch from Andy Glass - 03/03/2002
109 for i in `tr -s '\t' ' ' < /etc/fstab | cut -d' ' -f2 | grep -v '-'` ; do
110# End patch
111 grep -vx "$i/lost+found" $output | grep -vx $i"lost+found" > $output.MID
112 sync
113 mv -f $output.MID $output
114 done
115# exclude .journal files (ext3)
116 for i in `tr -s '\t' ' ' < /etc/fstab | grep "ext3" | cut -d' ' -f2` ; do
117 grep -vx "$i/\.journal" $output | grep -vx "$i\.journal" | grep -vx "$i\.autofsck" > $output.MID
118 sync
119 mv -f $output.MID $output
120 done
121# exclude /var/log/pacct and Mondo's temp files
122 grep -vx "" $output | grep -v "/var/log/pacct" | grep -v "tmp\.mondo\.$$" | grep -vx "/var/log/mondo-archive\.log" | grep -v "mondo\.scratch\.$$" > $output.MID
123 mv -f $output.MID $output
124 cp -f $output $TMP/filelist
125# exclude /var/run/*.pid (lockfiles)
126# grep -vx "/var/run/[^\.]*\.pid" $output > $output.MID
127# mv -f $output.MID $output
128}
129
130
131
132
133
134
135
136############################ main ############################
137
138if [ "$#" -ne "6" ] ; then
139 echo "mondo-makefilelist <logfile> <tmpdir> <scratchdir> <archivepath> <exclude_paths> <differential>" >> /dev/stderr
140 exit 1
141fi
142
143LOGFILE=$1
144TMP=$2
145scratchdir=$3
146archivepath="$4"
147EXCLUDE_PATHS="$5"
148USE_DIFFERENTIAL="$6"
149
150mkdir -p $DATEFILE &> /dev/null
151rmdir $DATEFILE &> /dev/null
152# If previous aborted backup then restore the old datestamp first :)
153[ -e "$DATEFILE.aborted" ] && mv -f $DATEFILE.aborted $DATEFILE
154# Now, take a backup of current datestamp. If backup is not aborted
155# then main() will delete backup datestamp. Cool. However, if it _is_
156# aborted then it won't, which means I'll find the backup datestamp
157# next time, recover it, and so on.
158cp -f $DATEFILE $DATEFILE.aborted 2> /dev/null
159
160if [ "$USE_DIFFERENTIAL" ] ; then
161 echo "Differential backup" >> $LOGFILE
162 if [ ! -e "$DATEFILE" ] ; then
163 echo "No datestamp. Reverting to full backup." >> $LOGFILE
164 USE_DIFFERENTIAL=""
165 rm -f $DATEFILE; echo "`date +%s`" > $DATEFILE
166 fi
167else
168 echo "Full backup. Updating datestamp." >> $LOGFILE
169 echo "`date +%s`" > $DATEFILE || FatalError "Unable to write to $DATEFILE"
170fi
171
172mkdir -p $scratchdir/archives
173exclude_these_please=""
174for i in $LOGFILE $scratchdir $TMP /mnt/cdrom /mnt/floppy /media/cdrom /media/cdrecorder /media/floppy /proc $EXCLUDE_PATHS /tmp /root/images/mondo /root/images/mindi ; do
175 [ "`echo "$i" | grep -x "/dev/.*"`" = "" ] && [ -e "$i" ] && exclude_these_please="$exclude_these_please $i"
176done
177MakeFilelist "$archivepath" $TMP/filelist.full "$exclude_these_please"
178> $TMP/cklist.full
179mv -f $TMP/filelist.full $TMP/filelist.blah
180## See if EXCLUDE_PATHS includes a file of two
181for X in $EXCLUDE_PATHS ; do
182 if [ ! -d $X ] ; then
183 grep -v $X $TMP/filelist.blah > $TMP/filelist.full
184 mv -f $TMP/filelist.full $TMP/filelist.blah
185 fi
186done
187grep -v "mojo-jojo-123" $TMP/filelist.blah > $TMP/filelist.full
188[ ! -e "$TMP/filelist.full" ] && FatalError "Serious error when removing mojo jojo from fielist"
189cp $TMP/filelist.full /tmp
190cp -f $TMP/filelist.full "$scratchdir"/archives/
191cp -f $TMP/filelist.full /var/cache/mondo-archive/
192[ ! -e "$TMP/filelist.full" ] && FatalError "Who let the dogs out? (Who!? Who!?)"
193#total_files_to_backup=`grep -n "" $TMP/filelist.full | tail -n1 | cut -d':' -f1`
194total_files_to_backup=`cat $TMP/filelist.full | wc -l`
195echo "Backing up $total_files_to_backup files" >> $LOGFILE
196exit 0
197
Note: See TracBrowser for help on using the repository browser.