-
Notifications
You must be signed in to change notification settings - Fork 11
/
do_backup.sh
146 lines (117 loc) · 5.06 KB
/
do_backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/ksh
# ********************************************************************
#
# File: do_backup
# Author: Eric Nielsen,
# Created: 04/10/96
# Modified:
#
# Description: This script runs the backups for host sec. The host
# sec has two file systems, one mounted on / and the
second mounted on /export.
# ********************************************************************
# ********************************************************************
#
# Check to be sure user is root
#
# ********************************************************************
USER=`/bin/id | grep root | wc -l`
if [ $USER -eq 0 ]
then
echo ""
echo "You must be root to run this script"
echo ""
exit 1
fi
# ********************************************************************
#
# Argument Processing
#
# ********************************************************************
if [ $# -ne 1 ]
then
/usr/bin/cat<<eof
Usage:do_backup <backup level>
<0> Full backup
<1> All changes since level 0
<2> All changes since level 1
<3> All changes since level 2
<4> All changes since level 3
<5> All changes since level 4
<6> All changes since level 5
<7> All changes since level 6
<8> All changes since level 7
<9> All changes since level 8
Example: do_backup 1
eof
exit
fi
# ********************************************************************
#
# Initialize Variables
#
# ********************************************************************
# set BACKUPHOME to the directory you want the log files stored.
BACKUPHOME=/backups
UFSDUMPHOME=/usr/sbin
EJECT=
# Set these variables to the filesystems you want to backup
# You can also define additional ones and annd dump corrisponding dump lines below
ROOTFILESYSTEM=/
EXPORTFILESYSTEM=/export
if [ $1 -eq 0 ]
then
DATE=`/usr/bin/date '+%d%b%y-%H:%M:%S'`.full
else
DATE=`/usr/bin/date '+%d%b%y-%H:%M:%S'`
fi
# ********************************************************************
#
# Dump the file systems
#
# ********************************************************************
# rewind the tape
/usr/bin/mt -f /dev/rmt/0 rewind
# echo the report header to the logfile and to standard out
echo "**************************************************************** " | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "*Starting Backups, Level $1, $DATE " | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo " " | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
# Dump a filesystem specified by $EXPORTFILESYSTEM
echo "#1. Dumping sec:/dev/md/dsk/d1 ${EXPORTFILESYSTEM}" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
${UFSDUMPHOME}/ufsdump ${1}fu /dev/rmt/0n ${EXPORTFILESYSTEM} 2>&1 | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo " " | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
# Dump a filesystem specified by $ROOTFILESYSTEM
echo "#2. Dumping sec:/dev/rdsk/c0t3d0s0, ${ROOTFILESYSTEM}" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
${UFSDUMPHOME}/ufsdump ${1}fu /dev/rmt/0n ${ROOTFILESYSTEM}" 2>&1 | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo " " | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
# Dump a filesystem specified by $ROOTFILESYSTEM
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "*Finishing Backups, Level $1, $DATE" | tee -a ${BACKUPHOME}/logs/log.${DATE}
echo "****************************************************************" | tee -a ${BACKUPHOME}/logs/log.${DATE}
# ********************************************************************
#
# Rewind the tape, eject the tape if backup Level 0
#
# Take the tape offiline and eject the tape if this is a level zero in
# order to allow someone to change the tape.
#
# ********************************************************************
/usr/bin/mt -f /dev/rmt/0 rewind
if [ $1 -eq 0 ]
then
/usr/bin/mt -f /dev/rmt/0 offline
fi
/bin/date | tee -a ${BACKUPHOME}/logs/log.${DATE}
# ********************************************************************
#
# The end
#
# ********************************************************************