| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | ### |
| 4 | # Copyright (C) 2001 Eugenio Diaz <[email protected]> |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions |
| 8 | # are met: |
| 9 | # |
| 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. |
| 19 | # |
| 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 |
| 31 | # SUCH DAMAGE. |
| 32 | # |
| 33 | ## |
| 34 | # |
| 35 | # This script will make a simple backup of the most critical |
| 36 | # partitions, using the "dump" facility, into the backup partition. |
| 37 | # |
| 38 | # Run the following to make a complete backup: |
| 39 | # |
| 40 | # $ su -c "backup full" |
| 41 | # |
| 42 | # Run the following to make an incremental backup: |
| 43 | # |
| 44 | # $ su -c "backup inc" |
| 45 | # |
| 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: |
| 48 | # |
| 49 | # $ su -c "backup full nodumpdate" |
| 50 | # |
| 51 | ## |
| 52 | |
| 53 | if [scip-shell system . . `[`. "$2" = "nodumpdate" ]; then |
| 54 | UPDATEDDATE="" |
| 55 | else |
| 56 | UPDATEDDATE="-u" |
| 57 | fi |
| 58 | |
| 59 | if [scip-shell system . . `[`. "$1" = "full" ]; then |
| 60 | DLEVEL="0" |
| 61 | BTYPE="full" |
| 62 | BACKUP="Full" |
| 63 | elif [scip-shell system . . `[`. "$1" = "inc" ]; then |
| 64 | DLEVEL="1" |
| 65 | BTYPE="inc" |
| 66 | BACKUP="Incremental" |
| 67 | else |
| 68 | echoscip-shell system . . echo. "Usage: $0 full|inc [nodumpdate]" |
| 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | |
| 73 | # |
| 74 | # Configuration Parameters |
| 75 | # |
| 76 | |
| 77 | BACKUPPART=${BACKUPPART:-"/backup"} |
| 78 | BACKUPDIR=${BACKUPDIR:-"current"} |
| 79 | DUMPLOGARCH="$BACKUPPART/backup.dump.log.gz" |
| 80 | FSTODUMP=${FSTODUMP:-/ /var /home /mnt/hdb1 /usr} |
| 81 | DUMPFILESMODE="0644" |
| 82 | DUMPFILESOWN="root.root" |
| 83 | |
| 84 | # |
| 85 | # Start |
| 86 | # |
| 87 | |
| 88 | echoscip-shell system . . echo. |
| 89 | echoscip-shell system . . echo. "############################################################" |
| 90 | echoscip-shell system . . echo. "Starting ${BACKUP} backup" |
| 91 | echoscip-shell system . . echo. "############################################################" |
| 92 | echoscip-shell system . . echo. |
| 93 | |
| 94 | |
| 95 | # |
| 96 | # Make system backup |
| 97 | # |
| 98 | |
| 99 | echoscip-shell system . . echo. "### ${BACKUP} System Dump Backup ###" |
| 100 | echoscip-shell system . . echo. "Using backup partition: $BACKUPPART" |
| 101 | echoscip-shell system . . echo. "Filesystems to dump: $FSTODUMP" |
| 102 | |
| 103 | echoscip-shell system . . echo. -n "Remounting backup partition read-write ... " |
| 104 | if ( mountscip-shell system . . mount. $BACKUPPART -o remount,rw &> /dev/nullscip-shell filesystem . . `/dev/null`. ) then |
| 105 | echoscip-shell system . . echo. "done." |
| 106 | elif ( mountscip-shell system . . mount. $BACKUPPART -o rw &> /dev/nullscip-shell filesystem . . `/dev/null`. ) then |
| 107 | echoscip-shell system . . echo. "done." |
| 108 | else |
| 109 | echoscip-shell system . . echo. "failure!" |
| 110 | echoscip-shell system . . echo. "There were problems remounting $BACKUPPART in read-write mode!" |
| 111 | echoscip-shell system . . echo. "Aborting ${BACKUP} System Dump Backup." |
| 112 | echoscip-shell system . . echo. "Aborted." |
| 113 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 114 | exit 1 |
| 115 | fi |
| 116 | |
| 117 | echoscip-shell system . . echo. -n "Checking directory structure on backup partition ... " |
| 118 | if [scip-shell system . . `[`. -d $BACKUPPART/$BACKUPDIR -a -w $BACKUPPART/$BACKUPDIR ]; then |
| 119 | echoscip-shell system . . echo. "done." |
| 120 | |
| 121 | echoscip-shell system . . echo. -n "Checking backup partition for available space ... " |
| 122 | SREQ=$(for i in $FSTODUMP; do dump -$DLEVEL -S $i 2> /dev/nullscip-shell filesystem . . `/dev/null`.; done | awkscip-shell system . . awk. '{x=x+$1/1048576} END {printf "%6.0f\n", x}') |
| 123 | SAVAILFREE=$(dfscip-shell system . . df. --block-size=1048576 | grepscip-shell system . . grep. -Fe $BACKUPPART | awkscip-shell system . . awk. '{printf "%6.0f\n", $4}') |
| 124 | SAVAILDEL=$(duscip-shell system . . du. -s --block-size=1048576 $BACKUPPART/$BACKUPDIR/. | awkscip-shell system . . awk. '{printf "%6.0f\n", $1}') |
| 125 | SAVAIL=$(( $SAVAILFREE + $SAVAILDEL )) |
| 126 | |
| 127 | if [scip-shell system . . `[`. "$(( $SAVAIL - $SREQ ))" -gt "0" ]; then |
| 128 | echoscip-shell system . . echo. "done." |
| 129 | echoscip-shell system . . echo. "Available: $SAVAIL MB Required: $SREQ MB." |
| 130 | else |
| 131 | echoscip-shell system . . echo. "not enough space!" |
| 132 | echoscip-shell system . . echo. "There is not enough space left in $BACKUPPART for the backup!" |
| 133 | echoscip-shell system . . echo. "Available: $SAVAIL MB Required: $SREQ MB." |
| 134 | echoscip-shell system . . echo. -n "Remounting backup partition read-only ... " |
| 135 | if ( mountscip-shell system . . mount. $BACKUPPART -o remount,ro &> /dev/nullscip-shell filesystem . . `/dev/null`. ) then |
| 136 | echoscip-shell system . . echo. "done." |
| 137 | elif ( mountscip-shell system . . mount. $BACKUPPART -o ro &> /dev/nullscip-shell filesystem . . `/dev/null`. ) then |
| 138 | echoscip-shell system . . echo. "done." |
| 139 | else |
| 140 | echoscip-shell system . . echo. "failure!" |
| 141 | echoscip-shell system . . echo. "There were problems remounting $BACKUPPART in read-only mode!" |
| 142 | echoscip-shell system . . echo. "Aborting ${BACKUP} System Dump Backup." |
| 143 | echoscip-shell system . . echo. "Aborted." |
| 144 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 145 | exit 1 |
| 146 | fi |
| 147 | echoscip-shell system . . echo. "Aborting ${BACKUP} System Dump Backup." |
| 148 | echoscip-shell system . . echo. "Aborted." |
| 149 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 150 | exit 1 |
| 151 | fi |
| 152 | |
| 153 | echoscip-shell system . . echo. -n "Deleting old files ... " |
| 154 | if [scip-shell system . . `[`. "$(lsscip-shell system . . ls. -la $BACKUPPART/$BACKUPDIR/ | wcscip-shell system . . wc. -l)" -gt "3" ]; then |
| 155 | rmscip-shell system . . rm. -f $BACKUPPART/$BACKUPDIR/* &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 156 | echoscip-shell system . . echo. "done." |
| 157 | else |
| 158 | echoscip-shell system . . echo. "no old files to delete." |
| 159 | fi |
| 160 | |
| 161 | echoscip-shell system . . echo. "Dumping filesystems ... " |
| 162 | for FS in $FSTODUMP |
| 163 | do |
| 164 | if [scip-shell system . . `[`. "$FS" = "/scip-shell filesystem . . `/`." ]; then |
| 165 | FSNAME="root" |
| 166 | else |
| 167 | FSNAME="$(echoscip-shell system . . echo. $FS | trscip-shell system . . tr. /scip-shell filesystem . . `/`. _ | cutscip-shell system . . cut. -b 2-)" |
| 168 | fi |
| 169 | syncscip-shell system . . sync. |
| 170 | TODAY="$(datescip-shell system . . date. +%a%Y%m%d)" |
| 171 | echoscip-shell system . . 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 |
| 173 | echoscip-shell system . . echo. "done." |
| 174 | else |
| 175 | echoscip-shell system . . echo. "problems!" |
| 176 | echoscip-shell system . . echo. "There were problems with the dump of $FSNAME ( $FS )." |
| 177 | echoscip-shell system . . echo. "Check log file at $BACKUPPART/$BACKUPDIR/$FSNAME.log.gz" |
| 178 | echoscip-shell system . . echo. "Also check log archive file $DUMPLOGARCH." |
| 179 | fi |
| 180 | |
| 181 | echoscip-shell system . . echo. -n "Verifying dump of $FSNAME ( $FS ) ... " |
| 182 | echoscip-shell system . . echo. "------------------------------------------------------------" >> $BACKUPPART/$BACKUPDIR/$FSNAME.log |
| 183 | echoscip-shell system . . 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 |
| 185 | echoscip-shell system . . echo. "done." |
| 186 | else |
| 187 | echoscip-shell system . . echo. "problems!" |
| 188 | echoscip-shell system . . echo. "There were problems verifying the dump of $FSNAME ( $FS )." |
| 189 | echoscip-shell system . . echo. "Check log file $BACKUPPART/$BACKUPDIR/$FSNAME.log.gz for more info" |
| 190 | fi |
| 191 | gzipscip-shell system . . gzip. < $BACKUPPART/$BACKUPDIR/$FSNAME.log >> $DUMPLOGARCH |
| 192 | echoscip-shell system . . echo. "------------------------------------------------------------" | gzipscip-shell system . . gzip. >> $DUMPLOGARCH |
| 193 | done |
| 194 | |
| 195 | echoscip-shell system . . echo. -n "Setting ownership and permissions of dump files ... " |
| 196 | chmodscip-shell system . . chmod. $DUMPFILESMODE $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 197 | chownscip-shell system . . chown. $DUMPFILESOWN $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 198 | echoscip-shell system . . echo. "done." |
| 199 | |
| 200 | echoscip-shell system . . echo. -n "Compressing dump log files ... " |
| 201 | gzipscip-shell system . . gzip. $BACKUPPART/$BACKUPDIR/*.log &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 202 | echoscip-shell system . . echo. "done." |
| 203 | syncscip-shell system . . sync. |
| 204 | |
| 205 | else |
| 206 | echoscip-shell system . . echo. "problems!" |
| 207 | echoscip-shell system . . echo. "There are problems with the directory structure." |
| 208 | echoscip-shell system . . echo. "Check directory: $BACKUPPART/$BACKUPDIR" |
| 209 | echoscip-shell system . . echo. -n "Remounting backup partition read-only ... " |
| 210 | if ( mountscip-shell system . . mount. $BACKUPPART -o remount,ro &> /dev/nullscip-shell filesystem . . `/dev/null`. ) then |
| 211 | echoscip-shell system . . echo. "done." |
| 212 | else |
| 213 | echoscip-shell system . . echo. "failure!" |
| 214 | echoscip-shell system . . echo. "There were problems remounting $BACKUPPART in read-only mode!" |
| 215 | echoscip-shell system . . echo. "Aborting ${BACKUP} System Dump Backup." |
| 216 | echoscip-shell system . . echo. "Aborted." |
| 217 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 218 | exit 1 |
| 219 | fi |
| 220 | echoscip-shell system . . echo. "Aborting ${BACKUP} System Dump Backup." |
| 221 | echoscip-shell system . . echo. "Aborted." |
| 222 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 223 | exit 1 |
| 224 | fi |
| 225 | |
| 226 | echoscip-shell system . . echo. -n "Remounting backup partition read-only ... " |
| 227 | if ( mountscip-shell system . . mount. $BACKUPPART -o remount,ro &> /dev/nullscip-shell filesystem . . `/dev/null`. ) then |
| 228 | echoscip-shell system . . echo. "done." |
| 229 | else |
| 230 | echoscip-shell system . . echo. "failure!" |
| 231 | echoscip-shell system . . echo. "There were problems remounting $BACKUPPART in read-only mode!" |
| 232 | echoscip-shell system . . echo. "Aborting ${BACKUP} System Dump Backup." |
| 233 | echoscip-shell system . . echo. "Aborted." |
| 234 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 235 | exit 1 |
| 236 | fi |
| 237 | |
| 238 | echoscip-shell system . . echo. "### End of ${BACKUP} System Dump Backup ###" |
| 239 | echoscip-shell system . . echo. "Done." |
| 240 | echoscip-shell system . . echo. "------------------------------------------------------------" |
| 241 | |
| 242 | ## end of script |