Commit 5fc240f6 authored by dobli's avatar dobli
Browse files

use individual backup configs

parent fdd08177
...@@ -58,7 +58,7 @@ EDIT_FILES = { ...@@ -58,7 +58,7 @@ EDIT_FILES = {
"id_rsa": "ssh/id_rsa", "id_rsa": "ssh/id_rsa",
"host_key": "ssh/ssh_host_ed25519_key", "host_key": "ssh/ssh_host_ed25519_key",
"known_hosts": "ssh/known_hosts", "known_hosts": "ssh/known_hosts",
"backup_config": "volumerize/backup_config.json", "backup_config": "volumerize/backup_config",
"postgres_user": "postgres/user", "postgres_user": "postgres/user",
"postgres_passwd": "postgres/passwd", "postgres_passwd": "postgres/passwd",
"pb_framr_pages": "pb-framr/pages.json", "pb_framr_pages": "pb-framr/pages.json",
...@@ -333,6 +333,14 @@ def add_volumerize_service(base_dir, hostname): ...@@ -333,6 +333,14 @@ def add_volumerize_service(base_dir, hostname):
template['volumes'].extend(get_attachable_volume_list( template['volumes'].extend(get_attachable_volume_list(
base_dir, volume_base, hostname)) base_dir, volume_base, hostname))
# adjust config
config_list = template['configs']
# get backup entry from configs
index, entry = next((i, c) for i, c in enumerate(config_list)
if c['source'] == 'backup_config')
entry['source'] = f'backup_config_{hostname}'
template['configs'][index] = entry
add_or_update_compose_service(compose_path, service_name, template) add_or_update_compose_service(compose_path, service_name, template)
...@@ -618,6 +626,26 @@ def add_volume_entry(compose_path, volume_name): ...@@ -618,6 +626,26 @@ def add_volume_entry(compose_path, volume_name):
yaml.dump(compose, compose_f) yaml.dump(compose, compose_f)
# reduce file to new size # reduce file to new size
compose_f.truncate() compose_f.truncate()
def add_config_entry(compose_path, config_name, config_path):
"""Creates an additional config entry in the stack file or updates it
:compose_path: path of the compose file to change
:config_name: name of the additional config
:config_path: path of the additional config
"""
with open(compose_path, 'r+') as compose_f:
# load compose file
compose = yaml.load(compose_f)
# add config
compose['configs'][config_name] = {"file": config_path}
# write content starting from first line
compose_f.seek(0)
# write new compose content
yaml.dump(compose, compose_f)
# reduce file to new size
compose_f.truncate()
# >>> # >>>
...@@ -859,24 +887,30 @@ def generate_traefik_file(base_dir, username, password): ...@@ -859,24 +887,30 @@ def generate_traefik_file(base_dir, username, password):
file_content) file_content)
def generate_volumerize_file(base_dir, hosts): def generate_volumerize_files(base_dir, hosts):
"""Generates config for volumerize backups """Generates config for volumerize backups
:base_dir: path that contains custom config folder :base_dir: path that contains custom config folder
:hosts: names of backup hosts :hosts: names of backup hosts
""" """
configs = [] compose_path = base_dir + '/' + CUSTOM_DIR + "/" + COMPOSE_NAME
# create one config per host
for h in hosts: for h in hosts:
host_config = { configs = []
'description': f'Backup Server on {h}', # Each host knows other hosts
'url': f'sftp://ohadmin@sftp_{h}:' for t in hosts:
f'//home/ohadmin/backup_data/backup/{h}' host_config = {
} 'description': f'Backup Server on {t}',
configs.append(host_config) 'url': f'sftp://ohadmin@sftp_{t}:'
f'//home/ohadmin/backup_data/backup/{h}'
create_or_replace_config_file( }
base_dir, EDIT_FILES['backup_config'], configs, json=True) configs.append(host_config)
config_file = f"{EDIT_FILES['backup_config']}_{h}.json"
create_or_replace_config_file(
base_dir, config_file, configs, json=True)
add_config_entry(
compose_path, f'backup_config_{h}', f"./{config_file}")
def generate_pb_framr_file(base_dir, frames): def generate_pb_framr_file(base_dir, frames):
...@@ -1448,7 +1482,7 @@ def init_menu(args): ...@@ -1448,7 +1482,7 @@ def init_menu(args):
generate_postgres_files(base_dir, username, password) generate_postgres_files(base_dir, username, password)
generate_mosquitto_file(base_dir, username, password) generate_mosquitto_file(base_dir, username, password)
generate_traefik_file(base_dir, username, password) generate_traefik_file(base_dir, username, password)
generate_volumerize_file(base_dir, hosts) generate_volumerize_files(base_dir, hosts)
generate_filebrowser_file(base_dir, username, password) generate_filebrowser_file(base_dir, username, password)
generate_id_rsa_files(base_dir) generate_id_rsa_files(base_dir)
generate_host_key_files(base_dir, hosts) generate_host_key_files(base_dir, hosts)
......
...@@ -7,8 +7,6 @@ networks: ...@@ -7,8 +7,6 @@ networks:
attachable: true attachable: true
configs: configs:
backup_config:
file: ./volumerize/backup_config.json
sftp_config: sftp_config:
file: ./ssh/sshd_config file: ./ssh/sshd_config
sftp_users: sftp_users:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment