Project

General

Profile

1 3781 daigle
#!/bin/sh
2
3
#
4
# Backup files needed for metacat.  This script creates a temporary directory,
5
# backs up the postgres database, metacat data files, and ldap directory, and
6
# then creates a gzipped tar file from those files.  It then writes the backup
7
# file to a DVD drive and then cleans up any old backup files.
8
#
9
# To run this file, install it in /usr/sbin or a similar location and add an
10
# entry in the root user's crontab to run the command periodically.  The
11
# following crontab entry would run it every night at 2:00 am
12
# 0 2 * * *       /usr/sbin/backup-metacat.sh >> $HOME/cron-output 2>&1
13
#
14
# This is really just an example script and may not work in your environment
15
# uless you modify it appropriately.
16
#
17
# 13 March 2006 Matt Jones
18
19
# Name of the metacat database in postgres to be backed up
20
DBNAME=metacat
21
22
# The day of the week on which the DVD is swapped (1-7, 1=Monday)
23
# This must be correct or else the write to DVD will not work
24
SWAPDAY=2
25
26
# Number of days of backups to keep online, anything older is removed
27
DAYSTOKEEP=7
28
29
# Device to be used for the DVD writer -- this may vary on your system
30
DVD=/dev/dvd
31
32 8883 tao
# Location of the metacat.properties file
33 8882 tao
METACATPROPERTIESPATH=/var/lib/tomcat6/webapps/knb/WEB-INF/metacat.properties
34 8883 tao
35
# Location of the apache configuration file
36
APACHECONF=/etc/apache2/sites-enabled
37 8919 tao
38
#Location of the server key
39
KEYLOCATION=/etc/ssl/private
40
41
#Location of the server certificate
42
CERTLOCATION=/etc/ssl/certs/_.test.dataone.org.crt
43 3781 daigle
#
44
# Below here lie demons
45
#
46
47
# Set up our umask to protect files from prying eyes
48
umask 007
49
50
# Make a temp dir for the backed up files
51
TAG=`date +%F-%H%M%S`
52
DATADIR="/var/metacat"
53
ARCHROOT="/var/metacat/metacat-backup"
54
mkdir $ARCHROOT
55
chgrp postgres $ARCHROOT
56
chmod g+rwxs $ARCHROOT
57
58
ARCHNAME="metacat-backup-$TAG"
59
ARCHDIR="$ARCHROOT/$ARCHNAME"
60
mkdir $ARCHDIR
61
62
# Shut down the tomcat server so nobody else changes anything while we backup
63 8882 tao
/etc/init.d/tomcat6 stop
64 3781 daigle
65
# Shut down ldap too
66 8882 tao
#/etc/init.d/slapd stop
67 3781 daigle
68 8882 tao
# Copy the metacat.properties file to /var/metacat
69
cp $METACATPROPERTIESPATH $DATADIR
70
71 3781 daigle
# Backup postgres
72 8938 tao
su - postgres -c "pg_dumpall | gzip > $ARCHDIR/metacat-postgres-backup.gz"
73 3781 daigle
74
# Backup the data files
75 9090 tao
tar czhf $ARCHDIR/datafiles-backup.tgz --exclude=$ARCHROOT $DATADIR
76 3781 daigle
77 8883 tao
# Backup the apache configuration files
78 8919 tao
tar czhf $ARCHDIR/apache-config-backup.tgz $APACHECONF $KEYLOCATION $CERTLOCATION
79 8883 tao
80 3781 daigle
# Backup LDAP to an LDIF file
81 8883 tao
#slapcat -l $ARCHDIR/$DBNAME-ldap.ldif
82 3781 daigle
83
# Restart LDAP
84 8882 tao
#/etc/init.d/slapd start
85 3781 daigle
86
# Restart tomcat
87 8882 tao
/etc/init.d/tomcat6 start
88 3781 daigle
89
# Tar up the archive and copy it to archive media
90
cd $ARCHROOT
91 9090 tao
tar czhf $ARCHDIR.tgz $ARCHNAME
92 3781 daigle
93
# Clean up the temp files
94
rm -rf $ARCHDIR
95
96
# Write the backup file to DVD
97 8919 tao
#DAY=`date +%u`
98
#DVDFLAG=-M
99
#if [ $DAY == $SWAPDAY ] ; then
100
  #DVDFLAG=-Z
101
#fi
102 8918 tao
#growisofs $DVDFLAG $DVD -R -J $ARCHDIR.tgz
103 3781 daigle
104
# clean up any of the backup files that are older than DAYSTOKEEP
105
find $ARCHROOT -mtime +$DAYSTOKEEP -exec rm -f {} \;