Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
fix: Use backup-maker and tracexit always from GitHub releases
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Jan 20, 2022
1 parent b8b9780 commit b76e746
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/.venv
.venv-setup.log
.idea
/.build
6 changes: 3 additions & 3 deletions .rkd/makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def release_docker(ctx: ExecutionContext, task: TaskInterface) -> bool:
Pipeline(':test:dev:create', [':sh', '-c', '''
docker run --name nginx_bahub_test -d nginx:1.19 || true;
export TEST_COLLECTION_ID=$(cat ../backup-maker/.build/test/collection-id.txt);
export SERVER_URL=$(cat ../backup-maker/.build/test/domain.txt);
export API_TOKEN=$(cat ../backup-maker/.build/test/collection-id.txt);
export TEST_COLLECTION_ID=$(cat .build/test/collection-id.txt);
export SERVER_URL=$(cat .build/test/domain.txt);
export API_TOKEN=$(cat .build/test/collection-id.txt);
RKD_SYS_LOG_LEVEL=debug python -m bahub :backup:make -c ./bahub.conf.yaml fs_kubernetes_pod -rl debug
''']),

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Backup Controller
=================

WIP: Note this project is a work in progress

![](docs/backup-controller.svg)

Backups made easy, automated, monitored and SECURED with an audited encryption.
Expand Down
7 changes: 1 addition & 6 deletions bahub/adapters/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,4 @@ def create_definition(config: dict, name: str) -> Definition:
return BackupDefinition.from_config(Definition, config, name)

def get_required_binaries(self) -> List[RequiredBinary]:
from ..bin import RequiredBinaryFromGithubRelease # todo: remove (testing only)

return [
# todo: remove (testing only)
RequiredBinaryFromGithubRelease("riotkit-org/gpbkdf2", "v1.0", "gpbkdf2")
]
return []
26 changes: 21 additions & 5 deletions bahub/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tempfile import TemporaryFile, NamedTemporaryFile
from rkd.api.inputoutput import IO
from bahub.fs import FilesystemInterface
from bahub.versions import BACKUP_MAKER_BIN_VERSION, TRACEXIT_BIN_VERSION


class RequiredBinary(object):
Expand Down Expand Up @@ -114,9 +115,9 @@ def download_required_tools(fs: FilesystemInterface, io: IO, bin_path: str,
fs.make_executable(version_path)


def fetch_required_tools_from_cache(local_cache_fs: FilesystemInterface, dst_fs: FilesystemInterface, io: IO,
bin_path: str, versions_path: str, local_versions_path: str,
binaries: List[RequiredBinary]):
def copy_required_tools_from_controller_cache_to_target_env(local_cache_fs: FilesystemInterface, dst_fs: FilesystemInterface, io: IO,
bin_path: str, versions_path: str, local_versions_path: str,
binaries: List[RequiredBinary]):
"""
Pack selected binaries from local cache, send them to remote filesystem and unpack
Expand Down Expand Up @@ -165,8 +166,23 @@ def fetch_required_tools_from_cache(local_cache_fs: FilesystemInterface, dst_fs:
io.debug(f"Linking version {version_path} into {bin_path}")
dst_fs.delete_file(bin_path)
dst_fs.link(version_path, bin_path)
dst_fs.make_executable(bin_path)
dst_fs.make_executable(version_path)


def get_backup_maker_binaries() -> List[RequiredBinary]:
return []
return [
RequiredBinaryFromGithubReleasePackedInArchive(
project_name="riotkit-org/br-backup-maker",
version=BACKUP_MAKER_BIN_VERSION,
binary_name="br-backup-maker",
# todo: support for multiple architectures
archive_name="br-backup-maker_0.0.4_linux_amd64.tar.gz"
),
RequiredBinaryFromGithubReleasePackedInArchive(
project_name="riotkit-org/tracexit",
version=TRACEXIT_BIN_VERSION,
binary_name="tracexit",
# todo: support for multiple architectures
archive_name=f"tracexit_{TRACEXIT_BIN_VERSION}_linux_amd64.tar.gz"
)
]
10 changes: 8 additions & 2 deletions bahub/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@


def create_backup_maker_command(command: str, definition, is_backup: bool,
version: str = "", prepend: list = None) -> List[str]:
version: str = "", prepend: list = None, bin_path: str = '') -> List[str]:
args = [
"/usr/bin/env"
]

if bin_path:
args += [
bin_path + "/tracexit", f"env:PATH+BIN={bin_path}"
]

if prepend:
args += prepend

args += [
"backup-maker", "make" if is_backup else "restore",
"br-backup-maker",
"make" if is_backup else "restore",
"--url", definition.access().url,
"--collection-id", definition.get_collection_id(),
"--auth-token", definition.access().token,
Expand Down
4 changes: 2 additions & 2 deletions bahub/transports/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from rkd.api.inputoutput import IO
from .base import TransportInterface, create_backup_maker_command
from .sh import LocalFilesystem
from ..bin import RequiredBinary, fetch_required_tools_from_cache
from ..bin import RequiredBinary, copy_required_tools_from_controller_cache_to_target_env
from ..fs import FilesystemInterface
from ..settings import TARGET_ENV_BIN_PATH, TARGET_ENV_VERSIONS_PATH

Expand Down Expand Up @@ -149,7 +149,7 @@ def schedule(self, command: str, definition, is_backup: bool, version: str = "")
new_path = self.discover_path_variable_in_container() + ":" + self.bin_path
self.io().debug(f"Setting $PATH={new_path}")

fetch_required_tools_from_cache(
copy_required_tools_from_controller_cache_to_target_env(
local_cache_fs=LocalFilesystem(),
dst_fs=self.fs,
io=self.io(),
Expand Down
4 changes: 2 additions & 2 deletions bahub/transports/kubernetespodexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from kubernetes.stream.ws_client import WSClient, ERROR_CHANNEL
from rkd.api.inputoutput import IO

from bahub.bin import RequiredBinary, fetch_required_tools_from_cache, RequiredBinaryFromGithubReleasePackedInArchive
from bahub.bin import RequiredBinary, copy_required_tools_from_controller_cache_to_target_env, RequiredBinaryFromGithubReleasePackedInArchive
from bahub.settings import BIN_VERSION_CACHE_PATH, TARGET_ENV_BIN_PATH, TARGET_ENV_VERSIONS_PATH
from bahub.transports.base import TransportInterface, create_backup_maker_command
from bahub.transports.kubernetes import KubernetesPodFilesystem
Expand Down Expand Up @@ -71,7 +71,7 @@ def schedule(self, command: str, definition, is_backup: bool, version: str = "")
pod_name = self.find_pod_name()
self.wait_for_pod_to_be_ready(pod_name, self._namespace)

fetch_required_tools_from_cache(
copy_required_tools_from_controller_cache_to_target_env(
local_cache_fs=LocalFilesystem(),
dst_fs=KubernetesPodFilesystem(pod_name, self._namespace, self.io()),
io=self.io(),
Expand Down
4 changes: 2 additions & 2 deletions bahub/transports/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from rkd.api.inputoutput import IO

from .base import TransportInterface, create_backup_maker_command
from ..bin import RequiredBinary, download_required_tools, fetch_required_tools_from_cache
from ..bin import RequiredBinary, download_required_tools, copy_required_tools_from_controller_cache_to_target_env
from ..fs import FilesystemInterface
from ..inputoutput import StreamableBuffer
from ..model import BackupDefinition
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(self, spec: dict, io: IO):
self.fs = LocalFilesystem()

def prepare_environment(self, binaries: List[RequiredBinary]) -> None:
fetch_required_tools_from_cache(
copy_required_tools_from_controller_cache_to_target_env(
local_cache_fs=LocalFilesystem(),
dst_fs=self.fs,
io=self.io(),
Expand Down
3 changes: 2 additions & 1 deletion bahub/versions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
POSTGRES_HELPER_BIN_VERSION = "1.0.0"
BACKUP_MAKER_BIN_VERSION = "0.0.4"
POSTGRES_HELPER_BIN_VERSION = "0.0.1"
TRACEXIT_BIN_VERSION = "1.0.0"

0 comments on commit b76e746

Please sign in to comment.