source: LMDZ6/branches/IPSLCM6.0.15/tools/fcm/templates/utils/daily_cron

Last change on this file was 1578, checked in by jghattas, 13 years ago
  • Add fcm in LMDZ5/tools directory

It is no longer needed to have fcm in your environement PATH variable.
Now makelmdz_fcm takes by default this fcm. It is still possible to use
another fcm, using -fcm_path argument in makelmdz_fcm.

  • Property svn:executable set to *
File size: 7.6 KB
Line 
1#!/bin/ksh
2
3out=~fcm/FCM/daily_cron.out
4svn_live=/data/local/fcm/svn/live
5svn_backup=~fcm/svn/backups
6svn_tmp=/var/tmp/fcm/svn/backups
7svn_dump=~fcm/svn/dumps
8trac_live=~fcm/trac/live
9trac_backup=~fcm/trac/backups
10trac_tmp=/var/tmp/fcm/trac/backups
11err=''
12
13export RSYNC_RSH=rsh # remote shell for "rsync"
14
15{
16
17  # Verify and backup Subversion repository database
18  # ----------------------------------------------------------------------------
19  cd $svn_live
20  tmpfile=/tmp/${USER}.$$
21  now=$(date +%s)
22  for dir in *; do
23    if [[ ! -d $dir ]]; then continue; fi
24
25    # Verify
26    # --------------------------------------------------------------------------
27    echo "$(date): Verifying $dir ..."
28    sed '/^\* Verified revision [0-9][0-9]*\./d'<<EOF
29$(svnadmin verify $dir 2>&1; echo $? > $tmpfile)
30EOF
31    RC=$(cat $tmpfile)
32
33    if ((RC != 0)); then
34      err="${err}Error in $dir repository integrity. "
35      continue
36    fi
37
38    # Backup
39    # --------------------------------------------------------------------------
40    # Create the temporary backup location if it does not exists
41    if [[ ! -d $svn_tmp ]]; then
42      mkdir -p $svn_tmp
43
44      if (($? != 0)); then
45        err="${err}Error creating $svn_tmp. "
46        break
47      fi
48    fi
49
50    # Hotcopy to temporary location
51    tmp_backup_dir=$svn_tmp/$dir
52    echo "$(date): Hotcopying $dir SVN repository to $tmp_backup_dir ..."
53    svnadmin hotcopy $dir $tmp_backup_dir
54
55    if (($? != 0)); then
56      err="${err}Error hotcopying $dir SVN repository to $tmp_backup_dir. "
57      continue
58    fi
59
60    # Create the backup location if it does not exists
61    if [[ ! -d $svn_backup ]]; then
62      mkdir -p $svn_backup
63
64      if (($? != 0)); then
65        err="${err}Error creating $svn_backup. "
66        break
67      fi
68    fi
69
70    # Tar and gzip the backup
71    new_backup=$svn_backup/$dir.$(date +%Y%m%d).tgz
72    echo "$(date): Creating tar archive in $new_backup ..."
73    tar -C $svn_tmp -c -z -f $new_backup $(basename $tmp_backup_dir)
74
75    if (($? != 0)); then
76      err="${err}Error creating tar archive in $new_backup. "
77      continue
78    fi
79
80    # Remove the temporary hotcopy
81    rm -rf $tmp_backup_dir
82
83    if (($? != 0)); then
84      err="${err}Error removing $tmp_backup_dir. "
85    fi
86
87    # Remove the old backup, if necessary
88    backup=$svn_backup/$dir.tgz
89
90    if [[ -f $backup ]]; then
91      rm -f $backup
92
93      if (($? != 0)); then
94        err="${err}Error removing old copy of $backup. "
95        continue
96      fi
97    fi
98
99    # Move today's backup to the final location
100    echo "$(date): Renaming $new_backup to $backup ..."
101    mv $new_backup $backup
102
103    if (($? != 0)); then
104      err="${err}Error renaming $new_backup to $backup. "
105    fi
106
107    # Housekeep the revision dumps
108    # --------------------------------------------------------------------------
109    if [[ -d $svn_dump/$dir ]]; then
110      # Keep dumps created in the last 3 days
111      echo "$(date): Housekeeping dumps in $svn_dump/$dir ..."
112
113      cd $svn_dump/$dir
114      for rev in *; do
115        # Check that $rev is a regular file
116        if [[ ! -f $rev ]]; then
117          continue
118        fi
119
120        # 3 days = 24 * 60 * 60 * 3 = 259200 seconds
121        if (($now - $(stat -c %Y $rev) > 259200)); then
122          echo "$(date): Removing $svn_dump/$dir/$rev ..."
123          rm -f $rev
124          if (($? != 0)); then
125            err="${err}Error removing dump $svn_dump/$dir/$rev. "
126          fi
127        fi
128      done
129
130      cd $OLDPWD
131    fi
132  done
133
134  # Backing up Trac systems
135  # ----------------------------------------------------------------------------
136  cd $trac_live
137  for dir in *; do
138    if [[ ! -d $dir ]]; then continue; fi
139
140    # Backup
141    # --------------------------------------------------------------------------
142    # Create the temporary backup location if it does not exists
143    if [[ ! -d $trac_tmp ]]; then
144      mkdir -p $trac_tmp
145
146      if (($? != 0)); then
147        err="${err}Error creating $trac_tmp. "
148        break
149      fi
150    fi
151
152    # Hotcopy to temporary location
153    tmp_backup_dir=$trac_tmp/$dir
154    echo "$(date): Hotcopying $dir Trac system to $tmp_backup_dir ..."
155    trac-admin $dir hotcopy $tmp_backup_dir
156
157    if (($? != 0)); then
158      err="${err}Error hotcopying $dir Trac system to $tmp_backup_dir. "
159      continue
160    fi
161
162    # Create the backup location if it does not exists
163    if [[ ! -d $trac_backup ]]; then
164      mkdir -p $trac_backup
165
166      if (($? != 0)); then
167        err="${err}Error creating $trac_backup. "
168        break
169      fi
170    fi
171
172    # Tar and gzip the backup
173    new_backup=$trac_backup/$dir.$(date +%Y%m%d).tgz
174    echo "$(date): Creating tar archive in $new_backup ..."
175    tar -C $trac_tmp -c -z -f $new_backup $(basename $tmp_backup_dir)
176
177    if (($? != 0)); then
178      err="${err}Error creating tar archive in $new_backup. "
179      continue
180    fi
181
182    # Remove the temporary hotcopy
183    rm -rf $tmp_backup_dir
184
185    if (($? != 0)); then
186      err="${err}Error removing $tmp_backup_dir. "
187    fi
188
189    # Rename backups on success
190    # --------------------------------------------------------------------------
191    # Shift backup "1" to backup "2", and then backup "0" to backup "1"
192    for i in 1 0; do
193      old_file=$trac_backup/$dir.$i.tgz
194      new_file=$trac_backup/$dir.$((i + 1)).tgz
195
196      # Check if move is necessary
197      if [[ ! -f $old_file ]]; then
198        continue
199      fi
200
201      if [[ -f $new_file ]]; then
202        echo "$(date): Removing $new_file ..."
203        rm -f $new_file
204
205        if (($? != 0)); then
206          err="${err}Error removing $new_file. "
207          break
208        fi
209      fi
210
211      echo "$(date): Renaming $old_file to $new_file ..."
212      mv $old_file $new_file
213      if (($? != 0)); then
214        err="${err}Error renaming $old_file. "
215        break
216      fi
217    done
218
219    # Move today's backup to "0", if possible
220    backup=$trac_backup/$dir.0.tgz
221    if [[ ! -f $backup ]]; then
222      echo "$(date): Renaming $new_backup to $backup ..."
223      mv $new_backup $backup
224      if (($? != 0)); then
225        err="${err}Error renaming $new_backup to $backup. "
226      fi
227    fi
228  done
229
230  # Update the Trac password file and databases with latest login information
231  # ----------------------------------------------------------------------------
232  echo "$(date): Updating password files and Trac databases ..."
233  $(dirname $0)/fcm_manage_login.py
234  if (($? != 0)); then
235    err="${err} Error updating Trac password file and databases. "
236  fi
237
238  # Sync the working copy to the NEC
239  # ----------------------------------------------------------------------------
240  echo "$(date): Updating NEC ..."
241  rsync -a -v --timeout=1800 --exclude='.*' --exclude='FCM/doc' \
242    --delete-excluded ~/FCM/work/FCM fcm@tx01:~/FCM/work
243  if (($? != 0)); then
244    err="${err}Error updating NEC. "
245  fi
246
247  # Update "synch" path from "synch" machine
248  # ----------------------------------------------------------------------------
249  echo "$(date): Updating synch machine ..."
250  for subdir in bin lib etc; do
251    rsync -a -v --timeout=1800 --exclude='.*' ~/FCM/work/FCM/src/$subdir/* \
252      fcm@hc0100:/opt/ukmo/utils/supported/portable/$subdir/
253
254    if (($? != 0)); then
255      err="${err}Error updating $subdir/ on synch machine. "
256    fi
257  done
258
259  # Final report
260  # ----------------------------------------------------------------------------
261  if [[ -n $err ]]; then
262    subject="$(basename $0) finished with errors: $err"
263
264  else
265    subject="$(basename $0) finished normally."
266  fi
267
268  echo "$(date): $subject"
269} 1>$out 2>&1
270
271# Report completion via e-mail
272# ------------------------------------------------------------------------------
273mail -s "$subject" my.name@somewhere.org <<EOF
274$(<$out)
275EOF
276
277# EOF
Note: See TracBrowser for help on using the repository browser.