Portainer Client Tools - CLI for managing Portainer from client
Project description
ptctools - Portainer Client Tools
CLI for managing Portainer stacks, volume backups, and database operations.
Note: Only tested on Portainer 2.33.6
Installation
# From Git repository
uv tool install git+https://github.com/tamntlib/ptctools.git
# or
uv tool install ptctools --from git+https://github.com/tamntlib/ptctools.git
# From local path
uv tool install openapi-generator-cli==7.19.0
openapi-generator-cli generate \
-i portainer_openapi.yml \
-g python \
-o ./src/ptctools/portainer_client \
--skip-validate-spec \
--additional-properties=generateSourceCodeOnly=true
uv tool install . --no-cache --reinstall
Usage
export PORTAINER_URL=https://portainer.example.com
export PORTAINER_ACCESS_TOKEN=your-api-key
export S3_ACCESS_KEY=your-s3-key
export S3_SECRET_KEY=your-s3-secret
export S3_ENDPOINT=https://s3.<region>.amazonaws.com
# Stack deployment
ptctools stack deploy -u $PORTAINER_URL -n mystack -f compose.yaml
# Volume backup/restore (uses Duplicati)
ptctools volume backup -u $PORTAINER_URL -v vol1,vol2 -o s3://mybucket
ptctools volume restore -u $PORTAINER_URL -i s3://mybucket/vol1 # volume name derived from URI path
ptctools volume restore -u $PORTAINER_URL -v vol1 -i s3://mybucket/vol1 # explicit volume name
# Volume copy (raw copy using mc/busybox)
ptctools volume cp -u $PORTAINER_URL source dest # volume to volume
ptctools volume cp -u $PORTAINER_URL s3://mybucket/path dest # S3 to volume
ptctools volume cp -u $PORTAINER_URL source s3://mybucket/path # volume to S3
# Volume management
ptctools volume rm -u $PORTAINER_URL myvolume # remove volume (with confirmation)
ptctools volume rm -u $PORTAINER_URL -y myvolume # remove without confirmation
ptctools volume rename -u $PORTAINER_URL old_name new_name # rename volume (copy + delete)
# Database backup/restore (uses minio/mc for S3)
ptctools db backup -u $PORTAINER_URL -c container_id -v db_data \
--db-user postgres --db-name mydb -o backup.sql.gz
ptctools db backup -u $PORTAINER_URL -c container_id -v db_data \
--db-user postgres --db-name mydb -o s3://mybucket/backups/db.sql.gz
ptctools db restore -u $PORTAINER_URL -c container_id -v db_data \
--db-user postgres --db-name mydb -i backup.sql.gz
ptctools db restore -u $PORTAINER_URL -c container_id -v db_data \
--db-user postgres --db-name mydb -i s3://mybucket/backups/db.sql.gz
# Config management
# Create config from inline data
ptctools config set -u $PORTAINER_URL -n my-config -d "config content"
ptctools config set -u $PORTAINER_URL -n nginx.conf -f ./nginx.conf
ptctools config set -u $PORTAINER_URL -n my-config -d "new content" --force
ptctools config list -u $PORTAINER_URL
ptctools config get -u $PORTAINER_URL -n my-config
ptctools config delete -u $PORTAINER_URL -n my-config
# Utils - local Duplicati operations
ptctools utils backup --input ./data --output s3://backups/mydata
ptctools utils restore --input s3://backups/mydata --output ./restored
Environment Variables
PORTAINER_ACCESS_TOKEN- Portainer API key (required)S3_ACCESS_KEY/S3_SECRET_KEY- S3 credentials (for backup commands)S3_ENDPOINT- S3/MinIO endpoint URLDUPLICATI_PASSPHRASE- Backup encryption passphrase (optional, for volume backups)
Commands
ptctools stack deploy
Deploy or update a Docker stack in Portainer.
ptctools volume backup/restore
- backup: Backup multiple Docker volumes (comma-separated) to S3 using Duplicati container.
- restore: Restore a single Docker volume from S3. Volume name can be specified via
--volumeor derived from the input URI path.
ptctools volume cp
Copy data between volumes and S3 (raw file copy).
- volume to volume: Uses
busyboxwithcp -a - S3 to volume: Uses
minio/mcto download files - volume to S3: Uses
minio/mcto upload files
ptctools volume rm
Remove a Docker volume. Use -y to skip confirmation, -f to force removal.
ptctools volume rename
Rename a volume by copying data to a new volume and deleting the original.
ptctools db backup/restore
Backup/restore PostgreSQL database. Supports both local files and S3 URIs.
- Uses
pg_dump/psqlfor database operations - Uses
minio/mccontainer for S3 transfers
ptctools utils backup/restore
Local backup/restore operations using Duplicati CLI (docker or local).
ptctools config set/get/list/delete
Manage Docker Swarm configs via Portainer API.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ptctools-0.1.1.tar.gz.
File metadata
- Download URL: ptctools-0.1.1.tar.gz
- Upload date:
- Size: 639.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
619f8a0415dcf71a459128d600e5eebce524d456b4deef8cb24595e422df2543
|
|
| MD5 |
3132ada28be63ac600dcec2696acd16e
|
|
| BLAKE2b-256 |
913ba0cc3357556de7b10644889d91434c7d41f34fb839fb49a7a9497f416b80
|
File details
Details for the file ptctools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ptctools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61aa537cf3ac6d3eb243f8b3381070d0a226b6f343b2338716b4206501acf6b2
|
|
| MD5 |
860c80f65d64f8fc63e18d9507050f52
|
|
| BLAKE2b-256 |
e248d16cafff31dfcd5ed20c32e31f366b7aa17530b1c9645ac6d70297aacee8
|