Imported Upstream version 0.4b42
[debian/dump] / examples / cron_dump_to_disk / backup_rotate
1 #!/bin/bash
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
42
43 #
44 # Configuration Parameters
45 #
46
47 if [ "$1" = "monthly" ]; then
48    REALDIR="monthly"
49 else
50    REALDIR=`date +%A`
51 fi
52
53 BACKUPPART=${BACKUPPART:-"/backup"}
54 BACKUPDIR=${BACKUPDIR:-"current"}
55
56 echo "### Start of Backup Rotation ###"
57 echo "Using backup partition: $BACKUPPART"
58
59 echo -n "Remounting backup partition read-write ... "
60 if ( mount $BACKUPPART -o remount,rw &> /dev/null ) then
61    echo "done."
62 else
63    echo "failure!"
64    echo "There were problems remounting $BACKUPPART in read-write mode!"
65    echo "Rotation not made!"
66    echo "### End of Backup Rotation ###"
67    exit 1
68 fi
69
70 echo -n "Checking that no directory named \"$BACKUPDIR\" exists ... "
71 if [ -d $BACKUPPART/$BACKUPDIR -a ! -L $BACKUPPART/$BACKUPDIR ]; then
72    echo "failure!"
73    echo "Directory \"$BACKUPDIR\" exists. Can't create link!"
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!"
81       echo "There were problems remounting $BACKUPPART in read-only mode!"
82       echo "### End of Backup Rotation ###"
83       exit 1
84    fi
85    echo "### End of Backup Rotation ###"
86    exit 1
87 else
88    echo "done."
89 fi
90
91 cd $BACKUPPART
92
93 echo -n "Creating link: $BACKUPDIR --> $REALDIR ... "
94 if ( ln -snf $REALDIR $BACKUPDIR &> /dev/null ) then
95    echo "done."
96 else
97    echo "failure!"
98    echo "There were problems creating link!"
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!"
106       echo "There were problems remounting $BACKUPPART in read-only mode!"
107       echo "### End of Backup Rotation ###"
108       exit 1
109    fi
110    echo "### End of Backup Rotation ###"
111    exit 1
112 fi
113
114 echo -n "Remounting backup partition read-only ... "
115 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
116    echo "done."
117 else
118    echo "failure!"
119    echo "There were problems remounting $BACKUPPART in read-only mode!"
120    echo "### End of Backup Rotation ###"
121    exit 1
122 fi
123 echo "### End of Backup Rotation ###"
124
125 ## end of script