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 |
3781
|
daigle
|
#
|
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 |
8882
|
tao
|
/etc/init.d/tomcat6 stop
|
58 |
3781
|
daigle
|
|
59 |
|
|
# Shut down ldap too
|
60 |
8882
|
tao
|
#/etc/init.d/slapd stop
|
61 |
3781
|
daigle
|
|
62 |
8882
|
tao
|
# Copy the metacat.properties file to /var/metacat
|
63 |
|
|
cp $METACATPROPERTIESPATH $DATADIR
|
64 |
|
|
|
65 |
3781
|
daigle
|
# 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 |
8883
|
tao
|
# Backup the apache configuration files
|
72 |
|
|
tar czhf $ARCHDIR/apache-config-backup.tgz $APACHECONF
|
73 |
|
|
|
74 |
3781
|
daigle
|
# Backup LDAP to an LDIF file
|
75 |
8883
|
tao
|
#slapcat -l $ARCHDIR/$DBNAME-ldap.ldif
|
76 |
3781
|
daigle
|
|
77 |
|
|
# Restart LDAP
|
78 |
8882
|
tao
|
#/etc/init.d/slapd start
|
79 |
3781
|
daigle
|
|
80 |
|
|
# Restart tomcat
|
81 |
8882
|
tao
|
/etc/init.d/tomcat6 start
|
82 |
3781
|
daigle
|
|
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 {} \;
|