3 # This script will make a simple backup of the most critical partitions,
4 # using the "dump" facility, into the backup partition. It will stop the
5 # webserver, and recurse the sites directories making a tar mini-backup of
6 # the database dirs. It will the restart the webserver, and start the
10 if [ "$2" = "nodumpdate" ]; then
16 if [ "$1" = "full" ]; then
19 elif [ "$1" = "inc" ]; then
23 echo "Usage: $0 full|inc [nodumpdate]"
29 # Configuration Parameters
34 DUMPLOGARCH="$BACKUPPART/backup.dump.log.gz"
35 FSTODUMP="/ /var /home /mnt/hdb1 /usr"
37 DUMPFILESOWN="root.root"
44 echo "#####################################################################"
45 echo "Starting backup."
46 echo "#####################################################################"
51 # Make full system backup
54 echo "Phase 1: ### Full System Dump Backup ###"
55 echo "Phase 1: Using backup partition: $BACKUPPART"
56 echo "Phase 1: Filesystems to dump: $FSTODUMP"
58 echo -n "Phase 1: Remounting backup partition read-write ... "
59 if ( mount $BACKUPPART -o remount,rw &> /dev/null ) then
63 echo "Phase 1: There were problems remounting $BACKUPPART in read-write mode!"
64 echo "Phase 1: Aborting Full System Dump Backup."
65 echo "Phase 1: Aborted, done."
66 echo "-------------------------------------------------------------------------------"
70 echo -n "Phase 1: Checking backup partition for correct dir structure ... "
71 if [ -d $BACKUPPART/$BACKUPDIR -a -w $BACKUPPART/$BACKUPDIR ]; then
74 echo -n "Phase 1: Checking backup partition for available space ... "
75 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}'`
76 SAVAILFREE=`df --block-size=1048576 |grep -Ew $BACKUPPART|awk '{printf "%6.0f\n", $4}'`
77 SAVAILDEL=`du -s --block-size=1048576 $BACKUPPART/$BACKUPDIR/. |awk '{printf "%6.0f\n", $1}'`
78 SAVAIL=`expr $SAVAILFREE + $SAVAILDEL`
80 if [ `expr $SAVAIL - $SREQ` -gt "0" ]; then
82 echo "Phase 1: Available: $SAVAIL MB Required: $SREQ MB."
84 echo "no enough space!"
85 echo "Phase 1: There is not enough space left in $BACKUPPART for the backup!"
86 echo "Phase 1: Available: $SAVAIL MB Required: $SREQ MB."
87 echo -n "Phase 1: Remounting backup partition read-only ... "
88 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
92 echo "Phase 1: There were problems remounting $BACKUPPART in read-only mode!"
93 echo "Phase 1: Aborting Full System Dump Backup."
94 echo "Phase 1: Aborted, done."
95 echo "-------------------------------------------------------------------------------"
98 echo "Phase 1: Aborting Full System Dump Backup."
99 echo "Phase 1: Aborted, done."
100 echo "-------------------------------------------------------------------------------"
104 echo -n "Phase 1: Deleting old files ... "
105 if [ `ls -la $BACKUPPART/$BACKUPDIR/|wc -l` -gt "3" ]; then
106 rm -f $BACKUPPART/$BACKUPDIR/* &> /dev/null
109 echo "no old files to delete."
112 echo "Phase 1: Dumping filesystems ... "
115 if [ "$FS" = "/" ]; then
118 FSNAME=`echo $FS|tr / _|cut -b 2-`
121 echo -n "Phase 1: Starting dump of $FSNAME ( $FS ) ... "
122 if ( dump -$DLEVEL $UPDATEDDATE -z -M -s 27306 -f $BACKUPPART/$BACKUPDIR/$FSNAME.$BTYPE. $FS &> $BACKUPPART/$BACKUPDIR/$FSNAME.log ) then
126 echo "Phase 1: There where problems with the dump of $FSNAME ( $FS )."
127 echo "Phase 1: Check logfile $BACKUPPART/$BACKUPDIR/$FSNAME.log for more info"
128 echo "Phase 1: Also check log archive file $DUMPLOGARCH."
130 cat $BACKUPPART/$BACKUPDIR/$FSNAME.log |gzip >> $DUMPLOGARCH
131 echo "-------------------------------------------------------------------------------" |gzip >> $DUMPLOGARCH
134 echo -n "Phase 1: Setting ownership and permissions of dump files ... "
135 chmod $DUMPFILESMODE $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev/null
136 chown $DUMPFILESOWN $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev/null
139 echo -n "Phase 1: Compressing dump log files ... "
140 gzip $BACKUPPART/$BACKUPDIR/*.log &> /dev/null
146 echo "Phase 1: There are problems with the directory structure."
147 echo "Phase 1: Check dirs: $BACKUPPART/$BACKUPDIR"
148 echo -n "Phase 1: Remounting backup partition read-only ... "
149 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
153 echo "Phase 1: There were problems remounting $BACKUPPART in read-only mode!"
154 echo "Phase 1: Aborting Full System Dump Backup."
155 echo "Phase 1: Aborted, done."
156 echo "-------------------------------------------------------------------------------"
159 echo "Phase 1: Aborting Full System Dump Backup."
160 echo "Phase 1: Aborted, done."
161 echo "-------------------------------------------------------------------------------"
165 echo -n "Phase 1: Remounting backup partition read-only ... "
166 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
170 echo "Phase 1: There were problems remounting $BACKUPPART in read-only mode!"
171 echo "Phase 1: Aborting Full System Dump Backup."
172 echo "Phase 1: Aborted, done."
173 echo "-------------------------------------------------------------------------------"
177 echo "Phase 1: End of Full System Dump Backup."
178 echo "Phase 1: Done."
179 echo "-------------------------------------------------------------------------------"