Skip to content

Commit

Permalink
finish azure upload provider
Browse files Browse the repository at this point in the history
  • Loading branch information
rafsaf committed Aug 27, 2023
1 parent 844c53d commit a9f6901
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions backuper/upload_providers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,32 @@ def __init__(
def _post_save(self, backup_file: Path) -> str:
zip_backup_file = core.run_create_zip_archive(backup_file=backup_file)

backup_dest_in_bucket = "{}/{}".format(
backup_dest_in_azure_container = "{}/{}".format(
zip_backup_file.parent.name,
zip_backup_file.name,
)
blob_client = self.blob_service_client.get_blob_client(
container=self.container_name, blob=backup_dest_in_bucket
container=self.container_name, blob=backup_dest_in_azure_container
)

log.info("start uploading %s to %s", zip_backup_file, backup_dest_in_bucket)
log.info(
"start uploading %s to %s", zip_backup_file, backup_dest_in_azure_container
)

with open(file=zip_backup_file, mode="rb") as data:
blob_client.upload_blob(data=data)

log.info(
"uploaded %s to %s in %s",
zip_backup_file,
backup_dest_in_bucket,
backup_dest_in_azure_container,
self.container_name,
)
return backup_dest_in_bucket
return backup_dest_in_azure_container

def _clean(self, backup_file: Path, max_backups: int) -> None:
def _clean(
self, backup_file: Path, max_backups: int, min_retention_days: int
) -> None:
for backup_path in backup_file.parent.iterdir():
core.remove_path(backup_path)
log.info("removed %s from local disk", backup_path)
Expand All @@ -72,5 +76,17 @@ def _clean(self, backup_file: Path, max_backups: int) -> None:

while len(backup_list_cloud) > max_backups:
backup_to_remove = backup_list_cloud.pop()
file_name = backup_to_remove.split("/")[-1]
if core.file_before_retention_period_ends(
backup_name=file_name, min_retention_days=min_retention_days
):
log.info(
"there are more backups than max_backups (%s/%s), "
"but oldest cannot be removed due to min retention days",
len(backup_list_cloud),
max_backups,
)
break

self.container_client.delete_blob(blob=backup_to_remove)
log.info("deleted backup %s from azure blob storage", backup_to_remove)

0 comments on commit a9f6901

Please sign in to comment.