Skip to content

Commit

Permalink
feat: add hostname to backup filename for a unique filename
Browse files Browse the repository at this point in the history
  • Loading branch information
qaldak committed Nov 20, 2023
1 parent 50c589a commit e9201bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/container/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from python_on_whales import docker, DockerException

from util.accessor import LocalHost

logger = logging.getLogger(__name__)


Expand All @@ -13,7 +15,7 @@ def create_tar_cmd(container) -> list[str]:
:return: tar command to execute
"""

tar_cmd = ["tar", "-czf", f"/backup/{container.name}_volume_backup.tar.gz"]
tar_cmd = ["tar", "-czf", f"/backup/{LocalHost.get_hostname()}_{container.name}_volume_backup.tar.gz"]

for volume in container.docker_volumes:
tar_cmd.append(f"{volume}")
Expand Down
6 changes: 4 additions & 2 deletions tests/container/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_run_backup_successful(self, tmp):
self.assertEqual(["INFO:container.backup:Volume backup for container 'foo_bar' successful"], log.output)


def test_create_tar_cmd():
@patch("src.container.backup.LocalHost.get_hostname", return_value="groot")
def test_create_tar_cmd(host):
container = MockContainer()
tar_cmd = create_tar_cmd(container)
assert ["tar", "-czf", f"/backup/foo_bar_volume_backup.tar.gz", "/foo/data", "/foo/config", "/bar/log"] == tar_cmd
assert ["tar", "-czf", f"/backup/groot_foo_bar_volume_backup.tar.gz", "/foo/data", "/foo/config",
"/bar/log"] == tar_cmd

0 comments on commit e9201bf

Please sign in to comment.