Extend backup_runner with additonal parameters
This commit is contained in:
parent
2913398564
commit
dd091041b8
|
@ -5,7 +5,7 @@ import docker
|
||||||
from restic_volume_backup.config import Config
|
from restic_volume_backup.config import Config
|
||||||
|
|
||||||
|
|
||||||
def run(image: str, command: str):
|
def run(image: str = None, command: str = None, volumes: dict = None, enviroment: dict = None):
|
||||||
config = Config()
|
config = Config()
|
||||||
client = docker.DockerClient(base_url=config.docker_base_url)
|
client = docker.DockerClient(base_url=config.docker_base_url)
|
||||||
|
|
||||||
|
@ -15,14 +15,8 @@ def run(image: str, command: str):
|
||||||
labels={"restic-volume-backup.backup_process": 'True'},
|
labels={"restic-volume-backup.backup_process": 'True'},
|
||||||
auto_remove=True,
|
auto_remove=True,
|
||||||
detach=True,
|
detach=True,
|
||||||
environment={
|
environment={},
|
||||||
'test1': 'value1',
|
volumes=volumes,
|
||||||
'test2': 'value2',
|
|
||||||
},
|
|
||||||
volumes={
|
|
||||||
'/home/user1/': {'bind': '/mnt/vol2', 'mode': 'rw'},
|
|
||||||
'/var/www': {'bind': '/mnt/vol1', 'mode': 'ro'},
|
|
||||||
},
|
|
||||||
working_dir=os.getcwd(),
|
working_dir=os.getcwd(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,9 @@ def main():
|
||||||
print()
|
print()
|
||||||
|
|
||||||
elif args.action == 'backup':
|
elif args.action == 'backup':
|
||||||
|
# Make sure we don't spawn multiple backup processes
|
||||||
if containers.backup_process_running:
|
if containers.backup_process_running:
|
||||||
raise ValueError("Backup process alredy running")
|
raise ValueError("Backup process already running")
|
||||||
|
|
||||||
print("Initializing repository")
|
print("Initializing repository")
|
||||||
|
|
||||||
|
@ -35,19 +36,22 @@ def main():
|
||||||
|
|
||||||
print("Starting backup container..")
|
print("Starting backup container..")
|
||||||
backup_runner.run(
|
backup_runner.run(
|
||||||
containers.this_container.image,
|
image=containers.this_container.image,
|
||||||
# "sleep 10",
|
command='restic-volume-backup start-backup-process',
|
||||||
'./test.sh',
|
volumes={},
|
||||||
|
enviroment={},
|
||||||
)
|
)
|
||||||
# for vol in containers.backup_volumes():
|
|
||||||
# restic.backup_volume(Config.repository, vol)
|
# Separate command to avoid spawning infinite containers :)
|
||||||
|
elif args.action == 'start-backup-process':
|
||||||
|
print("start-backup-process")
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(prog='restic_volume_backup')
|
parser = argparse.ArgumentParser(prog='restic_volume_backup')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'action',
|
'action',
|
||||||
choices=['status', 'backup'],
|
choices=['status', 'backup', 'start-backup-process'],
|
||||||
)
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue