File: mysql-server-4.1.mysql-server-41.cron.daily

package info (click to toggle)
mysql-dfsg-4.1 4.1.11a-4sarge8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 86,724 kB
  • ctags: 78,396
  • sloc: ansic: 380,120; cpp: 348,266; sh: 32,501; tcl: 30,484; perl: 20,873; yacc: 5,447; java: 4,610; makefile: 4,406; xml: 3,857; pascal: 1,795; awk: 1,338; asm: 1,064; sed: 772; sql: 503
file content (53 lines) | stat: -rw-r--r-- 1,320 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="mysql --defaults-file=/etc/mysql/debian.cnf"
MA="mysqladmin --defaults-file=/etc/mysql/debian.cnf"
tmp=`tempfile`;

my_exit () {
  rm $tmp
  exit $1	  
}

test -x /usr/bin/mysqladmin || my_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