Skip to content

Commit 870ca1d

Browse files
authored
Merge pull request #19 from lawndoc/add-tests #none
chore: update tests and documentation
2 parents 353be28 + ec55ecb commit 870ca1d

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

docs/guide/configuration.rst

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ connecting to the Docker host. Combined with ``DOCKER_TLS_VERIFY``
188188
this can be used to talk to docker through TLS in cases
189189
were we cannot map in the docker socket.
190190

191+
INCLUDE_ALL_VOLUMES
192+
~~~~~~~~~~~~~~~~~~~
193+
194+
If defined, all volumes will be included in the backup.
195+
This is useful when you want to back up all volumes
196+
in a project without having to add labels to each service.
197+
198+
Volumes can be excluded by adding the ``stack-back.volumes.exclude``
199+
label to the service.
200+
191201
INCLUDE_PROJECT_NAME
192202
~~~~~~~~~~~~~~~~~~~~
193203

@@ -272,6 +282,30 @@ Their path in restic will be:
272282
- /volumes/myservice/srv/files
273283
- /volumes/myservice/srv/data
274284

285+
In situations where the files in the volume are at risk of being
286+
corrupted during the backup process (such as SQLite databases),
287+
the `stack-back.volumes.stop-during-backup` label can be added to
288+
the service. This will stop the service during the backup process
289+
and start it again when the backup is done.
290+
291+
Example:
292+
293+
.. code:: yaml
294+
295+
myservice:
296+
image: some_image
297+
labels:
298+
stack-back.volumes: true
299+
stack-back.volumes.stop-during-backup: true
300+
volumes:
301+
- uploaded_media:/srv/media
302+
- uploaded_files:/srv/files
303+
- /srv/data:/srv/data
304+
305+
volumes:
306+
media:
307+
files:
308+
275309
A simple `include` and `exclude` filter for what volumes
276310
should be backed up is also available. Note that this
277311
includes or excludes entire volumes and are not include/exclude
@@ -333,16 +367,16 @@ when using the official mariadb_ image.
333367

334368
.. code::
335369
336-
MYSQL_USER
337-
MYSQL_PASSWORD
370+
MARIADB_USER
371+
MARIADB_PASSWORD
338372
339373
Backups are done by dumping all databases directly into
340374
restic through stdin using ``mysqldump``. It will appear
341375
in restic as a separate snapshot with path
342376
``/databases/<service_name>/all_databases.sql``.
343377

344378
.. warning: This will only back up the databases the
345-
``MYSQL_USER` has access to. If you have multiple
379+
``MARIADB_USER` has access to. If you have multiple
346380
databases this must be taken into consideration.
347381
348382
Example:

src/tests/tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,46 @@ def test_basic_functionality(self):
245245
self.assertEqual(len(mounts), 2)
246246
self.assertEqual(mounts[0].source, "/srv/files/media")
247247
self.assertEqual(mounts[1].source, "/srv/files/stuff")
248+
249+
def test_redundant_label(self):
250+
"""Test that a container has a redundant label and should be backed up"""
251+
252+
containers = self.createContainers()
253+
containers += [
254+
{
255+
"service": "web",
256+
"labels": {
257+
"stack-back.volumes": True,
258+
},
259+
"mounts": [
260+
{
261+
"Source": "/srv/files/media",
262+
"Destination": "/srv/media",
263+
"Type": "bind",
264+
},
265+
{
266+
"Source": "/srv/files/stuff",
267+
"Destination": "/srv/stuff",
268+
"Type": "bind",
269+
},
270+
],
271+
},
272+
]
273+
with mock.patch(
274+
list_containers_func, fixtures.containers(containers=containers)
275+
):
276+
cnt = RunningContainers()
277+
278+
web_service = cnt.get_service("web")
279+
self.assertNotEqual(web_service, None, msg="Web service not found")
280+
281+
mounts = web_service.filter_mounts()
282+
print(mounts)
283+
self.assertEqual(len(mounts), 2)
284+
self.assertEqual(mounts[0].source, "/srv/files/media")
285+
self.assertEqual(mounts[1].source, "/srv/files/stuff")
286+
287+
248288

249289
def test_explicit_exclude(self):
250290
"""Test that a container can be excluded from the backup"""

0 commit comments

Comments
 (0)