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 -->
29 Execute the following steps to do a backup.
32 $ juju run-action mongodb-k8s/0 backup --wait
37 Stderr: "2020-02-26T14:13:56.448+0000\twriting admin.system.version to archive
38 '/data/backup.archive'\n2020-02-26T14:13:56.451+0000\tdone dumping admin.system.version
41 cmd: kubectl cp mongo-ha/mongodb-k8s-0:/data/backup.archive backup.archive
43 cmd: kubectl cp backup.archive mongo-ha/mongodb-k8s-0:/data/backup.archive
44 juju: juju action mongodb-k8s/0 restore --wait
47 completed: 2020-02-26 14:13:57 +0000 UTC
48 enqueued: 2020-02-26 14:13:55 +0000 UTC
49 started: 2020-02-26 14:13:56 +0000 UTC
50 $ kubectl cp mongo-ha/mongodb-k8s-0:/data/backup.archive backup.archive
53 > 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.
57 When the backup function is executed, you will see the commands you need to execute for restoring from a backup.
60 $ kubectl cp backup.archive mongo-ha/mongodb-k8s-0:/data/backup.archive
61 Defaulting container name to mongodb-k8s.
62 $ juju run-action mongodb-k8s/0 restore --wait
67 Stderr: "2020-02-26T14:17:00.300+0000\tpreparing collections to restore from\n2020-02-26T14:17:00.312+0000\t0
68 document(s) restored successfully. 0 document(s) failed to restore.\n"
71 completed: 2020-02-26 14:17:01 +0000 UTC
72 enqueued: 2020-02-26 14:16:57 +0000 UTC
73 started: 2020-02-26 14:17:00 +0000 UTC
78 When a backup is made, it is stored in the unit. To easily remove the backup, execute this action:
81 $ juju run-action mongodb-k8s/0 remove-backup --wait
87 Backup successfully removed!
90 completed: 2020-02-26 16:31:11 +0000 UTC
91 enqueued: 2020-02-26 16:31:08 +0000 UTC
92 started: 2020-02-26 16:31:10 +0000 UTC
97 To check if the unit is primary:
100 $ juju run-action mongodb-k8s/0 is-primary --wait
102 UnitId: mongodb-k8s/0
110 completed: 2020-02-26 16:32:10 +0000 UTC
111 enqueued: 2020-02-26 16:32:08 +0000 UTC
112 started: 2020-02-26 16:32:09 +0000 UTC
113 $ juju run-action mongodb-k8s/1 is-primary --wait
115 UnitId: mongodb-k8s/1
123 completed: 2020-02-26 16:32:34 +0000 UTC
124 enqueued: 2020-02-26 16:32:32 +0000 UTC
125 started: 2020-02-26 16:32:33 +0000 UTC
130 If we want to perform a backup remotely, follow the next steps:
133 $ sudo apt install mongo-tools-y
134 $ juju status mongodb-k8s
135 Model Controller Cloud/Region Version SLA Timestamp
136 mongo-ha microk8s-localhost microk8s/localhost 2.7.2 unsupported 16:26:02+01:00
138 App Version Status Scale Charm Store Rev OS Address Notes
139 mongodb-k8s mongo:latest active 2 mongodb-k8s local 0 kubernetes 10.152.183.90
141 Unit Workload Agent Address Ports Message
142 mongodb-k8s/0* active idle 10.1.31.75 27017/TCP ready
143 mongodb-k8s/1 active idle 10.1.31.76 27017/TCP ready
144 $ mongodump --host 10.152.183.90 --port 27017 --gzip --archive=backup.archive --forceTableScan
145 2020-02-26T16:41:23.777+0100 writing admin.system.version to archive 'backup.archive'
146 2020-02-26T16:41:23.779+0100 done dumping admin.system.version (1 document)
147 $ mongorestore --host 10.152.183.90 --port 27017 --gzip --archive=backup.archive
152 The tests of this charm are done using tox and Zaza.
154 ### Prepare environment
156 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:
159 sudo apt install tox -y
160 sudo snap install microk8s --classic
161 sudo snap install juju
163 microk8s.status --wait-ready
164 microk8s.enable storage dashboard dns
166 juju bootstrap microk8s k8s-cloud
169 ### Test charm with Tox
172 tox -e black # Check syntax
173 tox -e build # Build the charm
174 tox -e func # Test charm