Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewallace1979 committed Oct 17, 2023
1 parent 059516e commit efdac06
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
3 changes: 2 additions & 1 deletion barman/clients/cloud_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
configure_logging,
)
from barman.cloud_providers import get_cloud_interface, get_snapshot_interface
from barman.cloud_providers.kopia import CloudBackupKopia
from barman.exceptions import (
BarmanException,
ConfigurationException,
Expand Down Expand Up @@ -219,7 +220,7 @@ def main(args=None):
else:
if config.cloud_provider == "kopia":
uploader = CloudBackupKopia(
postgrs=postgres,
postgres=postgres,
backup_name=config.backup_name,
**uploader_kwargs,
)
Expand Down
2 changes: 1 addition & 1 deletion barman/clients/cloud_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def create_argument_parser(description, source_or_destination=UrlArgumentType.so
parser.add_argument(
"--cloud-provider",
help="The cloud provider to use as a storage backend",
choices=["aws-s3", "azure-blob-storage", "google-cloud-storage"],
choices=["aws-s3", "azure-blob-storage", "google-cloud-storage", "kopia"],
default="aws-s3",
)
s3_arguments = parser.add_argument_group(
Expand Down
102 changes: 99 additions & 3 deletions barman/cloud_providers/kopia.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
from barman.cloud import CloudInterface
from barman.cloud import CloudBackup
from barman.command_wrappers import Command


class KopiaCloudInterface(CloudInterface):
pass
class KopiaCloudInterface(object):
def __init__(self, *args, **kwargs):
pass

def test_connectivity(self):
return True

def close(self):
pass

def setup_bucket(self):
pass


class CloudBackupKopia(CloudBackup):
def __init__(
self,
server_name,
cloud_interface,
max_archive_size,
postgres,
compression=None,
backup_name=None,
**kwargs,
):
super(CloudBackupKopia, self).__init__(
server_name,
cloud_interface,
postgres,
backup_name=backup_name,
)

def _take_backup(self):
"""
Take a kopia snapshot including PGDATA and all tablespaces.
"""
# TODO add tablespaces
kopia_cmd = Kopia(
"kopia",
"snapshot",
[
"create",
self.backup_info.pgdata,
"--tags",
f"backup_id:{self.backup_info.backup_id}",
],
)
kopia_cmd()

def _upload_backup_label(self):
"""No-op because backup label gets added to a snapshot with backup.info."""
pass

def _add_stats_to_backup_info(self):
"""Maybe add some useful stuff here?"""
pass

def _finalise_copy(self):
"""Probably nothing to do here."""
pass

def _upload_backup_info(self):
"""Create a separate kopia snapshot with just the metadata."""
# Write both the backup label and backup info to a staging location
# Create a kopia snapshot of that location and tag accordingly
# TODO create a new snapshot with backup label and backup.info here

def backup(self):
"""
Upload a Backup via Kopia, probably
"""
server_name = "cloud"
self.backup_info = self._get_backup_info(server_name)

self._check_postgres_version()

self._coordinate_backup()


class Kopia(Command):
"""
Wrapper for the kopia command.
"""

def __init__(
self,
kopia="kopia",
subcommand=None,
args=None,
path=None,
):
options = []
if subcommand is not None:
options += [subcommand]
if args is not None:
options += args
super(Kopia, self).__init__(kopia, args=options, path=path)

0 comments on commit efdac06

Please sign in to comment.