weak-head / nimbus

Nimbus is engineered to optimize data backup processes and efficiently orchestrate service deployments for homelabs and dev environments.
MIT License
1 stars 0 forks source link

Add zip archival format that doesn't depend on external utilities #9

Closed weak-head closed 4 months ago

weak-head commented 4 months ago

Description

Python native zip format should be supported, so backups and uploads could work out of the box.

Example

Using zipfile library.

import zipfile
import os

def create_zip_archive(source_folder, output_zip):
    with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED) as zipf:
        for root, _, files in os.walk(source_folder):
            for file in files:
                file_path = os.path.join(root, file)
                arcname = os.path.relpath(file_path, source_folder)
                zipf.write(file_path, arcname=arcname)

# Usage
source_folder_path = '/path/to/source/folder'
output_zip_path = '/path/to/output/archive.zip'

create_zip_archive(source_folder_path, output_zip_path)
print(f"Archive created at: {output_zip_path}")