Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
3294 rexy 1
#!/bin/bash
2
 
3
#########################
4
## ALCASAR replication ##
5
##      uninstall      ##
6
#########################
7
# The script is designed to delete all replication artefacts.
8
 
9
# Constants
10
readonly PASSWD_FILE="/root/ALCASAR-passwords.txt"
11
readonly REPL_USER="replication"
12
readonly REPL_DB_USER="$REPL_USER"
13
readonly DB_CONF=/etc/my.cnf.d/server.cnf
14
readonly DB_REPL_CONF=/etc/my.cnf.d/replication.cnf
15
readonly ALCASAR_CONF=/usr/local/etc/alcasar.conf
16
 
17
# Dynamically generated constants
18
DB_ROOT_PWD="$(grep db_root "$PASSWD_FILE" | cut -d '=' -f 2-)"
19
readonly DB_ROOT_PWD
20
 
21
 
22
# Execute SQL queries on local server
23
exec_query() {
24
	if [ $# -ne 1 ]
25
	then
26
		echo "A SQL query must be given." >&2
27
		return 1
28
	fi
29
 
30
	# Execute the query
31
	/usr/bin/mariadb --user=root --password="$DB_ROOT_PWD" --execute="$1"
32
}
33
 
34
if grep -q "REPLICATION=off" "$ALCASAR_CONF"
35
then
36
	echo "error: replication not installed" >&2
37
	exit 2
38
fi
39
 
40
# Remove all remotes connected
41
/usr/local/bin/alcasar-replication-stop.sh --all
42
/usr/local/bin/alcasar-replication-delete.sh --all
43
 
44
# Delete generated credentials for system user
45
sed -i "/# Replication/d" "$PASSWD_FILE"
46
sed -i "/^replication/d" "$PASSWD_FILE"
47
 
48
# Delete generated credentials for database user
49
sed -i "/# Database replication/d" "$PASSWD_FILE"
50
sed -i "/^db_replication/d" "$PASSWD_FILE"
51
 
52
# Delete database replication user
53
echo "Revoking '$REPL_DB_USER' privileges..."
54
exec_query "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '$REPL_DB_USER'@'%'" || exit
55
exec_query "FLUSH PRIVILEGES" || exit
56
echo "Deleting '$REPL_DB_USER' user from database..."
57
exec_query "DROP USER IF EXISTS '$REPL_DB_USER'@'%'" || exit
58
 
59
# Disable binary logging
60
echo "Disabling binary logging..."
61
rm -f "$DB_REPL_CONF"
62
exec_query "RESET MASTER" || exit
63
 
64
# Unlisten on localhost
65
sed -i "s?.*skip-networking.*?skip-networking?" "$DB_CONF"
66
sed -i "s?^bind-address=.*?#bind-address=127.0.0.1?" "$DB_CONF"
67
 
68
# Apply binary logging
69
echo "Restarting MariaDB..."
70
/usr/bin/systemctl restart mariadb.service
71
 
72
# User for SSH tunneling
73
echo "Dropping replication user..."
74
/usr/bin/pkill -u "$REPL_USER"
75
/usr/sbin/userdel -r "$REPL_USER"
76
 
77
# Reset REPLICATION config attributes in conf file
78
sed -i "/^REPLICATION=/s/on/off/" "$ALCASAR_CONF"
79
 
80
echo "Resetting outbound firewall rules..."
81
sed -i "/^REPLICATION_TO=/s/=.*$/=/" "$ALCASAR_CONF"
82
/usr/local/bin/alcasar-iptables.sh
83
 
84
echo "Database replication succesfully uninstalled."