File: mysql-server.cron.daily

package info (click to toggle)
mysql-dfsg 4.0.24-10sarge3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 56,212 kB
  • ctags: 42,312
  • sloc: ansic: 257,918; cpp: 93,002; perl: 29,480; sh: 24,628; tcl: 19,882; yacc: 3,558; makefile: 2,452; java: 2,300; awk: 1,484; asm: 687; sed: 428; sql: 27
file content (53 lines) | stat: -rw-r--r-- 1,335 bytes parent folder | download
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
#!/bin/bash
#
# This script only rotates the binary logs. The normal logs are rotated
# via /etc/logrotate.d/mysql-server.
#
# The number of binary logs that should be kept can be configured in
#	/etc/mysql/debian-log-rotate.conf
#
set -e
set -u

###########################################################################

M="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf"
MA="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
tmp=`tempfile`;

my_exit () {
  rm $tmp
  exit $1	  
}

test -x /usr/bin/mysqladmin || exit 0

# Read config and see if we should rotate at all.
. /etc/mysql/debian-log-rotate.conf
if [ "$KEEP_BINARY_LOGS" -eq 0 ]; then
  my_exit 0
fi

# Test if the server is up and running.
if ! $MA --silent ping >/dev/null; then
  my_exit 0
fi

# Retrieving list of file names. Can fail if no binary logs are in use.
if ! echo 'SHOW MASTER LOGS;' | $M --skip-column-names >$tmp 2>&1; then
  if grep -q 'You are not using binary logging' $tmp; then
    my_exit 0
  else
    echo "Unknown problem retrieving MySQL master log filenames in $0."
    cat $tmp
    my_exit 1
  fi
fi

# Test if we have enough log files to rotate and do so if.
if [ `wc -l < $tmp` -gt $KEEP_BINARY_LOGS ]; then
  filename=`tail -n $KEEP_BINARY_LOGS $tmp | head -n 1`
  echo "PURGE MASTER LOGS TO '$filename';" | $M
fi

my_exit 0