-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmakeSmartArchive.sh
executable file
·42 lines (32 loc) · 1.02 KB
/
makeSmartArchive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
# This script makes an archive of the current Smart
# database tables. The archive is stored in a file in the dataArchives
# directory, with the current timestamp or day of week as part of the filename.
DIR=/Users/abrady/WebApplications/ramp
ARCHIVEDIR=${DIR}/SmartDataArchives
MYSQLDIR=/usr/local/mysql/bin
# Create a new, unique filename on Sundays so that weekly archives are
# kept indefinitely (or until deleted). For the other days of the week,
# use the day of the week (e.g., fyregistMon.sql); these files will be
# overwritten by an archive one week later.
DAYOFWEEK=`date '+%a'`
if [ $DAYOFWEEK = "Sun" ]
then
TODAYSDATE=`date | tr -d ' '`
else
TODAYSDATE=$DAYOFWEEK
fi
if [ $# -gt 0 ]
then
ARCHIVENAME=$1
DATABASES="--databases $1"
else
ARCHIVENAME=all
DATABASES="--all-databases"
fi
ARCHIVE=${ARCHIVEDIR}/${ARCHIVENAME}${TODAYSDATE}.sql
# umask 277
OPTIONS="--single-transaction --host=localhost --user=rampdba"
${MYSQLDIR}/mysqldump $OPTIONS $DATABASES >$ARCHIVE
chmod 400 $ARCHIVE
exit 0