-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrestore-backup.sh
More file actions
executable file
·46 lines (38 loc) · 931 Bytes
/
restore-backup.sh
File metadata and controls
executable file
·46 lines (38 loc) · 931 Bytes
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
#!/bin/bash
set -e
if [ -e /.backup-restored ];
then
echo
echo 'Starting MySQL using prepared backup.'
echo
else
mkdir -p /var/lib/mysql
restore-percona-backup $1
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --datadir=/var/lib/mysql --user=mysql
mysqld &
pid="$!"
mysql=( mysql --protocol=socket -uroot )
for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
break
fi
echo 'MySQL init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'MySQL init process failed.'
exit 1
fi
echo "GRANT ALL PRIVILEGES ON *.* to root@`%` WITH GRANT OPTION;" | "${mysql[@]}"
echo "FLUSH PRIVILEGES;" | "${mysql[@]}"
if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'MySQL init process failed.'
exit 1
fi
touch /.backup-restored
echo
echo 'MySQL init process done. Ready for start up.'
echo
fi
exec "mysqld"