You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

75 lines
1.6 KiB

#!/bin/python3
"""
Automated backup script.
"""
import argparse
from pathlib import Path
import os
from typing import (
Callable,
List
)
import yaml
from backup.server import Server, load_server_from_file
from backup.repo import Repo, load_repo_from_file
#############
# Arguments #
#############
parser = argparse.ArgumentParser(description="Automated backup script")
parser.add_argument('--config_dir',
metavar="DIR",
default="./conf",
help="Directory for configuration files")
args = parser.parse_args()
#############
# Functions #
#############
def list_yml_files_in_dir( directory: Path ) -> List[str]:
"""
Lists the YAML files in a given directory.
"""
files: List[str] = []
with os.scandir( directory ) as iterator:
for entry in iterator:
if not entry.is_file():
continue
if entry.name.startswith('.'):
continue
if not entry.name.endswith('.yml'):
continue
files.append(entry.path)
return files
##########
# Script #
##########
config_dir = Path(args.config_dir)
# load servers
server_dir = config_dir / "servers"
servers: List[Server] = []
for server_file in list_yml_files_in_dir( server_dir ):
servers.append( load_server_from_file( server_file ) )
# load repos
repos_dir = config_dir / "backups"
repos: List[Repo] = []
for repo_file in list_yml_files_in_dir( repos_dir ):
repos.append( load_repo_from_file( repo_file ) )
# init backups
for server in servers:
for repo in repos:
repo.init_or_config( server )
print(repo.backup( server ))