/[smeserver]/rpms/smeserver-mysql/sme10/smeserver-mysql-2.7.0-bz12145-backupuserprivileges.patch
ViewVC logotype

Contents of /rpms/smeserver-mysql/sme10/smeserver-mysql-2.7.0-bz12145-backupuserprivileges.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Sun Sep 1 04:21:50 2024 UTC (2 months, 3 weeks ago) by jpp
Branch: MAIN
CVS Tags: smeserver-mysql-2_7_0-19_el7_sme
* Sun Sep 01 2024 Jean-Philippe Pialasse <jpp@koozali.org> 2.7.0-19.sme
- backup user privileges in separate file [SME: 12145]
  this will allow mariadb 10.3 and higher migration
  and is needed to restore to SME 11

1 diff -Nur --no-dereference smeserver-mysql-2.7.0.old/root/etc/e-smith/events/actions/mysql-dump-tables smeserver-mysql-2.7.0/root/etc/e-smith/events/actions/mysql-dump-tables
2 --- smeserver-mysql-2.7.0.old/root/etc/e-smith/events/actions/mysql-dump-tables 2022-03-11 10:32:13.000000000 -0500
3 +++ smeserver-mysql-2.7.0/root/etc/e-smith/events/actions/mysql-dump-tables 2024-09-01 00:17:19.404000000 -0400
4 @@ -18,24 +18,53 @@
5 echo $message | /usr/bin/mail -s "error on backup of $db MariaDB database" admin
6 fi
7 message="$message \nThere was an error trying to dump database $db, please check for table errors in this db. Forcing a backup of the corrupted DB."
8 - mysqldump --force --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db"-failed.dump || message="$message \nFailed to force backup of corrupted db $db as $db-failed.dump" >&2
9 + mysqldump --force --ignore-table=mysql.event --ignore-table=mysql.users --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db"-failed.dump || message="$message \nFailed to force backup of corrupted db $db as $db-failed.dump" >&2
10 if [ "$fixtables" = "enabled" ]; then
11 repair="failure"
12 message="$message \nTrying to auto-repair the db and do a backup after..."
13 mysqlcheck -s --auto-repair -c "$db" && \
14 - mysqldump --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db".dump && repair="success"
15 + mysqldump --ignore-table=mysql.event --ignore-table=mysql.users --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db".dump && repair="success"
16 message="$message \n => $repair"
17 fi
18 echo $message
19 echo $message | /usr/bin/mail -s "error on backup of $db MariaDB database" admin
20 }
21
22 +# Do nothing if disabled
23 if [ "$status" = "disabled" ]
24 then
25 echo "mysqld is disabled - no tables dumped" >&2
26 exit 0
27 fi
28 +
29 +# Actual mysql db backup
30 for db in $(mysql -BNre "show databases;"|egrep -vi "^information_schema$|^performance_schema$")
31 do
32 - mysqldump --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db".dump || onfailure $db
33 + mysqldump --ignore-table=mysql.event --ignore-table=mysql.users --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db".dump || onfailure $db
34 +done
35 +
36 +# Backup the users and privileges
37 +# backup of mysql/mariadb users excluding root for later restore.
38 +# would allow compatible backup from mariadb <103 to mariadb >= 103
39 +# will also need to exclude mysql.user from restore in mariadb >= 103
40 +# inspired by https://stackoverflow.com/a/56588240
41 +# for mariadb 5.5 we replace authentication_string with Password
42 +mysql $@ -sNe " \
43 + SELECT \
44 + CONCAT( 'CREATE USER \'', User, '\'@\'', Host, '\' IDENTIFIED BY \'', Password, '\'\;' ) AS User \
45 + FROM mysql.user \
46 + WHERE \
47 + User NOT LIKE 'mysql.%' AND CONCAT( User, Host ) <> 'rootlocalhost' \
48 +" >/home/e-smith/db/mysql/mysql.privileges.dump
49 +mysql $@ -sNe " \
50 + SELECT \
51 + CONCAT( '\'', User, '\'@\'', Host, '\'' ) as User FROM mysql.user \
52 + WHERE \
53 + User NOT LIKE 'mysql.%' \
54 + AND CONCAT( User, Host ) <> 'rootlocalhost' \
55 +" | sort | while read u ;
56 + do echo "-- $u">> /home/e-smith/db/mysql/mysql.privileges.dump
57 + mysql $@ -sNe "show grants for $u" | sed 's/$/;/' >> /home/e-smith/db/mysql/mysql.privileges.dump
58 done
59 +echo >> /home/e-smith/db/mysql/mysql.privileges.dump
60 +echo "FLUSH PRIVILEGES;" >> /home/e-smith/db/mysql/mysql.privileges.dump
61 diff -Nur --no-dereference smeserver-mysql-2.7.0.old/rootscl/etc/e-smith/events/actions/mariadb_VER_-dump-tables smeserver-mysql-2.7.0/rootscl/etc/e-smith/events/actions/mariadb_VER_-dump-tables
62 --- smeserver-mysql-2.7.0.old/rootscl/etc/e-smith/events/actions/mariadb_VER_-dump-tables 2024-08-31 23:52:18.590000000 -0400
63 +++ smeserver-mysql-2.7.0/rootscl/etc/e-smith/events/actions/mariadb_VER_-dump-tables 2024-09-01 00:16:51.103000000 -0400
64 @@ -35,24 +35,53 @@
65 echo $message | /usr/bin/mail -s "error on backup of $db MariaDB !!!VER!!! database" admin
66 fi
67 message="$message \nThere was an error trying to dump database $db, please check for table errors in this db. Forcing a backup of the corrupted DB."
68 - /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --force --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db"-failed.dump || message="$message \nFailed to force backup of corrupted db $db as $db-failed.dump" >&2
69 + /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --force --ignore-table=mysql.event --ignore-table=mysql.users --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db"-failed.dump || message="$message \nFailed to force backup of corrupted db $db as $db-failed.dump" >&2
70 if [ "$fixtables" = "enabled" ]; then
71 repair="failure"
72 message="$message \nTrying to auto-repair the db and do a backup after..."
73 /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqlcheck --socket=!!!SOCKET!!! -s --auto-repair -c "$db" && \
74 - /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db".dump && repair="success"
75 + /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --ignore-table=mysql.event --ignore-table=mysql.users --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db".dump && repair="success"
76 message="$message \n => $repair"
77 fi
78 echo $message
79 echo $message | /usr/bin/mail -s "error on backup of $db MariaDB database" admin
80 }
81
82 +# Do nothing if disabled
83 if [ "$status" = "disabled" ]
84 then
85 echo "mysqld is disabled - no tables dumped" >&2
86 exit 0
87 fi
88 +
89 +# Actual mysql db backup
90 for db in $(/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql --socket=!!!SOCKET!!! -BNre "show databases;"|egrep -vi "^information_schema$|^performance_schema$")
91 do
92 - /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db".dump || onfailure $db
93 + /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --ignore-table=mysql.event --ignore-table=mysql.users --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db".dump || onfailure $db
94 +done
95 +
96 +# Backup the users and privileges
97 +# backup of mysql/mariadb users excluding root for later restore.
98 +# would allow compatible backup from mariadb <103 to mariadb >= 103
99 +# will also need to exclude mysql.user from restore in mariadb >= 103
100 +# inspired by https://stackoverflow.com/a/56588240
101 +/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql $@ -sNe " \
102 + SELECT \
103 + CONCAT( 'CREATE USER \'', User, '\'@\'', Host, '\' IDENTIFIED BY \'', authentication_string, '\'\;' ) AS User \
104 + FROM mysql.user \
105 + WHERE \
106 + User NOT LIKE 'mysql.%' AND CONCAT( User, Host ) <> 'rootlocalhost' \
107 +" >/home/e-smith/db/mariadb!!!VER!!!/mysql.privileges.dump
108 +/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql $@ -sNe " \
109 + SELECT \
110 + CONCAT( '\'', User, '\'@\'', Host, '\'' ) as User FROM mysql.user \
111 + WHERE \
112 + User NOT LIKE 'mysql.%' \
113 + AND CONCAT( User, Host ) <> 'rootlocalhost' \
114 +" | sort | while read u ;
115 + do echo "-- $u">> /home/e-smith/db/mariadb!!!VER!!!/mysql.privileges.dump
116 + /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql $@ -sNe "show grants for $u" | sed 's/$/;/' >> /home/e-smith/db/mariadb!!!VER!!!/mysql.privileges.dump
117 done
118 +echo >> /home/e-smith/db/mariadb!!!VER!!!/mysql.privileges.dump
119 +echo "FLUSH PRIVILEGES;" >> /home/e-smith/db/mariadb!!!VER!!!/mysql.privileges.dump
120 +

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed