-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql-maint.sh
84 lines (70 loc) · 1.89 KB
/
mysql-maint.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# $Header:$
#
# This script handles normal maintance chores for the MySQL database engine and the
# 'licenses' database that it currently hosts.
#
# PATH to contain only well known and well controlled directories.
# In particular /usr/local/bin is avoided since a user might install
# something there that would cause us to break.
PATH=/opt/local/bin:/usr/bin:/usr/sbin:/sbin:$PATH
PATH=/var/opt/sysconf/scripts:$PATH
PATH=$(dirname $0):$(dirname $0)/../bin:$PATH
trap 'rm -f /tmp/*.tmp.$$~ /tmp/*.tmp.$$~.d/*' 0
usage()
{
echo " Usage: $0 [-vxqp]"
echo " -v) Verbose"
echo " -x) Trace on"
echo " -p) preview"
echo " -q) Quiet"
exit -1
}
trace=false
quiet=false
preview=false
verbose=false
set - `getopt qxpvh? $*`
if [ $? != 0 ]
then
echo $*
usage
fi
for I in $*
do
case "x$I" in
x-q) quiet=true ; shift;;
x-x) trace=true ; shift;;
x-p) preview=true ; shift;;
x-v) verbose=true ; shift;;
x-h) usage ;;
esac
done
hostname=$(hostname)
host=$(echo $hostname | sed 's/\..*//') # Just the short name.
if ! $quiet; then
echo "$0: Type=$machine-$os, Server=$server"
fi
if [ `id -u` -ne 0 ]
then
echo "This script should only be ran by root!"
exit 1
fi
###############################################################################
#
#
# Chores to do:
# 1 - check and clean tables
# 2 - re-optimize the flexlm_usage table
# 3 - get the counts to how many records are in the database, first and last
# dates.
# 4 - Backup database.
myisamchk --fast --silent /var/lib/mysql/*/*.MYI
# Optimize the main tables
#echo "OPTIMIZE TABLE flexlm_events" | mysql --silent -u lic_user --password=newpass licenses
#echo "OPTIMIZE TABLE license_usage" | mysql --silent -u lic_user --password=newpass licenses
#
# Backup Database
#
DEST=/disc/extras/mysql
#mysqlhotcopy --allowold -u root --flushlog --password=js-iwnly licenses $DEST