Project

General

Profile

« Previous | Next » 

Revision 10237

Added by Matt Jones over 7 years ago

Add backup script to copy files to Amazon S3.

View differences:

src/scripts/bash/backup-aws.sh
1
#!/bin/sh
2

  
3
#
4
# Backup files needed for metacat.  This script creates a directory in /var/metacat/backup,
5
# backs up the postgres database, metacat data files, and certificate and web config files,
6
# then syncs those files to an Amazon S3 bucket for backup.
7
#
8
# To run this file, install it in /usr/sbin or a similar location and add an
9
# entry in the root user's crontab to run the command periodically.  The
10
# following crontab entry would run it every night at 2:00 am
11
# 0 2 * * *       /usr/sbin/backup-aws.sh >> $HOME/cron-output 2>&1
12
#
13
# This is really just an example script and may not work in your environment
14
# uless you modify it appropriately.
15
#
16
# 25 Apr 2017 Matt Jones
17

  
18
# Name of the metacat database in postgres to be backed up
19
DBNAME=metacat
20

  
21
# Number of days of backups to keep online, anything older is removed
22
DAYSTOKEEP=7
23

  
24
# AWS S3 bucket to be used for backup
25
BUCKET=s3://arcticdata.io/backup
26

  
27
# Location of the metacat.properties file
28
METACATPROPERTIESPATH=/var/lib/tomcat7/webapps/metacat/WEB-INF/metacat.properties
29

  
30
# Location of the apache configuration file
31
APACHECONF=/etc/apache2/sites-enabled
32

  
33
#Location of the server key
34
KEYLOCATION=/etc/ssl/private 
35

  
36
#Location of the server certificate
37
CERTLOCATION=/etc/ssl/certs/www_arcticdata_io.crt
38
#
39
# Below here lie demons
40
#
41

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

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

  
53
ARCHDIR="$ARCHROOT"
54
mkdir -p $ARCHDIR
55

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

  
59
echo Copy the metacat.properties file to /var/metacat
60
cp $METACATPROPERTIESPATH $ARCHDIR
61

  
62
echo Backup postgres
63
su - postgres -c "pg_dumpall | gzip > $ARCHDIR/metacat-postgres-backup.gz"
64

  
65
echo Copy the apache configuration files
66
tar czhf $ARCHDIR/apache-config-backup.tgz $APACHECONF $KEYLOCATION $CERTLOCATION
67

  
68
echo Sync the backup directory to Amazon S3
69
aws s3 sync $DATADIR $BUCKET
70

  
71
# Restart tomcat
72
#/etc/init.d/tomcat7 start
73

  
74
# Clean up the temp files
75
#rm -rf $ARCHDIR
76

  
77
# clean up any of the backup files that are older than DAYSTOKEEP
78
#find $ARCHROOT -mtime +$DAYSTOKEEP -exec rm -f {} \;
79

  
80
echo "DONE backup for $TAG"
81

  
0 82

  

Also available in: Unified diff