Skip to main content

CLI tool to archive a Google Drive folder and replace it with the archive. Helps to free up Google Drive storage space by compressing rarely accessed folders while keeping them accessible.

Project description

gdarch

CI codecov PyPI Downloads

A CLI tool to archive Google Drive folders and replace them with compressed archives.

Motivation

Google Drive storage space is often filled with large folders that are rarely accessed but need to be kept for reference or backup purposes. This tool helps you free up storage space by:

  1. Automatically compressing such folders into high-compression archives
  2. Replacing the original folders with their compressed versions
  3. Maintaining the same folder structure and accessibility

This way, you can keep your important data while significantly reducing storage usage.

Features

  • Recursively downloads all files from a specified Google Drive folder
  • Creates a high-compression tar.xz archive (LZMA2, preset 9 + EXTREME)
  • Automatically sizes the LZMA dictionary to the archive so redundancy across files can be exploited for the best possible compression ratio
  • Groups similar files together to further improve solid compression
  • Uploads the archive to the parent folder
  • Optionally deletes the original folder

Installation

From PyPI

pip install gdarch

From Source

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Clone and install
git clone https://github.com/taross-f/gdarch.git
cd gdarch
poetry install

Usage

  1. Get OAuth2 credentials from Google Cloud Console:

    • Visit Google Cloud Console
    • Create or select a project
    • Go to APIs & Services > Credentials
    • Create an OAuth 2.0 Client ID
    • Download the credentials and save as credentials.json
  2. Run the command:

# When installed from PyPI
gdarch --folder-id <TARGET_FOLDER_ID> --credentials credentials.json

# When installed from source (using Poetry)
poetry run gdarch --folder-id <TARGET_FOLDER_ID> --credentials credentials.json

# Archive and delete the original folder
gdarch --folder-id <TARGET_FOLDER_ID> --credentials credentials.json --delete-folder

# Specify a custom archive name
gdarch --folder-id <TARGET_FOLDER_ID> --archive-name my_archive.tar.xz --credentials credentials.json

# Push the compression ratio even higher with a larger LZMA dictionary (more RAM)
gdarch --folder-id <TARGET_FOLDER_ID> --credentials credentials.json --max-dict-size-mib 768

Options

  • --folder-id: Google Drive folder ID to archive (required)
  • --credentials: Path to OAuth2 credentials file (defaults to credentials.json)
  • --archive-name: Name for the uploaded archive file (optional)
  • --delete-folder: Delete the original folder after archiving (flag)
  • --max-dict-size-mib: Maximum LZMA dictionary size in MiB (default: 256). The dictionary is automatically grown to cover the whole archive (up to this cap), letting LZMA find matches across files in the solid stream for a better compression ratio. Larger values can squeeze big folders further but use more memory while compressing (~10.5x the dictionary size).

Finding Folder ID

The folder ID is the last part of the Google Drive folder URL:

https://drive.google.com/drive/folders/1234567890abcdef
                                      ^^^^^^^^^^^^^^^^
                                      This is your folder ID

Development

# Install dependencies
poetry install

# Run tests
poetry run pytest

# Format code
poetry run black .
poetry run isort .

How It Works

  1. Authenticates with Google Drive using OAuth2
  2. Recursively lists all files in the specified folder
  3. Downloads files while streaming them directly into a tar.xz archive
  4. Uploads the compressed archive to the parent folder
  5. Optionally deletes the original folder
  6. Cleans up temporary files

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gdarch-0.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gdarch-0.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file gdarch-0.2.0.tar.gz.

File metadata

  • Download URL: gdarch-0.2.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.20 Linux/6.17.0-1018-azure

File hashes

Hashes for gdarch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ebe2b6d822c83e63d8ee352e55ea968cd408ecbc3194846667387469be0974fe
MD5 a1af1cdddaa4cd0666e26e9e480eb30f
BLAKE2b-256 73b694c3b7a0fa14d177964d420a284fc021203d062e949c2505730cd481992b

See more details on using hashes here.

File details

Details for the file gdarch-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gdarch-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.20 Linux/6.17.0-1018-azure

File hashes

Hashes for gdarch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06f8630e78fb3c286916659eb3dc368d9524d6c7958614a24d57fcde08d5332c
MD5 596e27417ea6494878136c19710bb6cf
BLAKE2b-256 cf07e77a018a93a2fc09d613c09896e81a90c08ebbee5d94b686698bcca0648c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page