Revision 2955
Added by Matt Jones almost 19 years ago
bin/backup-metacat.sh | ||
---|---|---|
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 |
# |
|
33 |
# Below here lie demons |
|
34 |
# |
|
35 |
|
|
36 |
# Set up our umask to protect files from prying eyes |
|
37 |
umask 007 |
|
38 |
|
|
39 |
# Make a temp dir for the backed up files |
|
40 |
TAG=`date +%F-%H%M%S` |
|
41 |
ARCHROOT="/tmp/metacat-backup" |
|
42 |
mkdir $ARCHROOT |
|
43 |
chgrp postgres $ARCHROOT |
|
44 |
chmod g+rwxs $ARCHROOT |
|
45 |
|
|
46 |
ARCHNAME="metacat-backup-$TAG" |
|
47 |
ARCHDIR="$ARCHROOT/$ARCHNAME" |
|
48 |
mkdir $ARCHDIR |
|
49 |
|
|
50 |
# Shut down the tomcat server so nobody else changes anything while we backup |
|
51 |
/etc/init.d/tomcat stop |
|
52 |
|
|
53 |
# Shut down ldap too |
|
54 |
/etc/init.d/slapd stop |
|
55 |
|
|
56 |
# Backup postgres |
|
57 |
su - postgres -c "pg_dump $DBNAME > $ARCHDIR/metacat-postgres-backup.sql" |
|
58 |
|
|
59 |
# Backup the data files |
|
60 |
tar czf $ARCHDIR/datafiles-backup.tgz /var/metacat |
|
61 |
|
|
62 |
# Backup LDAP to an LDIF file |
|
63 |
slapcat -l $ARCHDIR/$DBNAME-ldap.ldif |
|
64 |
|
|
65 |
# Restart LDAP |
|
66 |
/etc/init.d/slapd start |
|
67 |
|
|
68 |
# Restart tomcat |
|
69 |
/etc/init.d/tomcat start |
|
70 |
|
|
71 |
# Tar up the archive and copy it to archive media |
|
72 |
cd $ARCHROOT |
|
73 |
tar czf $ARCHDIR.tgz $ARCHNAME |
|
74 |
|
|
75 |
# Clean up the temp files |
|
76 |
rm -rf $ARCHDIR |
|
77 |
|
|
78 |
# Write the backup file to DVD |
|
79 |
DAY=`date +%u` |
|
80 |
DVDFLAG=-M |
|
81 |
if [ $DAY == $SWAPDAY ] ; then |
|
82 |
DVDFLAG=-Z |
|
83 |
fi |
|
84 |
growisofs $DVDFLAG $DVD -R -J $ARCHDIR.tgz |
|
85 |
|
|
86 |
# clean up any of the backup files that are older than DAYSTOKEEP |
|
87 |
find $ARCHROOT -mtime +$DAYSTOKEEP -exec rm -f {} \; |
|
0 | 88 |
Also available in: Unified diff
Adding a new metacat backup shell script that collates all of the files needed by metacat into a temp directory, tars them up, and writes them to a DVD drive. The script makes some assumptions about the system, so it will need to be customized for particular deployments. It is only an example. But it may be useful to others, so it is included here.