1 <!-- Copyright 2021 Canonical Ltd.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may
4 not use this file except in compliance with the License. You may obtain
5 a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 License for the specific language governing permissions and limitations
15 For those usages not covered by the Apache License, Version 2.0 please
16 contact: legal@canonical.com
18 To get in touch with the maintainers, please contact:
19 osm-charmers@lists.launchpad.net -->
27 You must specify key configuration attributes when deploying,
28 or else arbitary defaults will be used. The attributes which
38 --config user=fred \
39 --config password=secret \
40 --config database=test \
41 --config root_password=admin
43 These values may also be in a config.yaml file, eg
45 $ juju deploy mysql --config config.yaml
52 Execute the following steps to do a backup.
55 $ juju run-action mariadb-k8s/0 backup --wait
61 cmd: kubectl cp zaza-9769f2bf245e/mariadb-k8s-0:/var/lib/mysql/backup.sql.gz
64 cmd: kubectl cp backup.sql.gz zaza-9769f2bf245e/mariadb-k8s-0:/var/lib/mysql/backup.sql.gz
65 juju: juju run-action mariadb-k8s/0 restore --wait
68 completed: 2020-02-27 14:16:09 +0000 UTC
69 enqueued: 2020-02-27 14:16:08 +0000 UTC
70 started: 2020-02-27 14:16:09 +0000 UTC
71 $ kubectl cp zaza-9769f2bf245e/mariadb-k8s-0:/var/lib/mysql/backup.sql.gz backup.sql.gz
74 > Additional note: You can add `--string-args target=PRIMARY|SECONDARY` if you want this action to be run in a specific mongo unit. If `SECONDARY` is set, but the mongo unit isn't the `SECONDARY`, the action will fail.
78 When the backup function is executed, you will see the commands you need to execute for restoring from a backup.
81 $ kubectl cp backup.sql.gz zaza-9769f2bf245e/mariadb-k8s-0:/var/lib/mysql/backup.sql.gz
82 $ juju run-action mariadb-k8s/0 restore --wait
87 message: Backup restored successfully
90 completed: 2020-02-27 14:18:17 +0000 UTC
91 enqueued: 2020-02-27 14:18:07 +0000 UTC
92 started: 2020-02-27 14:18:11 +0000 UTC
97 When a backup is made, it is stored in the unit. To easily remove the backup, execute this action:
100 $ juju run-action mariadb-k8s/0 remove-backup --wait
102 UnitId: mariadb-k8s/0
106 Backup successfully removed!
109 completed: 2020-02-27 14:18:41 +0000 UTC
110 enqueued: 2020-02-27 14:18:36 +0000 UTC
111 started: 2020-02-27 14:18:41 +0000 UTC
116 If we want to perform a backup remotely, follow the next steps:
119 $ sudo apt install mariadb-client-10.1 -y
120 $ juju status mariadb-k8s
121 Model Controller Cloud/Region Version SLA Timestamp
122 zaza-9769f2bf245e microk8s-localhost microk8s/localhost 2.7.2 unsupported 15:20:42+01:00
124 App Version Status Scale Charm Store Rev OS Address Notes
125 mariadb-k8s rocks.canonical... active 2 mariadb-k8s local 0 kubernetes 10.152.183.109
127 Unit Workload Agent Address Ports Message
128 mariadb-k8s/0* active idle 10.1.31.185 3306/TCP,4444/TCP,4567/TCP,4568/TCP ready
129 mariadb-k8s/1 active idle 10.1.31.186 3306/TCP,4444/TCP,4567/TCP,4568/TCP ready
130 $ mysqldump -uroot -posm4u --single-transaction \
131 --databases database \
132 --host 10.152.183.109 \
133 --port 3306 | gzip > backup.sql.gz
134 $ gunzip -c backup.sql.gz | mysql -uroot -posm4u --host 10.152.183.109 --port 3306
137 > Note: The remote backups should be done for each database. If `--all-databases` is step, when restoring from a database, you will see this error: `ERROR 1556 (HY000) at line 825: You can't use locks with log tables`
141 The tests of this charm are done using tox and Zaza.
143 ### Prepare environment
145 The machine in which the tests are run needs access to a juju k8s controller. The easiest way to approach this is by executing the following commands:
148 sudo apt install tox -y
149 sudo snap install microk8s --classic
150 sudo snap install juju
152 microk8s.status --wait-ready
153 microk8s.enable storage dns
155 juju bootstrap microk8s k8s-cloud
158 ### Test charm with Tox
161 tox -e black # Check syntax
162 tox -e build # Build the charm
163 tox -e func # Test charm