]>
git.wh0rd.org - dump.git/blob - examples/cron_dump_to_disk/backup
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
20 elif [ "$1" = "inc" ]; then
25 echo "Usage: $0 full|inc [nodumpdate]"
31 # Configuration Parameters
34 BACKUPPART
=${BACKUPPART:-"/backup"}
35 BACKUPDIR
=${BACKUPDIR:-"current"}
36 DUMPLOGARCH
="$BACKUPPART/backup.dump.log.gz"
37 FSTODUMP
=${FSTODUMP:-/ /var /home /mnt/hdb1 /usr}
39 DUMPFILESOWN
="root.root"
46 echo "#####################################################################"
47 echo "Starting ${BACKUP} backup."
48 echo "#####################################################################"
56 echo "### ${BACKUP} System Dump Backup ###"
57 echo "Using backup partition: $BACKUPPART"
58 echo "Filesystems to dump: $FSTODUMP"
60 echo -n "Remounting backup partition read-write ... "
61 if ( mount
$BACKUPPART -o remount
,rw
&> /dev
/null
) then
63 elif ( mount
$BACKUPPART -o rw
&> /dev
/null
) then
67 echo " There were problems remounting $BACKUPPART in read-write mode!"
68 echo "Aborting ${BACKUP} System Dump Backup."
70 echo "-------------------------------------------------------------------------------"
74 echo -n "Checking backup partition for correct dir structure ... "
75 if [ -d $BACKUPPART/$BACKUPDIR -a -w $BACKUPPART/$BACKUPDIR ]; then
78 echo -n "Checking backup partition for available space ... "
79 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}'`
80 SAVAILFREE
=`df --block-size=1048576 | grep -Fe $BACKUPPART | awk '{printf "%6.0f\n", $4}'`
81 SAVAILDEL
=`du -s --block-size=1048576 $BACKUPPART/$BACKUPDIR/. | awk '{printf "%6.0f\n", $1}'`
82 SAVAIL
=`expr $SAVAILFREE + $SAVAILDEL`
84 if [ `expr $SAVAIL - $SREQ` -gt "0" ]; then
86 echo "Available: $SAVAIL MB Required: $SREQ MB."
88 echo "not enough space!"
89 echo "There is not enough space left in $BACKUPPART for the backup!"
90 echo "Available: $SAVAIL MB Required: $SREQ MB."
91 echo -n "Remounting backup partition read-only ... "
92 if ( mount
$BACKUPPART -o remount
,ro
&> /dev
/null
) then
94 elif ( mount
$BACKUPPART -o ro
&> /dev
/null
) then
98 echo "There were problems remounting $BACKUPPART in read-only mode!"
99 echo "Aborting ${BACKUP} System Dump Backup."
101 echo "-------------------------------------------------------------------------------"
104 echo "Aborting ${BACKUP} System Dump Backup."
106 echo "-------------------------------------------------------------------------------"
110 echo -n "Deleting old files ... "
111 if [ `ls -la $BACKUPPART/$BACKUPDIR/ | wc -l` -gt "3" ]; then
112 rm -f $BACKUPPART/$BACKUPDIR/* &> /dev
/null
115 echo "no old files to delete."
118 echo "Dumping filesystems ... "
121 if [ "$FS" = "/" ]; then
124 FSNAME
=`echo $FS | tr / _ | cut -b 2-`
127 echo -n "Starting dump of $FSNAME ( $FS ) ... "
128 if ( dump
-$DLEVEL $UPDATEDDATE -z -M -s 27306 -f $BACKUPPART/$BACKUPDIR/$FSNAME.
$BTYPE.
$FS &> $BACKUPPART/$BACKUPDIR/$FSNAME.log
) then
132 echo "There were problems with the dump of $FSNAME ( $FS )."
133 echo "Check log file at $BACKUPPART/$BACKUPDIR/$FSNAME.log.gz"
134 echo "Also check log archive file $DUMPLOGARCH."
136 cat $BACKUPPART/$BACKUPDIR/$FSNAME.log |
gzip >> $DUMPLOGARCH
137 echo "-------------------------------------------------------------------------------" |
gzip >> $DUMPLOGARCH
140 echo -n "Setting ownership and permissions of dump files ... "
141 chmod $DUMPFILESMODE $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev
/null
142 chown
$DUMPFILESOWN $BACKUPPART/$BACKUPDIR/* $DUMPLOGARCH &> /dev
/null
145 echo -n "Compressing dump log files ... "
146 gzip $BACKUPPART/$BACKUPDIR/*.log
&> /dev
/null
152 echo "There are problems with the directory structure."
153 echo "Check directory: $BACKUPPART/$BACKUPDIR"
154 echo -n "Remounting backup partition read-only ... "
155 if ( mount
$BACKUPPART -o remount
,ro
&> /dev
/null
) then
159 echo "There were problems remounting $BACKUPPART in read-only mode!"
160 echo "Aborting ${BACKUP} System Dump Backup."
162 echo "-------------------------------------------------------------------------------"
165 echo "Aborting ${BACKUP} System Dump Backup."
167 echo "-------------------------------------------------------------------------------"
171 echo -n "Remounting backup partition read-only ... "
172 if ( mount
$BACKUPPART -o remount
,ro
&> /dev
/null
) then
176 echo "There were problems remounting $BACKUPPART in read-only mode!"
177 echo "Aborting ${BACKUP} System Dump Backup."
179 echo "-------------------------------------------------------------------------------"
183 echo "### End of ${BACKUP} System Dump Backup ###"
185 echo "-------------------------------------------------------------------------------"