How to uploade the .gzip file to Swift Object Store?

Featured Imgs 23

I wrote the Python code to upload the .gz file from my local machine to the OpenStack object store using the following documentation: https://docs.openstack.org/python-swiftclient/latest/client-api.html.
Below is the code I wrote.

from keystoneauth1 import session
    from keystoneauth1.identity import v3
    from swiftclient.client import Connection, logger
    from swiftclient.client import ClientException
    import gzip

    # Create a password auth plugin
    auth = v3.Password(
        auth_url='https://cloud.company.com:5000/v3/',
        username='myaccount',
        password='mypassword',
        user_domain_name='Default',
        project_name='myproject',
        project_domain_name='Default'
    )

    # Create swiftclient Connection
    swift_conn = Connection(session=keystone_session)

    # Create a new container
    container = 'object-backups'
    swift_conn.put_container(container)
    res_headers, containers = swift_conn.get_account()
    if container in containers:
        print("The container " + container + " was created!")

    # Create a new object with the contents of Netbox database backup
    with gzip.open('/var/backup/netbox_backups/netbox_2024-03-16.psql.gz', 'rb') as f:
        # Read the contents...
        file_gz_content = f.read()

        # Upload the returned contents to the Swift Object Storage container
        swift_conn.put_object(
            container,
            "object_netbox_2024-06-16.psql.gz",
            contents=file_gz_content,
            content_type='application/gzip'
        )

    # Confirm the presence of the object holding the Netbox database backup
    obj1 = 'object_netbox_2024-06-16.psql.gz'
    container = 'object-backups'
    try:
        resp_headers = swift_conn.head_object(container, obj1)
        print("The object " + obj1 + " was successfully created")
    except ClientException as e:
        if e.http_status == '404':
            print("The object " + obj1 + " was not found!")
        else:
            print("An error occurred checking for the existence of the object " + obj1)

The file gets uploaded successfully. However, if I download the file from the object store and try to decompress it, I get the following error:

# gzip -d object_netbox_2024-06-16.psql.gz 

gzip: sanbox_nb01_netbox_2024-06-16.psql.gz: not in gzip format

What should I do to ensure the file gets downloaded in the same format and size to the Object storage as the file in my local machine?

Any assistance will be appreciated.

Yours sincerely

This Is How SSL Certificates Work: HTTPS Explained in 15 Minutes

Featured Imgs 23

The world of online security may seem complex, but understanding the basics of how SSL certificates work and why HTTPS is essential can empower you to make safer choices online. Just like Jane, you can navigate the digital landscape with confidence, knowing that your data is protected from prying eyes. So next time you browse the web, remember the story of Jane and the coffee shop hacker and choose secure, trusted websites for your online activities. Let’s start our day with Jane who was enjoying her coffee peacefully.

Chapter 1: The Coffee Shop Conundrum

It was a sunny afternoon, and Jane decided to take a break from her hectic day. She headed to her favorite coffee shop, ordered a latte, and found a cozy corner to catch up on some online shopping and emails. As she settled in, she connected her laptop to the coffee shop’s free Wi-Fi and began browsing. Little did she know, a hacker named Bob was sitting just a few tables away, eager to intercept her data.