source: trunk/mondo/mondo/mondo-makefilelist @ 274

Last change on this file since 274 was 274, checked in by bcornec, 14 years ago

merge -r272:273 $SVN_M/branches/2.06

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