[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 |
|
---|
| 50 | DATEFILE=/var/cache/mondo-archive/last-backup
|
---|
| 51 |
|
---|
| 52 | FatalError() {
|
---|
| 53 | echo "$1" >> $LOGFILE
|
---|
| 54 | echo "$1" >> /dev/stderr
|
---|
| 55 | exit 1
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | MakeFilelist() {
|
---|
| 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
|
---|
| 101 | cat $TMP/filelist | sort | uniq | \
|
---|
| 102 | grep -v "/win386\.swp" | grep -v "/vmmhiber\.w9x" | \
|
---|
| 103 | grep -v "/hiberfil\.sys" | grep -v "/win386.swp" | grep -v "/pagefile\.sys" | \
|
---|
| 104 | grep -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
|
---|
| 110 | cat $output | grep -vx "$i/lost+found" | grep -vx $i"lost+found" > $output.MID
|
---|
| 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
|
---|
| 116 | cat $output | grep -vx "$i/\.journal" | grep -vx "$i\.journal" | grep -vx "$i\.autofsck" > $output.MID
|
---|
| 117 | sync
|
---|
| 118 | mv -f $output.MID $output
|
---|
| 119 | done
|
---|
| 120 | # exclude /var/log/pacct and Mondo's temp files
|
---|
| 121 | cat $output | grep -vx "" | grep -v "/var/log/pacct" | grep -v "tmp\.mondo\.$$" | grep -vx "/var/log/mondo-archive\.log" | grep -v "mondo\.scratch\.$$" > $output.MID
|
---|
| 122 | mv -f $output.MID $output
|
---|
| 123 | cp -f $output $TMP/filelist
|
---|
| 124 | # exclude /var/run/*.pid (lockfiles)
|
---|
| 125 | # cat $output | grep -vx "/var/run/[^\.]*\.pid" > $output.MID
|
---|
| 126 | # mv -f $output.MID $output
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | ############################ main ############################
|
---|
| 136 |
|
---|
| 137 | if [ "$#" -ne "6" ] ; then
|
---|
| 138 | echo "mondo-makefilelist <logfile> <tmpdir> <scratchdir> <archivepath> <exclude_paths> <differential>" >> /dev/stderr
|
---|
| 139 | exit 1
|
---|
| 140 | fi
|
---|
| 141 |
|
---|
| 142 | LOGFILE=$1
|
---|
| 143 | TMP=$2
|
---|
| 144 | scratchdir=$3
|
---|
| 145 | archivepath="$4"
|
---|
| 146 | EXCLUDE_PATHS="$5"
|
---|
| 147 | USE_DIFFERENTIAL="$6"
|
---|
| 148 |
|
---|
| 149 | mkdir -p $DATEFILE &> /dev/null
|
---|
| 150 | rmdir $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.
|
---|
| 157 | cp -f $DATEFILE $DATEFILE.aborted 2> /dev/null
|
---|
| 158 |
|
---|
| 159 | if [ "$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
|
---|
| 166 | else
|
---|
| 167 | echo "Full backup. Updating datestamp." >> $LOGFILE
|
---|
| 168 | echo "`date +%s`" > $DATEFILE || FatalError "Unable to write to $DATEFILE"
|
---|
| 169 | fi
|
---|
| 170 |
|
---|
| 171 | mkdir -p $scratchdir/archives
|
---|
| 172 | exclude_these_please=""
|
---|
| 173 | for 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"
|
---|
| 175 | done
|
---|
| 176 | MakeFilelist "$archivepath" $TMP/filelist.full "$exclude_these_please"
|
---|
| 177 | > $TMP/cklist.full
|
---|
| 178 | mv -f $TMP/filelist.full $TMP/filelist.blah
|
---|
| 179 | ## See if EXCLUDE_PATHS includes a file of two
|
---|
| 180 | for X in $EXCLUDE_PATHS ; do
|
---|
| 181 | if [ ! -d $X ] ; then
|
---|
| 182 | cat $TMP/filelist.blah | grep -v $X > $TMP/filelist.full
|
---|
| 183 | mv -f $TMP/filelist.full $TMP/filelist.blah
|
---|
| 184 | fi
|
---|
| 185 | done
|
---|
| 186 | cat $TMP/filelist.blah | grep -v "mojo-jojo-123" > $TMP/filelist.full
|
---|
| 187 | [ ! -e "$TMP/filelist.full" ] && FatalError "Serious error when removing mojo jojo from fielist"
|
---|
| 188 | cp $TMP/filelist.full /tmp
|
---|
| 189 | cp -f $TMP/filelist.full "$scratchdir"/archives/
|
---|
| 190 | cp -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`
|
---|
| 193 | total_files_to_backup=`cat $TMP/filelist.full | wc -l`
|
---|
| 194 | echo "Backing up $total_files_to_backup files" >> $LOGFILE
|
---|
| 195 | exit 0
|
---|
| 196 |
|
---|