4 # Copyright (C) 2001 Eugenio Diaz <getnito@yahoo.com>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # 3. Neither the name of the University nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
24 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 # This script will make a simple backup of the most critical
36 # partitions, using the "dump" facility, into the backup partition.
38 # Run the following to make a complete backup:
40 # $ su -c "backup full"
42 # Run the following to make an incremental backup:
44 # $ su -c "backup inc"
46 # Add "nodumpdate" to run a backup but not effect the backup state
47 # recorded in the file /var/lib/dumpdates and reported by dump -W:
49 # $ su -c "backup full nodumpdate"
53 if [ "$2" = "nodumpdate" ]; then
59 if [ "$1" = "full" ]; then
63 elif [ "$1" = "inc" ]; then
68 echo "Usage: $0 full|inc [nodumpdate]"
74 # Configuration Parameters
77 BACKUPPART=${BACKUPPART:-"/backup"}
78 BACKUPDIR=${BACKUPDIR:-"current"}
79 DUMPLOGARCH="$BACKUPPART/backup.dump.log.gz"
80 FSTODUMP=${FSTODUMP:-/ /var /home /mnt/hdb1 /usr}
82 DUMPFILESOWN="root.root"
89 echo "############################################################"
90 echo "Starting ${BACKUP} backup"
91 echo "############################################################"
99 echo "### ${BACKUP} System Dump Backup ###"
100 echo "Using backup partition: $BACKUPPART"
101 echo "Filesystems to dump: $FSTODUMP"
103 echo -n "Remounting backup partition read-write ... "
104 if ( mount $BACKUPPART -o remount,rw &> /dev/null ) then
106 elif ( mount $BACKUPPART -o rw &> /dev/null ) then
110 echo "There were problems remounting $BACKUPPART in read-write mode!"
111 echo "Aborting ${BACKUP} System Dump Backup."
113 echo "------------------------------------------------------------"
117 echo -n "Checking directory structure on backup partition ... "
118 if [ -d $BACKUPPART/$BACKUPDIR -a -w $BACKUPPART/$BACKUPDIR ]; then
121 echo -n "Checking backup partition for available space ... "
122 SREQ=$(for i in $FSTODUMP; do dump -$DLEVEL -S $i 2> /dev/null; done | awk '{x=x+$1/1048576} END {printf "%6.0f\n", x}')
123 SAVAILFREE=$(df --block-size=1048576 | grep -Fe $BACKUPPART | awk '{printf "%6.0f\n", $4}')
124 SAVAILDEL=$(du -s --block-size=1048576 $BACKUPPART/$BACKUPDIR/. | awk '{printf "%6.0f\n", $1}')
125 SAVAIL=$(( $SAVAILFREE + $SAVAILDEL ))
127 if [ "$(( $SAVAIL - $SREQ ))" -gt "0" ]; then
129 echo "Available: $SAVAIL MB Required: $SREQ MB."
131 echo "not enough space!"
132 echo "There is not enough space left in $BACKUPPART for the backup!"
133 echo "Available: $SAVAIL MB Required: $SREQ MB."
134 echo -n "Remounting backup partition read-only ... "
135 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
137 elif ( mount $BACKUPPART -o ro &> /dev/null ) then
141 echo "There were problems remounting $BACKUPPART in read-only mode!"
142 echo "Aborting ${BACKUP} System Dump Backup."
144 echo "------------------------------------------------------------"
147 echo "Aborting ${BACKUP} System Dump Backup."
149 echo "------------------------------------------------------------"
153 echo -n "Deleting old files ... "
154 if [ "$(ls -la $BACKUPPART/$BACKUPDIR/ | wc -l)" -gt "3" ]; then
155 rm -f $BACKUPPART/$BACKUPDIR/* &> /dev/null
158 echo "no old files to delete."
161 echo "Dumping filesystems ... "
164 if [ "$FS" = "/" ]; then
167 FSNAME="$(echo $FS | tr / _ | cut -b 2-)"
170 TODAY="$(date +%a%Y%m%d)"
171 echo -n "Starting dump of $FSNAME ( $FS ) ... "
172 if ( dump -$DLEVEL $UPDATEDDATE -z -M -s 27306 -f $BACKUPPART/$BACKUPDIR/$FSNAME.$BTYPE. -Q $BACKUPPART/$BACKUPDIR/$FSNAME.$BTYPE.qfa -L ${TODAY}file $FS &> $BACKUPPART/$BACKUPDIR/$FSNAME.log ) then
176 echo "There were problems with the dump of $FSNAME ( $FS )."
177 echo "Check log file at $BACKUPPART/$BACKUPDIR/$FSNAME.log.gz"
178 echo "Also check log archive file $DUMPLOGARCH."
181 echo -n "Verifying dump of $FSNAME ( $FS ) ... "
182 echo "------------------------------------------------------------" >> $BACKUPPART/$BACKUPDIR/$FSNAME.log
183 echo "Result of dump for $FSNAME ( $FS ):" >> $BACKUPPART/$BACKUPDIR/$FSNAME.log
184 if ( restore -C -M -f $BACKUPPART/$BACKUPDIR/$FSNAME.$BTYPE. >> $BACKUPPART/$BACKUPDIR/$FSNAME.log 2>&1 ) then
188 echo "There were problems verifying the dump of $FSNAME ( $FS )."
189 echo "Check log file $BACKUPPART/$BACKUPDIR/$FSNAME.log.gz for more info"
191 gzip < $BACKUPPART/$BACKUPDIR/$FSNAME.log >> $DUMPLOGARCH
192 echo "------------------------------------------------------------" | gzip >> $DUMPLOGARCH
195 echo -n "Setting ownership and permissions of dump files ... "
196 chmod $DUMPFILESMODE $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev/null
197 chown $DUMPFILESOWN $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev/null
200 echo -n "Compressing dump log files ... "
201 gzip $BACKUPPART/$BACKUPDIR/*.log &> /dev/null
207 echo "There are problems with the directory structure."
208 echo "Check directory: $BACKUPPART/$BACKUPDIR"
209 echo -n "Remounting backup partition read-only ... "
210 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
214 echo "There were problems remounting $BACKUPPART in read-only mode!"
215 echo "Aborting ${BACKUP} System Dump Backup."
217 echo "------------------------------------------------------------"
220 echo "Aborting ${BACKUP} System Dump Backup."
222 echo "------------------------------------------------------------"
226 echo -n "Remounting backup partition read-only ... "
227 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
231 echo "There were problems remounting $BACKUPPART in read-only mode!"
232 echo "Aborting ${BACKUP} System Dump Backup."
234 echo "------------------------------------------------------------"
238 echo "### End of ${BACKUP} System Dump Backup ###"
240 echo "------------------------------------------------------------"