]> git.wh0rd.org - dump.git/blame - examples/cron_dump_to_disk/backup_rotate
Yet more improvements to cron_dump_to_disk.
[dump.git] / examples / cron_dump_to_disk / backup_rotate
CommitLineData
1733496b 1#!/bin/bash
6a33575a
SP
2
3###
4 # Copyright (C) 2001 Eugenio Diaz <getnito@yahoo.com>
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 redirect the backup directory to implement desired
36 # backup schedules.
37 #
38 # We will use just a seven day format where we just move a link that
39 # represents the backup directory, to point to the day of the week.
40 ##
41
1733496b
SP
42
43#
44# Configuration Parameters
45#
46
47if [ "$1" = "monthly" ]; then
48 REALDIR="monthly"
49else
50 REALDIR=`date +%A`
51fi
52
b35abb32
SP
53BACKUPPART=${BACKUPPART:-"/backup"}
54BACKUPDIR=${BACKUPDIR:-"current"}
1733496b
SP
55
56echo "### Start of Backup Rotation ###"
57echo "Using backup partition: $BACKUPPART"
58
59echo -n "Remounting backup partition read-write ... "
60if ( mount $BACKUPPART -o remount,rw &> /dev/null ) then
61 echo "done."
62else
63 echo "failure!"
6a33575a 64 echo "There were problems remounting $BACKUPPART in read-write mode!"
1733496b
SP
65 echo "Rotation not made!"
66 echo "### End of Backup Rotation ###"
67 exit 1
68fi
69
70echo -n "Checking that no directory named \"$BACKUPDIR\" exists ... "
71if [ -d $BACKUPPART/$BACKUPDIR -a ! -L $BACKUPPART/$BACKUPDIR ]; then
72 echo "failure!"
6a33575a 73 echo "Directory \"$BACKUPDIR\" exists. Can't create link!"
1733496b
SP
74 echo "Rotation not made!"
75
76 echo -n "Remounting backup partition read-only ... "
77 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
78 echo "done."
79 else
80 echo "failure!"
6a33575a 81 echo "There were problems remounting $BACKUPPART in read-only mode!"
1733496b
SP
82 echo "### End of Backup Rotation ###"
83 exit 1
84 fi
85 echo "### End of Backup Rotation ###"
86 exit 1
87else
88 echo "done."
89fi
90
91cd $BACKUPPART
92
93echo -n "Creating link: $BACKUPDIR --> $REALDIR ... "
94if ( ln -snf $REALDIR $BACKUPDIR &> /dev/null ) then
95 echo "done."
96else
97 echo "failure!"
6a33575a 98 echo "There were problems creating link!"
1733496b
SP
99 echo "Rotation not made!"
100
101 echo -n "Remounting backup partition read-only ... "
102 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
103 echo "done."
104 else
105 echo "failure!"
6a33575a 106 echo "There were problems remounting $BACKUPPART in read-only mode!"
1733496b
SP
107 echo "### End of Backup Rotation ###"
108 exit 1
6a33575a 109 fi
1733496b
SP
110 echo "### End of Backup Rotation ###"
111 exit 1
112fi
113
114echo -n "Remounting backup partition read-only ... "
115if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
116 echo "done."
117else
118 echo "failure!"
6a33575a 119 echo "There were problems remounting $BACKUPPART in read-only mode!"
1733496b
SP
120 echo "### End of Backup Rotation ###"
121 exit 1
122fi
123echo "### End of Backup Rotation ###"
6a33575a
SP
124
125## end of script