~percona-dev/percona-xtrabackup/percona-xtrabackup-windows-vadim

« back to all changes in this revision

Viewing changes to test/inc/common.sh

  • Committer: Aleksandr Kuzminsky
  • Date: 2010-06-02 13:05:00 UTC
  • mto: This revision was merged to the branch mainline in revision 138.
  • Revision ID: aleksandr.kuzminsky@percona.com-20100602130500-8f39yicogve1xamm
Added the XtraBackup test framework

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/env bash
 
2
 
 
3
set -eu
 
4
topdir="`pwd`/var"
 
5
mysql_datadir="$topdir/mysql"
 
6
mysql_port="3306"
 
7
mysql_socket="$topdir/mysql.sock"
 
8
MYSQL=mysql
 
9
MYSQL_ARGS="--socket=${mysql_socket} --user=root"
 
10
MYSQLD=mysqld_safe
 
11
MYSQLD_ARGS="--socket=${mysql_socket} --datadir=$mysql_datadir"
 
12
 
 
13
 
 
14
function vlog
 
15
{
 
16
    #echo ""
 
17
    echo "`date +"%F %T"`: `basename "$0"`: $1"
 
18
}
 
19
 
 
20
function clean()
 
21
{
 
22
    vlog "Removing temporary $topdir"
 
23
    rm -rf "$topdir"
 
24
}
 
25
function clean_on_error()
 
26
{
 
27
vlog "Exit on error"
 
28
clean
 
29
exit
 
30
}
 
31
 
 
32
 
 
33
function initdir()
 
34
{
 
35
    if test -d "$topdir"
 
36
    then
 
37
        vlog "Directory $topdir exists. Removing it..."
 
38
        rm -r "$topdir"
 
39
    fi
 
40
    vlog "Creating temporary directory: $topdir"
 
41
    mkdir -p "$topdir"
 
42
    vlog "Creating MySQL data directory: $mysql_datadir"
 
43
    mkdir -p "$mysql_datadir"
 
44
}
 
45
 
 
46
function init_mysql_dir()
 
47
{
 
48
    vlog "Creating MySQL database"
 
49
    mysql_install_db --datadir="$mysql_datadir"
 
50
}
 
51
function set_mysl_port()
 
52
{
 
53
    i=$mysql_port
 
54
    while [ $i -lt 65536 ]
 
55
    do
 
56
        # check if port $i is used
 
57
        vlog "Checking port $i"
 
58
        port_status=`netstat -an | grep LISTEN | grep tcp | grep ":$i " || true`
 
59
        if test -z "$port_status"
 
60
        then
 
61
            # port is not used
 
62
            vlog "Port $i is free"
 
63
            mysql_port=$i
 
64
            break
 
65
        else
 
66
            vlog "Port $i is used"
 
67
            let i=$i+1
 
68
        fi
 
69
    done
 
70
}
 
71
 
 
72
# Checks whether MySQL is alive
 
73
function mysql_ping()
 
74
{
 
75
    local result="0"
 
76
    if test -S ${mysql_socket}
 
77
    then
 
78
        result=`${MYSQL} ${MYSQL_ARGS} -e "SELECT IF(COUNT(*)>=0, 1, 1) FROM user;" -s --skip-column-names mysql 2>/dev/null` || result="0"
 
79
    else
 
80
        result="0"
 
81
    fi
 
82
    echo $result
 
83
    }
 
84
 
 
85
 
 
86
function run_mysqld()
 
87
{
 
88
    local c=0
 
89
    ${MYSQLD} ${MYSQLD_ARGS} --port=$mysql_port &
 
90
    while [ "`mysql_ping`" != "1" ]
 
91
    do
 
92
        if [ ${c} -eq 100 ]
 
93
        then
 
94
            vlog "Can't run MySQL!"
 
95
            clean_on_error
 
96
        fi
 
97
        let c=${c}+1
 
98
        sleep 1
 
99
    done
 
100
    vlog "MySQL started successfully"
 
101
 
 
102
}
 
103
 
 
104
function stop_mysqld()
 
105
{
 
106
    mysqladmin ${MYSQL_ARGS} shutdown
 
107
 
 
108
}
 
109
 
 
110
function load_sakila()
 
111
{
 
112
vlog "Loading sakila"
 
113
${MYSQL} ${MYSQL_ARGS} -e "create database sakila"
 
114
vlog "Loading sakila scheme"
 
115
${MYSQL} ${MYSQL_ARGS} sakila < inc/sakila-db/sakila-schema.sql
 
116
vlog "Loading sakila data"
 
117
${MYSQL} ${MYSQL_ARGS} sakila < inc/sakila-db/sakila-data.sql
 
118
}