summaryrefslogtreecommitdiff
path: root/wip/mariadb-push-replica.sh
blob: fbf94023b183b07c7218879eb368ad61b002172c (plain)
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
#!/bin/bash
set -ex

default_slave_remote_file=data/default-slave-remote
master_password_file=data/mysql-master-password

if [ -r "$default_slave_remote_file" ]
then
	read default_remote_host < "$default_slave_remote_file"
fi

gen_password()
{
	generated_password_length=32
	generated_password=$(tr -cd a-zA-Z0-9 < /dev/urandom | head -c "$generated_password_length")
	[ "${#generated_password}" -eq "$generated_password_length" ]
	printf '%s\n' "$generated_password"
}

if ! [ -e "$master_password_file" ]
then
	gen_password > "$master_password_file"
fi

if [ -r "$master_password_file" ]
then
	read master_password < "$master_password_file" 
	[ "${#master_password}" -ge 30 ]
fi

our_host=$(hostname --fqdn)
remote_host=${1:-$default_remote_host}

rpc_funcs=

rpc()
{
	read shellscript < <(declare -f $rpc_funcs; echo $*)
	set -- $shellscript
	ssh -l "$remote_user" -- "$remote_host" ${*@Q}
}

[ "$our_host" ]
[ "$remote_host" ]
[ "$master_password" ]

primarydb_create_user()
{
	:
}

mariabackup_target_dir=/var/mariadb/backup
primarydb_export_backup()
{
	mkdir -p "$mariabackup_target_dir"
	mariabackup --backup --target-dir="$mariabackup_target_dir"
}

primarydb()
{
	ssh -l root "$remote_host" -- "$@"
}
remote_user=root
rpc uptime
exit 1

ssh -l root "$remote_host" -- mariadb -t <<END
select @@hostname, @@server_id, @@gtid_slave_pos, @@sql_log_bin;
SELECT VARIABLE_NAME,SESSION_VALUE,GLOBAL_VALUE  FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME='sql_log_bin' OR VARIABLE_NAME='HOSTNAME' \G
SELECT VARIABLE_NAME,SESSION_VALUE,GLOBAL_VALUE  FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES \G
END

exit 0

ssh -l root "$remote_host" -- mariadb <<END
CHANGE MASTER TO
  MASTER_HOST='$our_host',
  MASTER_USER='replication',
  MASTER_PASSWORD='$master_password'
END