Project

General

Profile

1
#!/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
# Location of the metacat.properties file
33
METACATPROPERTIESPATH=/var/lib/tomcat6/webapps/knb/WEB-INF/metacat.properties
34

    
35
# Location of the apache configuration file
36
APACHECONF=/etc/apache2/sites-enabled
37
#
38
# Below here lie demons
39
#
40

    
41
# Set up our umask to protect files from prying eyes
42
umask 007
43

    
44
# Make a temp dir for the backed up files
45
TAG=`date +%F-%H%M%S`
46
DATADIR="/var/metacat"
47
ARCHROOT="/var/metacat/metacat-backup"
48
mkdir $ARCHROOT
49
chgrp postgres $ARCHROOT
50
chmod g+rwxs $ARCHROOT
51

    
52
ARCHNAME="metacat-backup-$TAG"
53
ARCHDIR="$ARCHROOT/$ARCHNAME"
54
mkdir $ARCHDIR
55

    
56
# Shut down the tomcat server so nobody else changes anything while we backup
57
/etc/init.d/tomcat6 stop
58

    
59
# Shut down ldap too
60
#/etc/init.d/slapd stop
61

    
62
# Copy the metacat.properties file to /var/metacat
63
cp $METACATPROPERTIESPATH $DATADIR
64

    
65
# Backup postgres
66
su - postgres -c "pg_dump $DBNAME > $ARCHDIR/metacat-postgres-backup.sql"
67

    
68
# Backup the data files
69
tar czf $ARCHDIR/datafiles-backup.tgz --exclude=$ARCHROOT $DATADIR
70

    
71
# Backup the apache configuration files
72
tar czhf $ARCHDIR/apache-config-backup.tgz $APACHECONF 
73

    
74
# Backup LDAP to an LDIF file
75
#slapcat -l $ARCHDIR/$DBNAME-ldap.ldif
76

    
77
# Restart LDAP
78
#/etc/init.d/slapd start
79

    
80
# Restart tomcat
81
/etc/init.d/tomcat6 start
82

    
83
# Tar up the archive and copy it to archive media
84
cd $ARCHROOT
85
tar czf $ARCHDIR.tgz $ARCHNAME
86

    
87
# Clean up the temp files
88
rm -rf $ARCHDIR
89

    
90
# Write the backup file to DVD
91
DAY=`date +%u`
92
DVDFLAG=-M
93
if [ $DAY == $SWAPDAY ] ; then
94
  DVDFLAG=-Z
95
fi
96
growisofs $DVDFLAG $DVD -R -J $ARCHDIR.tgz
97

    
98
# clean up any of the backup files that are older than DAYSTOKEEP
99
find $ARCHROOT -mtime +$DAYSTOKEEP -exec rm -f {} \;
(2-2/8)