Listing 1 Rsync replication script
01
02 #!/usr/bin/ksh
03 # Rsync replication script
04 # Mike Scott
05 # 25/10/2005
06
07 # We should only attempt to sync if:
08 # * The destination IP address is pingable
09 # * There is a SSH connection
10 # * The vx diskgroup is locally imported (if not,
11 # then it's possible that we're in the failed over state)
12
13 # Remote destination hostname
14 HOSTNAME="standby_bak"
15 VXDG_NAME="database"
16
17 LOGFILE="/failover/logs/rsync.$HOSTNAME.$(date +'%d')"
18
19 exec 2>&1
20 exec >>$LOGFILE
21
22 #############################
23 # Supporting functions
24 timestamp() {
25 date +"%d/%m/%y %H:%M:%S"
26 }
27
28 log() {
29 if [ $# -gt 0 ] ; then
30 echo $(timestamp) $*
31 else
32 while read line
33 do
34 echo $(timestamp) $line
35 done
36 fi
37 }
38
39 gameOver() {
40 log "============================================================"
41 log " ERROR: Cannot Sync:"
42 log " $*"
43 log "============================================================"
44 echo logger -p user.err "/failover/rsync: $*"
45 exit 1
46 }
47
48 ##############################
49 # Prereq: vxdg is imported
50 log Checking Veritas Diskgroup
51 /usr/sbin/vxdg list $VXDG_NAME >/dev/null 2>&1
52
53 if [ $? -ne 0 ] ; then
54 gameOver "$VXDG_NAME Veritas Diskgroup not imported"
55 fi
56 log Veritas Diskgroup ok
57
58 log Checking failover host IP
59 ping $HOSTNAME 2 >/dev/null 2>&1
60 if [ $? -ne 0 ] ; then
61 gameOver "PING to $HOSTNAME Failed"
62 fi
63 log Failover host IP ok
64
65 log Checking failover host SSH
66 /usr/local/bin/ssh $HOSTNAME hostname >/dev/null 2>&1
67 if [ $? -ne 0 ] ; then
68 gameOver "SSH to $HOSTNAME Failed (rc=$?)"
69 fi
70 log Failover host SSH ok
71
72 log Checking Symmetrix SRDF State
73 # Note: we are assuming here that the Symmetrix Device group name
74 # is the same as the Veritas Disk Group name.
75 /usr/symcli/bin/symrdf -g $VXDG_NAME -synchronized verify >/dev/null 2>&1
76 if [ $? -ne 0 ] ; then
77 gameOver "SRDF is not fully synchronized for the $VXDG_NAME group"
78 fi
79 log Symmetrix SRDF State ok
80
81
82 RSYNC=/usr/local/bin/rsync
83 OPTIONS="-vtaz --one-file-system --rsync-path=$RSYNC --delete \
--rsh=/usr/local/bin/ssh"
84
85 # Here's the list of files to include and exclude
86 # Note that in this context a "file" means either
87 # a regular file or a directory
88 # If you are referring to a directory, then include a
89 # trailing "/"
90
91 INCLUDES="
92 /
93 /etc/init.d/
94 /etc/rc0.d/
95 /etc/rc2.d/
96 /etc/rc3.d/
97 /etc/rcS.d/
98 /etc/lp/
99 /etc/inet/
100 /etc/net/
101 /etc/opt/
102 /etc/ssh/
103 /etc/profile
104 /etc/passwd
105 /etc/shadow
106 /etc/group
107 /etc/resolv.conf
108 /etc/printers.conf
109 /etc/vfstab
110 /etc/system"
111
112 EXCLUDES="
113 /etc/
114 /kernel/drv/sd.conf
115 /dev/
116 /devices/
117 /proc/
118 /var/adm/sa/
119 /usr/emc/API/symapi/db
120 /usr/emc/API/symapi/log"
121
122 # Add exclusions to options list - I could have added them directly
# to the variable,
123 # but I felt that having an INCLUDE and EXCLUDE list as above was
# slightly clearer
124
125 for EXCLUSION in $EXCLUDES
126 do
127 OPTIONS="$OPTIONS --exclude=$EXCLUSION"
128 Done
129
130 log "Diskgroup configuration:"
131 VXVM_DG=$(/usr/sbin/vxdisk -g $VXDG_NAME -q list |wc -l|awk '{print $NF}')
132 SYMM_DG=$(/usr/symcli/bin/symdg show $VXDG_NAME |awk '/Number of STD \
Devices in Group/ {print $NF}')
133
134 log "NOTE: Number of Veritas Disks in $VXDG_NAME group : $VXVM_DG"
135 log "NOTE: Number of Symmetrix Disks in $VXDG_NAME group : $SYMM_DG"
136
137 /usr/symcli/bin/sympd list | log
138 /usr/symcli/bin/symrdf -g $VXDG_NAME query |log
139
140 log ""
141 log "Rsync Options: $OPTIONS"
142 log ""
143 log "Rsync startup"
144 ERROR=0
145
146 for FILE in $INCLUDES
147 do
148 echo Rsyncing $FILE to $HOSTNAME
149 echo -----------------
150 $RSYNC $OPTIONS $FILE $HOSTNAME:$FILE
151 ERROR=$(( $ERROR + $? ))
152 done |log
153
154 if [ $ERROR -gt 0 ] ; then
155 gameOver Rsync Failure
156 else
157 log -----------------------------
158 log " Rsync complete"
159 log -----------------------------
160 fi
|