]> git.wh0rd.org - dump.git/blame_incremental - examples/cron_dump_to_disk/backup
More improvements from Aaron S. Hawley <ashawley@sourceforge.net>
[dump.git] / examples / cron_dump_to_disk / backup
... / ...
CommitLineData
1#!/bin/bash
2#
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
7# "dump" backup.
8#
9
10if [ "$2" = "nodumpdate" ]; then
11 UPDATEDDATE=""
12else
13 UPDATEDDATE="-u"
14fi
15
16if [ "$1" = "full" ]; then
17 DLEVEL="0"
18 BTYPE="full"
19 BACKUP="Full"
20elif [ "$1" = "inc" ]; then
21 DLEVEL="1"
22 BTYPE="inc"
23 BACKUP="Incremental"
24else
25 echo "Usage: $0 full|inc [nodumpdate]"
26 exit 1
27fi
28
29
30#
31# Configuration Parameters
32#
33
34BACKUPPART=${BACKUPPART:-"/backup"}
35BACKUPDIR=${BACKUPDIR:-"current"}
36DUMPLOGARCH="$BACKUPPART/backup.dump.log.gz"
37FSTODUMP=${FSTODUMP:-/ /var /home /mnt/hdb1 /usr}
38DUMPFILESMODE="0644"
39DUMPFILESOWN="root.root"
40
41#
42# Start
43#
44
45echo
46echo "#####################################################################"
47echo "Starting ${BACKUP} backup."
48echo "#####################################################################"
49echo
50
51
52#
53# Make system backup
54#
55
56echo "### ${BACKUP} System Dump Backup ###"
57echo "Using backup partition: $BACKUPPART"
58echo "Filesystems to dump: $FSTODUMP"
59
60echo -n "Remounting backup partition read-write ... "
61if ( mount $BACKUPPART -o remount,rw &> /dev/null ) then
62 echo "done."
63elif ( mount $BACKUPPART -o rw &> /dev/null ) then
64 echo "done."
65else
66 echo "failure!"
67 echo " There were problems remounting $BACKUPPART in read-write mode!"
68 echo "Aborting ${BACKUP} System Dump Backup."
69 echo "Aborted."
70 echo "-------------------------------------------------------------------------------"
71 exit 1
72fi
73
74echo -n "Checking backup partition for correct dir structure ... "
75if [ -d $BACKUPPART/$BACKUPDIR -a -w $BACKUPPART/$BACKUPDIR ]; then
76 echo "done."
77
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`
83
84 if [ `expr $SAVAIL - $SREQ` -gt "0" ]; then
85 echo "done."
86 echo "Available: $SAVAIL MB Required: $SREQ MB."
87 else
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
93 echo "done."
94 elif ( mount $BACKUPPART -o ro &> /dev/null ) then
95 echo "done."
96 else
97 echo "failure!"
98 echo "There were problems remounting $BACKUPPART in read-only mode!"
99 echo "Aborting ${BACKUP} System Dump Backup."
100 echo "Aborted."
101 echo "-------------------------------------------------------------------------------"
102 exit 1
103 fi
104 echo "Aborting ${BACKUP} System Dump Backup."
105 echo "Aborted."
106 echo "-------------------------------------------------------------------------------"
107 exit 1
108 fi
109
110 echo -n "Deleting old files ... "
111 if [ `ls -la $BACKUPPART/$BACKUPDIR/ | wc -l` -gt "3" ]; then
112 rm -f $BACKUPPART/$BACKUPDIR/* &> /dev/null
113 echo "done."
114 else
115 echo "no old files to delete."
116 fi
117
118 echo "Dumping filesystems ... "
119 for FS in $FSTODUMP
120 do
121 if [ "$FS" = "/" ]; then
122 FSNAME="root"
123 else
124 FSNAME=`echo $FS | tr / _ | cut -b 2-`
125 fi
126 sync
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
129 echo "done."
130 else
131 echo "problems!"
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."
135 fi
136 cat $BACKUPPART/$BACKUPDIR/$FSNAME.log |gzip >> $DUMPLOGARCH
137 echo "-------------------------------------------------------------------------------" |gzip >> $DUMPLOGARCH
138 done
139
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
143 echo "done."
144
145 echo -n "Compressing dump log files ... "
146 gzip $BACKUPPART/$BACKUPDIR/*.log &> /dev/null
147 echo "done."
148 sync
149
150else
151 echo "problems!"
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
156 echo "done."
157 else
158 echo "failure!"
159 echo "There were problems remounting $BACKUPPART in read-only mode!"
160 echo "Aborting ${BACKUP} System Dump Backup."
161 echo "Aborted."
162 echo "-------------------------------------------------------------------------------"
163 exit 1
164 fi
165 echo "Aborting ${BACKUP} System Dump Backup."
166 echo "Aborted."
167 echo "-------------------------------------------------------------------------------"
168 exit 1
169fi
170
171echo -n "Remounting backup partition read-only ... "
172if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
173 echo "done."
174else
175 echo "failure!"
176 echo "There were problems remounting $BACKUPPART in read-only mode!"
177 echo "Aborting ${BACKUP} System Dump Backup."
178 echo "Aborted."
179 echo "-------------------------------------------------------------------------------"
180 exit 1
181fi
182
183echo "### End of ${BACKUP} System Dump Backup ###"
184echo "Done."
185echo "-------------------------------------------------------------------------------"