]> git.wh0rd.org - dump.git/blame - examples/cron_dump_to_disk/backup_rotate
More cleanup fixes.
[dump.git] / examples / cron_dump_to_disk / backup_rotate
CommitLineData
1733496b
SP
1#!/bin/bash
2#
3# This script will redirect the backup directory to implement desired backup
4# schedules.
5#
6# Currently we will use just a seven day format were we just move a link
7# that represents the backup directory, to point to the day of the week.
8#
9
10#
11# Configuration Parameters
12#
13
14if [ "$1" = "monthly" ]; then
15 REALDIR="monthly"
16else
17 REALDIR=`date +%A`
18fi
19
20BACKUPPART="/backup"
21BACKUPDIR="current"
22
23echo "### Start of Backup Rotation ###"
24echo "Using backup partition: $BACKUPPART"
25
26echo -n "Remounting backup partition read-write ... "
27if ( mount $BACKUPPART -o remount,rw &> /dev/null ) then
28 echo "done."
29else
30 echo "failure!"
31 echo " There were problems remounting $BACKUPPART in read-write mode!"
32 echo "Rotation not made!"
33 echo "### End of Backup Rotation ###"
34 exit 1
35fi
36
37echo -n "Checking that no directory named \"$BACKUPDIR\" exists ... "
38if [ -d $BACKUPPART/$BACKUPDIR -a ! -L $BACKUPPART/$BACKUPDIR ]; then
39 echo "failure!"
40 echo " Directory \"$BACKUPDIR\" exists. Can't create link!"
41 echo "Rotation not made!"
42
43 echo -n "Remounting backup partition read-only ... "
44 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
45 echo "done."
46 else
47 echo "failure!"
48 echo " There were problems remounting $BACKUPPART in read-only mode!"
49 echo "### End of Backup Rotation ###"
50 exit 1
51 fi
52 echo "### End of Backup Rotation ###"
53 exit 1
54else
55 echo "done."
56fi
57
58cd $BACKUPPART
59
60echo -n "Creating link: $BACKUPDIR --> $REALDIR ... "
61if ( ln -snf $REALDIR $BACKUPDIR &> /dev/null ) then
62 echo "done."
63else
64 echo "failure!"
65 echo " There were problems creating link!"
66 echo "Rotation not made!"
67
68 echo -n "Remounting backup partition read-only ... "
69 if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
70 echo "done."
71 else
72 echo "failure!"
73 echo " There were problems remounting $BACKUPPART in read-only mode!"
74 echo "### End of Backup Rotation ###"
75 exit 1
76 fi
77 echo "### End of Backup Rotation ###"
78 exit 1
79fi
80
81echo -n "Remounting backup partition read-only ... "
82if ( mount $BACKUPPART -o remount,ro &> /dev/null ) then
83 echo "done."
84else
85 echo "failure!"
86 echo " There were problems remounting $BACKUPPART in read-only mode!"
87 echo "### End of Backup Rotation ###"
88 exit 1
89fi
90echo "### End of Backup Rotation ###"