-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqldump_backup_restore.tar
90 lines (68 loc) · 7 KB
/
mysqldump_backup_restore.tar
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
81
82
83
84
85
86
87
88
89
90
mysql_backup_restoreAll.sh 0000777 0000000 0000000 00000002250 14614723235 013203 0 ustar #!/bin/bash
# Usage: ./mysql_backup_restoreAll.sh
# mysqlump file has format: db_name.hostname.domain.DD-MM-YYYY_HHMM
# filedir="USER INPUT"
read -p "Now enter the directory where all the backupfiles resides: " filedir
# MySQL Router instance
# mysqlrouter="USER INPUT"
read -p "Now provide the MySQL Router hostname to be used: " mysqlrouter
echo
echo "You have entered: $filedir & $mysqlrouter:"
echo
read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
#BACKUPFILE=`ls $filedir| grep 00 | grep 2024_ | grep -v mysql `
#DBNAME=echo $BACKUPFILE | cut -d . -f 1
cd $filedir
for i in `ls | grep -v mysql | grep 00 | grep 2024_ | cut -d . -f 1`; do echo "select \"""$i"\""; drop database $i; create database $i; use $i; source "`ls $i*`"; select count(table_name) from information_schema.tables where table_schema = '$i';" > cre_db_$i.sql ; echo "mysqlsh icadmin@$mysqlrouter --log-file=cre_db_$i.log --sqlc -e \"source cre_db_$i.sql;\""; echo "grep -i 'create table' `ls $i*` | wc -l"; done > restoreAll.sh
chmod 744 $filedir/restoreAll.sh
echo
echo "Now run 'cd $filedir' and execute './restoreAll.sh > restoreAll.sh.log '"
echo