Skip to main content

CLI tool for backing up TrueNAS configurations.

Project description

TrueNAS Backup Tool

A CLI tool for backing up TrueNAS configurations using the TrueNAS API. It initiates a config download via the API, saves the backup as a .tar.gz file, and manages retention by limiting the number of kept backups.

Features

  • Authenticates with TrueNAS using API key.
  • Downloads configuration backups with optional inclusion of secretseed and root authorized keys.
  • Saves backups to a specified directory (default: system temp directory, e.g., /tmp on Unix, %TEMP% on Windows).
  • Automatic retention management to keep only the specified number of recent backups.
  • Cross-platform compatible.
  • CLI commands: run to perform a backup.

Usage

No installation required. The tool can be run directly with uvx (requires uv installed):

uvx truenas-backup --url truenas.local --api-key your-api-key

Note: For uvx, provide options directly; .env files are not loaded automatically.

Optionally, export environment variables directly:

export TRUENAS_URL=truenas.local
export TRUENAS_API_KEY=your-api-key
export VERIFY_SSL=false
export MAX_BACKUPS=5
export SECRETSEED=false
export ROOT_AUTHORIZED_KEYS=false

Perform a Backup

truenas run

This performs a backup using environment defaults (from exports or .env).

With options (overrides env vars):

truenas run --url truenas.local --api-key your-api-key --backup-dir /path/to/backups --max-backups 10 --secretseed --verify-ssl

Options:

  • --url TEXT: TrueNAS URL (overrides TRUENAS_URL).
  • --api-key TEXT: API key (overrides TRUENAS_API_KEY).
  • --verify-ssl / --no-verify-ssl: Verify SSL (overrides VERIFY_SSL).
  • --max-backups INTEGER: Max backups to keep (overrides MAX_BACKUPS).
  • --secretseed / --no-secretseed: Include secretseed (overrides SECRETSEED).
  • --root-authorized-keys / --no-root-authorized-keys: Include root keys (overrides ROOT_AUTHORIZED_KEYS).
  • --backup-dir TEXT: Directory to save backups (default: system temp dir).

Output example:

Backup completed: {'filename': '/tmp/truenas-backup-20251023-232000.tar.gz', 'size': 123456, 'backups_kept': 5}

Docker

The project includes a Dockerfile for containerized deployment.

Build the image:

docker build -t truenas-backup .

Run with environment and volume mount:

docker run -it --env-file .env -v /host/backups:/app/backups truenas-backup python main.py run --backup-dir /app/backups

For scheduled runs, use cron inside the container or host cron.

Development

  • Linting: uv run ruff check .
  • Run tests: (Add tests as needed)

License

MIT License - see LICENSE for details.

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

truenas_backup-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

truenas_backup-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file truenas_backup-1.0.0.tar.gz.

File metadata

  • Download URL: truenas_backup-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for truenas_backup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79a9ebf4672b7095792f4e89a3b6302a220ad847622035e7a1d82d2a4983c0ff
MD5 58a72c7e2f72d6511079cc82bc063f0b
BLAKE2b-256 e8c7b9abc35ec29173126b00c2503878d19125d994668857503ee60772a343bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for truenas_backup-1.0.0.tar.gz:

Publisher: publish-to-pypi.yml on theLastOfCats/truenas-backup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file truenas_backup-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: truenas_backup-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for truenas_backup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a59e3692bd509792320fb08eb1e250568a80ccb6ed62a3fc4b18bb093f65495
MD5 9293aa00863d759dda3efac6c13f388c
BLAKE2b-256 8983ad634b3b075b6aef8cc219c0deff40f038ce09c5ede8b648f6116310a72d

See more details on using hashes here.

Provenance

The following attestation bundles were made for truenas_backup-1.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on theLastOfCats/truenas-backup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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