-
Notifications
You must be signed in to change notification settings - Fork 8
Podman support and option to backup across all projects #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8e07295
5086395
f29307a
c95caf6
d6f00d3
6ce96af
5823127
f59f7b5
f53acc6
2da8dca
c504b3e
164fda0
36ec179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -138,7 +138,7 @@ def status(config, containers): | |||||||
logger.info("-" * 67) | ||||||||
|
||||||||
|
||||||||
def backup(config, containers): | ||||||||
def backup(config, containers: RunningContainers): | ||||||||
"""Request a backup to start""" | ||||||||
# Make sure we don't spawn multiple backup processes | ||||||||
if containers.backup_process_running: | ||||||||
|
@@ -169,7 +169,7 @@ def backup(config, containers): | |||||||
command="rcb start-backup-process", | ||||||||
volumes=volumes, | ||||||||
environment=containers.this_container.environment, | ||||||||
source_container_id=containers.this_container.id, | ||||||||
source_container_network=containers.this_container.network_name, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll have to pass the
Suggested change
|
||||||||
labels={ | ||||||||
containers.backup_process_label: "True", | ||||||||
"com.docker.compose.project": containers.project_name, | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||||||||||||||||||||
import os | ||||||||||||||||||||||||
import logging | ||||||||||||||||||||||||
from pathlib import Path | ||||||||||||||||||||||||
import socket | ||||||||||||||||||||||||
from typing import List | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
from restic_compose_backup import enums, utils | ||||||||||||||||||||||||
|
@@ -57,9 +57,22 @@ def id(self) -> str: | |||||||||||||||||||||||
return self._data.get("Id") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
@property | ||||||||||||||||||||||||
def hostname(self) -> str: | ||||||||||||||||||||||||
"""Hostname of the container""" | ||||||||||||||||||||||||
return self.get_config("Hostname", default=self.id[0:12]) | ||||||||||||||||||||||||
def network_details(self) -> dict: | ||||||||||||||||||||||||
"""dict: The network details of the container""" | ||||||||||||||||||||||||
network_settings: dict = self._data.get("NetworkSettings", {}) | ||||||||||||||||||||||||
networks: dict = network_settings.get("Networks", {}) | ||||||||||||||||||||||||
first_network = list(networks.values())[0] | ||||||||||||||||||||||||
return first_network | ||||||||||||||||||||||||
Comment on lines
+60
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to return the full list of
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
@property | ||||||||||||||||||||||||
def network_name(self) -> str: | ||||||||||||||||||||||||
"""str: The name of the network the container is connected to""" | ||||||||||||||||||||||||
return self.network_details.get("NetworkID", "") | ||||||||||||||||||||||||
Comment on lines
+67
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still needed for the initial network creation, but you will need to adapt this to select the first network within this function since
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
@property | ||||||||||||||||||||||||
def ip_address(self) -> str: | ||||||||||||||||||||||||
"""str: IP address of the container""" | ||||||||||||||||||||||||
return self.network_details.get("IPAddress", "") | ||||||||||||||||||||||||
Comment on lines
+72
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can adapt this to select the first network within this function since
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
@property | ||||||||||||||||||||||||
def image(self) -> str: | ||||||||||||||||||||||||
|
@@ -407,13 +420,13 @@ def __init__(self): | |||||||||||||||||||||||
# Find the container we are running in. | ||||||||||||||||||||||||
# If we don't have this information we cannot continue | ||||||||||||||||||||||||
for container_data in all_containers: | ||||||||||||||||||||||||
if container_data.get("Id").startswith(os.environ["HOSTNAME"]): | ||||||||||||||||||||||||
if container_data.get("Id").startswith(socket.gethostname()): | ||||||||||||||||||||||||
self.this_container = Container(container_data) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if not self.this_container: | ||||||||||||||||||||||||
raise ValueError("Cannot find metadata for backup container") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# Gather all running containers in the current compose setup | ||||||||||||||||||||||||
# Gather relevant containers | ||||||||||||||||||||||||
for container_data in all_containers: | ||||||||||||||||||||||||
container = Container(container_data) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
@@ -429,25 +442,22 @@ def __init__(self): | |||||||||||||||||||||||
if not container.is_running: | ||||||||||||||||||||||||
continue | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# If not swarm mode we need to filter in compose project | ||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||
not config.swarm_mode | ||||||||||||||||||||||||
and not config.include_all_compose_projects | ||||||||||||||||||||||||
and container.project_name != self.this_container.project_name | ||||||||||||||||||||||||
): | ||||||||||||||||||||||||
continue | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# Gather stop during backup containers | ||||||||||||||||||||||||
if container.stop_during_backup: | ||||||||||||||||||||||||
if config.swarm_mode: | ||||||||||||||||||||||||
self.stop_during_backup_containers.append(container) | ||||||||||||||||||||||||
else: | ||||||||||||||||||||||||
if container.project_name == self.this_container.project_name: | ||||||||||||||||||||||||
self.stop_during_backup_containers.append(container) | ||||||||||||||||||||||||
self.stop_during_backup_containers.append(container) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# Detect running backup process container | ||||||||||||||||||||||||
if container.is_backup_process_container: | ||||||||||||||||||||||||
self.backup_process_container = container | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# --- Determine what containers should be evaluated | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# If not swarm mode we need to filter in compose project | ||||||||||||||||||||||||
if not config.swarm_mode: | ||||||||||||||||||||||||
if container.project_name != self.this_container.project_name: | ||||||||||||||||||||||||
continue | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# Containers started manually are not included | ||||||||||||||||||||||||
if container.is_oneoff: | ||||||||||||||||||||||||
continue | ||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to pass in the list of networks for the runner to be attached to so it can reach all the containers it is backing up.