### MCP Integration - Endpoint Setup Source: https://context7.com/localrivet/datasaver/llms.txt Instructions on how to enable and access the MCP endpoint for programmatic backup management using Bearer token authentication. ```APIDOC ## MCP Integration - Endpoint Setup The MCP (Model Context Protocol) endpoint allows AI assistants like Claude to manage backups programmatically with Bearer token authentication. ### Setup ```bash # Enable MCP endpoint export DATASAVER_MCP_API_KEY="your-secure-api-key" export DATASAVER_BASE_URL="https://your-domain.com" datasaver daemon ``` ### MCP Endpoint URL `http://localhost:8080/mcp` ### OAuth Discovery Endpoints - `GET /.well-known/oauth-protected-resource` - `GET /.well-known/oauth-authorization-server` ``` -------------------------------- ### YAML Configuration Example for DataSaver Source: https://github.com/localrivet/datasaver/blob/main/docs/configuration.md This snippet shows an example of a `config.yaml` file used to configure DataSaver. It includes settings for database, storage, schedule, retention, backup verification, and monitoring. This file needs to be created and referenced when running the `datasaver daemon` command. ```yaml database: type: postgres host: localhost port: 5432 name: myapp user: backup_user password: secret storage: backend: s3 path: ./backups s3: bucket: my-backups endpoint: s3.amazonaws.com region: us-west-2 access_key: AKIAIOSFODNN7EXAMPLE secret_key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY schedule: "0 */6 * * *" # Every 6 hours retention: daily: 7 weekly: 4 monthly: 12 backup: verify_after_backup: true verify_checksum: true monitoring: health_port: 8080 metrics_port: 9090 webhook_url: https://hooks.slack.com/services/... alert_after_hours: 26 ``` -------------------------------- ### MCP Endpoint Setup (Bash) Source: https://context7.com/localrivet/datasaver/llms.txt Shell commands to enable and configure the MCP (Model Context Protocol) endpoint for programmatic backup management. It requires setting environment variables for API key and base URL, then running the datasaver daemon. ```bash # Enable MCP endpoint export DATASAVER_MCP_API_KEY="your-secure-api-key" export DATASAVER_BASE_URL="https://your-domain.com" datasaver daemon # MCP endpoint available at: http://localhost:8080/mcp # OAuth discovery endpoints: # GET /.well-known/oauth-protected-resource # GET /.well-known/oauth-authorization-server ``` -------------------------------- ### Go Backup Engine API Usage (Go) Source: https://context7.com/localrivet/datasaver/llms.txt Example Go program demonstrating the usage of the datasaver backup engine API. It covers loading configuration, setting up storage and notifiers, running backups, listing existing backups, and cleaning up old ones. ```go package main import ( "context" "log/slog" "os" "github.com/localrivet/datasaver/internal/backup" "github.com/localrivet/datasaver/internal/config" "github.com/localrivet/datasaver/internal/notify" "github.com/localrivet/datasaver/internal/storage" ) func main() { ctx := context.Background() logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) // Load configuration cfg, err := config.Load("config.yaml") if err != nil { logger.Error("failed to load config", "error", err) os.Exit(1) } // Create storage backend factory := storage.NewFactory() store, err := factory.Create(cfg.Storage.Backend, cfg.Storage.Path, nil) if err != nil { logger.Error("failed to create storage", "error", err) os.Exit(1) } // Create notifier (optional) notifier := notify.NewNotifier(cfg.Monitoring.WebhookURL, logger) // Create backup engine engine := backup.NewEngine(cfg, store, notifier, logger) // Run backup result, err := engine.Run(ctx) if err != nil { logger.Error("backup failed", "error", err) os.Exit(1) } logger.Info("backup completed", "id", result.ID, "size", result.Size, "compressed_size", result.CompressedSize, "duration", result.Duration, ) // List backups backups, _ := engine.ListBackups(ctx) for _, b := range backups { logger.Info("backup", "id", b.ID, "timestamp", b.Timestamp, "type", b.Type) } // Cleanup old backups deleted, _ := engine.Cleanup(ctx) logger.Info("cleanup completed", "deleted", deleted) } ``` -------------------------------- ### Scheduler API (Go) Source: https://context7.com/localrivet/datasaver/llms.txt Provides cron-based backup scheduling with manual trigger support. Allows starting the scheduler, checking the next run time, triggering immediate backups, and stopping gracefully. Requires configuration, storage, and logging. ```go package main import ( "context" "log/slog" "os" "os/signal" "syscall" "github.com/localrivet/datasaver/internal/backup" "github.com/localrivet/datasaver/internal/config" "github.com/localrivet/datasaver/internal/storage" ) func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) cfg, _ := config.Load("") factory := storage.NewFactory() store, _ := factory.Create("local", "/backups", nil) engine := backup.NewEngine(cfg, store, nil, logger) scheduler := backup.NewScheduler(engine, "0 2 * * *", logger) // Start scheduler scheduler.Start(ctx) // Logs: scheduler started, schedule: 0 2 * * *, next_run: 2024-01-16T02:00:00Z // Check next scheduled run nextRun := scheduler.NextRun() // nextRun: 2024-01-16T02:00:00Z // Trigger immediate backup result, _ := scheduler.RunNow(ctx) // result.ID: backup_20240115_143022 // Check if running running := scheduler.IsRunning() // running: true // Wait for shutdown signal sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) <-sigCh // Stop scheduler gracefully scheduler.Stop() } ``` -------------------------------- ### Database Driver Interface (Go) Source: https://context7.com/localrivet/datasaver/llms.txt Abstracts database operations for PostgreSQL and SQLite. Supports connecting, getting version, and dumping database content to a writer. Requires database connection configurations. ```go package main import ( "context" "os" "github.com/localrivet/datasaver/pkg/database" ) func main() { ctx := context.Background() // PostgreSQL driver pgDriver, _ := database.NewDriver(database.Config{ Type: "postgres", Host: "localhost", Port: 5432, Name: "myapp", User: "postgres", Password: "secret", }) defer pgDriver.Close() pgDriver.Connect(ctx) version, _ := pgDriver.Version(ctx) // version: "16.1" // Dump to writer f, _ := os.Create("backup.dump") pgDriver.Dump(ctx, f) f.Close() // SQLite driver sqliteDriver, _ := database.NewDriver(database.Config{ Type: "sqlite", Path: "/data/myapp.db", }) defer sqliteDriver.Close() sqliteDriver.Connect(ctx) sqliteDriver.Dump(ctx, os.Stdout) } ``` -------------------------------- ### S3 Storage Backend Setup for Datasaver Source: https://context7.com/localrivet/datasaver/llms.txt Configures Datasaver to store backups in S3-compatible storage, such as AWS S3 or MinIO. This setup requires the Datasaver image and environment variables specifying S3 bucket details, endpoint, region, credentials, and SSL usage. Compression can also be configured. ```yaml # compose.yml with S3 storage services: datasaver: image: ghcr.io/localrivet/datasaver:latest environment: DATASAVER_DB_HOST: postgres DATASAVER_DB_NAME: myapp DATASAVER_DB_USER: postgres DATASAVER_DB_PASSWORD: secret DATASAVER_SCHEDULE: "0 */6 * * *" DATASAVER_STORAGE_BACKEND: s3 DATASAVER_S3_BUCKET: my-backups DATASAVER_S3_ENDPOINT: s3.amazonaws.com DATASAVER_S3_REGION: us-west-2 DATASAVER_S3_ACCESS_KEY: ${AWS_ACCESS_KEY_ID} DATASAVER_S3_SECRET_KEY: ${AWS_SECRET_ACCESS_KEY} DATASAVER_S3_USE_SSL: "true" DATASAVER_COMPRESSION: gzip depends_on: - postgres ``` -------------------------------- ### Go Library - Backup Engine API Source: https://context7.com/localrivet/datasaver/llms.txt Usage example of the Datasaver Go library's backup engine for programmatic backup operations. ```APIDOC ## Go Library - Backup Engine API The backup engine provides programmatic access to backup operations for custom integrations. ### Example Usage ```go package main import ( "context" "log/slog" "os" "github.com/localrivet/datasaver/internal/backup" "github.com/localrivet/datasaver/internal/config" "github.com/localrivet/datasaver/internal/notify" "github.com/localrivet/datasaver/internal/storage" ) func main() { ctx := context.Background() logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) // Load configuration cfg, err := config.Load("config.yaml") if err != nil { logger.Error("failed to load config", "error", err) os.Exit(1) } // Create storage backend factory := storage.NewFactory() store, err := factory.Create(cfg.Storage.Backend, cfg.Storage.Path, nil) if err != nil { logger.Error("failed to create storage", "error", err) os.Exit(1) } // Create notifier (optional) notifier := notify.NewNotifier(cfg.Monitoring.WebhookURL, logger) // Create backup engine engine := backup.NewEngine(cfg, store, notifier, logger) // Run backup result, err := engine.Run(ctx) if err != nil { logger.Error("backup failed", "error", err) os.Exit(1) } logger.Info("backup completed", "id", result.ID, "size", result.Size, "compressed_size", result.CompressedSize, "duration", result.Duration, ) // List backups backups, _ := engine.ListBackups(ctx) for _, b := range backups { logger.Info("backup", "id", b.ID, "timestamp", b.Timestamp, "type", b.Type) } // Cleanup old backups deleted, _ := engine.Cleanup(ctx) logger.Info("cleanup completed", "deleted", deleted) } ``` ``` -------------------------------- ### MCP Integration - Tool Calls Source: https://context7.com/localrivet/datasaver/llms.txt Available MCP tool calls for managing backups, including triggering backups, listing, restoring, verifying, and getting system status. ```APIDOC ## MCP Integration - Tool Calls Available MCP tools for backup management through AI assistants. ### `backup_now` **Description**: Trigger an immediate backup. **Arguments**: None ### `list_backups` **Description**: List available backups. **Arguments**: - `limit` (integer) - Optional - The maximum number of backups to return. ### `restore_backup` **Description**: Restore from a backup. **Arguments**: - `backup_id` (string) - Required - The ID of the backup to restore. - `target_db` (string) - Required - The name of the target database for restoration. - `dry_run` (boolean) - Optional - If true, perform a dry run without actually restoring. ### `verify_backup` **Description**: Verify the integrity of a backup. **Arguments**: - `backup_id` (string) - Required - The ID of the backup to verify. ### `get_status` **Description**: Get the system status. **Arguments**: None ``` -------------------------------- ### Start datasaver Daemon (Bash) Source: https://github.com/localrivet/datasaver/blob/main/docs/mcp-integration.md Starts the datasaver daemon, which exposes the MCP endpoint. The endpoint will then be accessible at http://localhost:8080/mcp by default. ```bash datasaver daemon ``` -------------------------------- ### Basic PostgreSQL Sidecar Setup with Local Storage Source: https://context7.com/localrivet/datasaver/llms.txt Deploys Datasaver as a sidecar container alongside a PostgreSQL database for automated backups using local storage. It requires the PostgreSQL image and Datasaver image, along with environment variables for database credentials and backup schedules. Volumes are defined for persistent PostgreSQL data and backup storage. ```yaml # compose.yml services: postgres: image: postgres:16 environment: POSTGRES_DB: myapp POSTGRES_USER: postgres POSTGRES_PASSWORD: secret volumes: - postgres_data:/var/lib/postgresql/data datasaver: image: ghcr.io/localrivet/datasaver:latest environment: DATASAVER_DB_HOST: postgres DATASAVER_DB_NAME: myapp DATASAVER_DB_USER: postgres DATASAVER_DB_PASSWORD: secret DATASAVER_SCHEDULE: "0 2 * * *" DATASAVER_STORAGE_BACKEND: local DATASAVER_STORAGE_PATH: /backups DATASAVER_KEEP_DAILY: 7 DATASAVER_KEEP_WEEKLY: 4 DATASAVER_KEEP_MONTHLY: 6 volumes: - backup_data:/backups depends_on: - postgres restart: unless-stopped volumes: postgres_data: backup_data: ``` -------------------------------- ### MCP Tool Calls (JSON) Source: https://context7.com/localrivet/datasaver/llms.txt Examples of JSON payloads representing tool calls for managing backups via the MCP endpoint. These include actions like triggering backups, listing, restoring, verifying, and checking system status. ```json // backup_now - Trigger immediate backup { "name": "backup_now", "arguments": {} } ``` ```json // list_backups - List available backups { "name": "list_backups", "arguments": { "limit": 10 } } ``` ```json // restore_backup - Restore from backup { "name": "restore_backup", "arguments": { "backup_id": "backup_20240115_0200", "target_db": "myapp_restored", "dry_run": true } } ``` ```json // verify_backup - Verify backup integrity { "name": "verify_backup", "arguments": { "backup_id": "backup_20240115_0200" } } ``` ```json // get_status - Get system status { "name": "get_status", "arguments": {} } ``` -------------------------------- ### datasaver CLI Commands for Management and Restore Source: https://github.com/localrivet/datasaver/blob/main/README.md Provides examples of datasaver CLI commands for daemon operation, listing backups, performing restores (including to a different database and dry-run), cleanup, health checks, and verifying backup integrity. These commands offer granular control over backup management. ```bash ### `datasaver daemon` # Run as scheduled backup daemon. Starts the scheduler, health endpoint, and metrics server. ```bash datasaver daemon datasaver daemon --config /etc/datasaver/config.yml ``` ### `datasaver backup` # Perform an immediate backup. ```bash datasaver backup ``` ### `datasaver list` # List all available backups. ```bash datasaver list ``` ### `datasaver restore ` # Restore from a specific backup. ```bash datasaver restore backup_20240111_0200 # Restore to different database datasaver restore backup_20240111_0200 --target-db mydb_restored # Dry run (test without applying) datasaver restore backup_20240111_0200 --dry-run ``` ### `datasaver cleanup` # Manually run the cleanup routine to delete old backups. ```bash datasaver cleanup ``` ### `datasaver health` # Check backup system health. ```bash datasaver health ``` ### `datasaver verify ` # Validate backup integrity. ```bash datasaver verify backup_20240111_0200 ``` ``` -------------------------------- ### Configuring Datasaver Webhook Notifications Source: https://context7.com/localrivet/datasaver/llms.txt This example demonstrates how to configure Datasaver to send webhook notifications to a specified URL upon backup events, such as success, failure, or alerts. The DATASAVER_WEBHOOK_URL environment variable is used to set the target URL for these notifications. ```bash # Configure webhook export DATASAVER_WEBHOOK_URL=https://hooks.example.com/backup ``` -------------------------------- ### datasaver Configuration File (YAML) Source: https://github.com/localrivet/datasaver/blob/main/README.md Example YAML configuration file for datasaver. This allows for structured configuration of database connection, schedule, storage (including S3 details), retention policies, compression, and monitoring parameters. ```yaml database: url: "postgres://user:pass@postgres:5432/mydb" schedule: "0 2 * * *" storage: backend: s3 s3: bucket: my-backups endpoint: s3.amazonaws.com region: us-east-1 access_key: ${AWS_ACCESS_KEY} secret_key: ${AWS_SECRET_KEY} retention: daily: 7 weekly: 4 monthly: 6 max_age_days: 90 compression: gzip monitoring: metrics_port: 9090 health_port: 8080 webhook_url: https://hooks.example.com/backup alert_after_hours: 26 ``` -------------------------------- ### Querying Datasaver Prometheus Metrics Endpoint Source: https://context7.com/localrivet/datasaver/llms.txt This command retrieves Prometheus metrics exposed by Datasaver, providing insights into backup performance and system usage. Key metrics include backup duration, size, success rate, and storage utilization. The example also includes a Prometheus scrape configuration. ```bash # Query metrics endpoint curl http://localhost:9090/metrics # Key metrics exposed: # datasaver_backup_duration_seconds - Histogram of backup duration # datasaver_backup_size_bytes - Gauge of last backup size # datasaver_backups_total - Counter of total backup attempts # datasaver_backup_failures_total - Counter of failed backups # datasaver_last_backup_timestamp - Gauge of last backup time # datasaver_last_backup_success - Gauge (1=success, 0=failure) # datasaver_storage_used_bytes - Gauge of total storage used # Example Prometheus scrape config: # scrape_configs: # - job_name: 'datasaver' # static_configs: # - targets: ['datasaver:9090'] ``` -------------------------------- ### Docker Compose Configuration for datasaver Source: https://github.com/localrivet/datasaver/blob/main/README.md Example Docker Compose configuration to deploy datasaver as a sidecar container. It specifies environment variables for database connection, scheduling, storage, and retention policies. Ensure `backup_data` volume is correctly configured for persistent storage. ```yaml datasaver: image: ghcr.io/localrivet/datasaver:latest environment: DATASAVER_DB_HOST: postgres DATASAVER_DB_NAME: mydb DATASAVER_DB_USER: postgres DATASAVER_DB_PASSWORD: secret DATASAVER_SCHEDULE: "0 2 * * *" DATASAVER_STORAGE_BACKEND: local DATASAVER_STORAGE_PATH: /backups DATASAVER_KEEP_DAILY: 7 DATASAVER_KEEP_WEEKLY: 4 DATASAVER_KEEP_MONTHLY: 6 volumes: - backup_data:/backups depends_on: - postgres restart: unless-stopped ``` -------------------------------- ### Example Webhook Notification Payload (JSON) Source: https://github.com/localrivet/datasaver/blob/main/README.md This JSON object represents the payload sent to a configured webhook URL upon backup events. It includes event details such as the event type, timestamp, backup ID, status, and specific details about the backup's size and duration. This format is crucial for integrating datasaver events with other systems. ```json { "event": "backup.completed", "timestamp": "2024-01-11T02:00:15Z", "backup_id": "backup_20240111_0200", "status": "success", "message": "Backup backup_20240111_0200 completed successfully", "details": { "size_bytes": 131621888, "duration_ms": 12500 } } ``` -------------------------------- ### Storage Backend Interface (Go) Source: https://context7.com/localrivet/datasaver/llms.txt Provides abstraction for local filesystem and S3-compatible storage. Supports writing, reading, listing, checking existence, and deleting backup files. Requires storage specific configurations. ```go package main import ( "bytes" "context" "io" "github.com/localrivet/datasaver/internal/storage" ) func main() { ctx := context.Background() // Local storage localStore, _ := storage.NewLocalStorage("/backups") // Write backup data := bytes.NewReader([]byte("backup data")) localStore.Write(ctx, "backup_20240115.dump", data) // Read backup reader, _ := localStore.Read(ctx, "backup_20240115.dump") content, _ := io.ReadAll(reader) reader.Close() // List backups files, _ := localStore.List(ctx, "") for _, f := range files { // f.Path, f.Size, f.LastModified } // Check existence exists, _ := localStore.Exists(ctx, "backup_20240115.dump") // Delete backup localStore.Delete(ctx, "backup_20240115.dump") // S3 storage s3Store, _ := storage.NewS3Storage(storage.S3Config{ Bucket: "my-backups", Endpoint: "s3.amazonaws.com", Region: "us-west-2", AccessKey: "AKIAIOSFODNN7EXAMPLE", SecretKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", UseSSL: true, }) // Same interface as local storage s3Store.Write(ctx, "backup_20240115.dump", bytes.NewReader(content)) } ``` -------------------------------- ### Datasaver Application Structure (Go) Source: https://github.com/localrivet/datasaver/blob/main/prd.md Illustrates the directory structure for the datasaver Go application, highlighting the organization of core logic, modules, and entry points. Key directories include 'cmd' for the CLI entry point, 'internal' for application logic, and 'pkg' for reusable packages. ```tree datasaver/ ├── cmd/ │ └── datasaver/ │ └── main.go # CLI entry point ├── internal/ │ ├── backup/ │ │ ├── engine.go # Core backup logic │ │ ├── scheduler.go # Cron scheduling │ │ └── validator.go # Backup validation │ ├── storage/ │ │ ├── interface.go # Storage abstraction │ │ ├── local.go # Local filesystem │ │ └── s3.go # S3-compatible storage │ ├── rotation/ │ │ ├── policy.go # Retention policies │ │ └── gfs.go # GFS rotation logic │ ├── restore/ │ │ ├── engine.go # Restore operations │ │ └── pitr.go # Point-in-time recovery │ ├── config/ │ │ └── config.go # Configuration management │ ├── metrics/ │ │ └── prometheus.go # Metrics collection │ └── notify/ │ └── webhook.go # Notification handling ├── pkg/ │ └── postgres/ │ ├── connection.go # Postgres client │ └── metadata.go # Backup metadata ├── Dockerfile ├── docker-compose.yml # Example deployment └── README.md ``` -------------------------------- ### Build and Run datasaver Application (Bash) Source: https://github.com/localrivet/datasaver/blob/main/CLAUDE.md These commands demonstrate how to build the datasaver Go application binary, run its tests, create a Docker image, and launch it using docker-compose. This is essential for development and deployment. ```bash # Build binary go build -o datasaver ./cmd/datasaver # Run tests go test ./... # Build Docker image docker build -t datasaver . # Run with docker-compose docker compose up -d ``` -------------------------------- ### Build Binary and Docker Image (Bash) Source: https://github.com/localrivet/datasaver/blob/main/README.md These bash commands are used to build the datasaver project. The first command compiles the Go source code into an executable binary named 'datasaver'. The second command builds a Docker image tagged as 'datasaver' from the project's Dockerfile, enabling containerized deployment. ```bash # Build binary go build -o datasaver ./cmd/datasaver # Build Docker image docker build -t datasaver . ``` -------------------------------- ### Datasaver CLI - Daemon Mode (Bash) Source: https://github.com/localrivet/datasaver/blob/main/prd.md Demonstrates how to run the datasaver application in daemon mode using the CLI. The primary command is `datasaver daemon`. An optional flag `--config` can be used to specify a custom configuration file path, allowing for flexible deployment configurations. ```bash # Run as scheduled backup daemon datasaver daemon # Run with config file datasaver daemon --config /etc/datasaver/config.yml ``` -------------------------------- ### Datasaver CLI - One-Time Operations (Bash) Source: https://github.com/localrivet/datasaver/blob/main/prd.md Details various one-time operations that can be performed using the datasaver CLI. This includes initiating an immediate backup (`backup`), listing available backups with their details (`list`), restoring backups with options for target database and dry-run (`restore`), manually cleaning up old backups (`cleanup`), and verifying backup integrity (`verify`). The `list` command shows a sample output format. ```bash # Perform immediate backup datasaver backup # List available backups datasaver list # Output: # ID DATE SIZE TYPE # backup_20240111_0200 2024-01-11 02:00 125.5 MB daily # backup_20240110_0200 2024-01-10 02:00 124.8 MB daily # Restore from backup datasaver restore backup_20240111_0200 # Restore to different database datasaver restore backup_20240111_0200 --target-db mydb_restored # Test restore without applying datasaver restore backup_20240111_0200 --dry-run # Clean up old backups manually datasaver cleanup # Validate backup integrity datasaver verify backup_20240111_0200 ``` -------------------------------- ### Cleanup Algorithm for Backup Rotation Source: https://github.com/localrivet/datasaver/blob/main/prd.md Outlines the step-by-step process for cleaning up old backups based on defined retention policies. It involves scanning all backups, sorting by date, applying retention counts for daily, weekly, and monthly types, filtering by max age, and finally deleting marked backups. ```text 1. Scan all backups 2. For each backup type (daily/weekly/monthly): - Sort by date descending - Keep first N according to retention policy - Mark others for deletion if not protected by another policy 3. Apply max_age_days filter 4. Delete marked backups ``` -------------------------------- ### Claude Desktop Configuration Source: https://context7.com/localrivet/datasaver/llms.txt Configuration JSON for Claude Desktop to connect to the Datasaver MCP endpoint. ```APIDOC ## Claude Desktop Configuration Configure Claude Desktop to connect to the datasaver MCP endpoint. ```json // claude_desktop_config.json { "mcpServers": { "datasaver": { "url": "http://localhost:8080/mcp", "headers": { "Authorization": "Bearer your-secure-api-key" } } } } ``` ``` -------------------------------- ### datasaver Environment Variable Configuration Source: https://github.com/localrivet/datasaver/blob/main/README.md Lists and explains environment variables used to configure datasaver. Covers database connection details for PostgreSQL and SQLite, backup scheduling, storage options (local and S3), retention policies, compression, and monitoring settings. ```bash # Database Type (postgres or sqlite) DATASAVER_DB_TYPE=postgres # postgres (default) or sqlite # PostgreSQL Connection DATASAVER_DB_HOST=postgres DATASAVER_DB_PORT=5432 DATASAVER_DB_NAME=mydb DATASAVER_DB_USER=postgres DATASAVER_DB_PASSWORD=secret # Or use connection string (PostgreSQL) DATASAVER_DATABASE_URL=postgres://user:pass@host:5432/dbname # SQLite Configuration DATASAVER_DB_TYPE=sqlite DATASAVER_DB_PATH=/data/myapp.db # Path to SQLite database file # Backup Schedule (cron format) DATASAVER_SCHEDULE="0 2 * * *" # Storage DATASAVER_STORAGE_BACKEND=local # local or s3 DATASAVER_STORAGE_PATH=/backups # for local storage # S3 Storage DATASAVER_S3_BUCKET=my-backups DATASAVER_S3_ENDPOINT=s3.amazonaws.com DATASAVER_S3_REGION=us-east-1 DATASAVER_S3_ACCESS_KEY=xxx DATASAVER_S3_SECRET_KEY=xxx DATASAVER_S3_USE_SSL=true # Retention Policy DATASAVER_KEEP_DAILY=7 DATASAVER_KEEP_WEEKLY=4 DATASAVER_KEEP_MONTHLY=6 DATASAVER_MAX_AGE_DAYS=90 # Compression DATASAVER_COMPRESSION=gzip # gzip or none # Monitoring DATASAVER_METRICS_PORT=9090 DATASAVER_HEALTH_PORT=8080 DATASAVER_WEBHOOK_URL=https://hooks.example.com/backup DATASAVER_ALERT_AFTER_HOURS=26 ``` -------------------------------- ### Datasaver Configuration - Environment Variables (Bash) Source: https://github.com/localrivet/datasaver/blob/main/prd.md Defines the environment variables used to configure the datasaver application. These variables cover database connection details, backup scheduling, storage backend settings (local or S3), retention policies, compression methods, and monitoring parameters. Some variables like DATASAVER_STORAGE_BACKEND and DATASAVER_S3_ENDPOINT use specific values to indicate the chosen configuration. ```bash # Database Connection DATASAVER_DB_HOST=postgres DATASAVER_DB_PORT=5432 DATASAVER_DB_NAME=mydb DATASAVER_DB_USER=postgres DATASAVER_DB_PASSWORD=secret # Or use connection string DATASAVER_DATABASE_URL=postgres://user:pass@host:5432/dbname # Backup Schedule DATASAVER_SCHEDULE="0 2 * * *" # 2 AM daily # Storage DATASAVER_STORAGE_BACKEND=s3 # local|s3 DATASAVER_STORAGE_PATH=/backups # for local DATASAVER_S3_BUCKET=my-backups DATASAVER_S3_ENDPOINT=s3.amazonaws.com DATASAVER_S3_REGION=us-east-1 DATASAVER_S3_ACCESS_KEY=xxx DATASAVER_S3_SECRET_KEY=xxx # Retention DATASAVER_KEEP_DAILY=7 DATASAVER_KEEP_WEEKLY=4 DATASAVER_KEEP_MONTHLY=6 DATASAVER_MAX_AGE_DAYS=90 # Compression DATASAVER_COMPRESSION=gzip # gzip|zstd|none # Monitoring DATASAVER_METRICS_PORT=9090 DATASAVER_WEBHOOK_URL=https://hooks.example.com/backup DATASAVER_ALERT_AFTER_HOURS=26 # Alert if no backup in 26 hours ``` -------------------------------- ### Running DataSaver Daemon with YAML Configuration Source: https://github.com/localrivet/datasaver/blob/main/docs/configuration.md This command demonstrates how to run the DataSaver daemon while specifying a custom configuration file path. The `-c` flag is used to point to the location of the `config.yaml` file. ```bash datasaver daemon -c /path/to/config.yaml ``` -------------------------------- ### datasaver CLI Commands for Backup Operations Source: https://github.com/localrivet/datasaver/blob/main/README.md Demonstrates common datasaver CLI commands for performing backups, listing existing backups, restoring from a specific backup, and checking the system's health. These commands can be executed directly from the terminal. ```bash # Run as daemon datasaver daemon # Perform immediate backup datasaver backup # List backups datasaver list # Restore from backup datasaver restore backup_20240111_0200 # Check health datasaver health ``` -------------------------------- ### Comprehensive Datasaver YAML Configuration Source: https://context7.com/localrivet/datasaver/llms.txt Provides a detailed YAML configuration file for Datasaver, covering database connection (PostgreSQL and SQLite), storage options (local and S3), backup scheduling, compression, retention policies, backup verification, and monitoring settings. Environment variable expansion is supported for sensitive parameters like passwords. ```yaml # config.yaml database: type: postgres host: localhost port: 5432 name: myapp user: backup_user password: ${DB_PASSWORD} # Environment variable expansion supported storage: backend: s3 path: ./backups # Used for local backend s3: bucket: my-backups endpoint: s3.amazonaws.com region: us-west-2 access_key: ${AWS_ACCESS_KEY_ID} secret_key: ${AWS_SECRET_ACCESS_KEY} use_ssl: true schedule: "0 */6 * * *" # Every 6 hours compression: gzip # gzip, zstd, or none retention: daily: 7 weekly: 4 monthly: 12 max_age_days: 90 backup: verify_after_backup: true # Verify backup integrity after creation verify_checksum: true # Verify checksum on restore monitoring: health_port: 8080 metrics_port: 9090 webhook_url: https://hooks.slack.com/services/xxx/yyy/zzz alert_after_hours: 26 ``` ```yaml # config-sqlite.yaml database: type: sqlite path: /data/myapp.db storage: backend: local path: /backups schedule: "0 3 * * *" compression: gzip retention: daily: 7 weekly: 4 monthly: 6 ``` -------------------------------- ### Datasaver CLI - Health Check (Bash) Source: https://github.com/localrivet/datasaver/blob/main/prd.md Shows how to perform a health check on the datasaver backup system using the CLI. The `datasaver health` command provides a summary of the system's status, including the last and next backup times, total number of backups, and current storage utilization. A sample output is provided. ```bash # Check backup system health datasaver health # Output: # Status: healthy # Last backup: 2024-01-11 02:00:15 (success) # Next backup: 2024-01-12 02:00:00 # Total backups: 23 # Storage used: 2.8 GB ``` -------------------------------- ### Claude Desktop MCP Configuration (JSON) Source: https://context7.com/localrivet/datasaver/llms.txt JSON configuration file for Claude Desktop to connect to the datasaver MCP endpoint. It specifies the endpoint URL and includes the necessary Bearer token for authentication. ```json // claude_desktop_config.json { "mcpServers": { "datasaver": { "url": "http://localhost:8080/mcp", "headers": { "Authorization": "Bearer your-secure-api-key" } } } } ``` -------------------------------- ### Datasaver Docker Compose Integration Source: https://github.com/localrivet/datasaver/blob/main/prd.md Provides a docker-compose.yml file for deploying the datasaver application alongside a PostgreSQL database. It defines two services: 'postgres' for the database and 'datasaver' for the application itself. The 'datasaver' service is configured with environment variables and volumes, and it depends on the 'postgres' service to ensure proper startup order. ```yaml version: "3.8" services: postgres: image: postgres:16-alpine environment: POSTGRES_DB: mydb POSTGRES_USER: postgres POSTGRES_PASSWORD: secret volumes: - postgres_data:/var/lib/postgresql/data networks: - app_network datasaver: image: ghcr.io/yourusername/datasaver:latest environment: DATASAVER_DB_HOST: postgres DATASAVER_DB_NAME: mydb DATASAVER_DB_USER: postgres DATASAVER_DB_PASSWORD: secret DATASAVER_SCHEDULE: "0 2 * * *" DATASAVER_STORAGE_BACKEND: local DATASAVER_STORAGE_PATH: /backups DATASAVER_KEEP_DAILY: 7 DATASAVER_KEEP_WEEKLY: 4 DATASAVER_KEEP_MONTHLY: 6 volumes: - backup_data:/backups depends_on: - postgres networks: - app_network restart: unless-stopped volumes: postgres_data: backup_data: networks: app_network: ``` -------------------------------- ### backup_now Tool Source: https://github.com/localrivet/datasaver/blob/main/docs/mcp-integration.md Triggers an immediate backup of the data. ```APIDOC ## POST /mcp/tools/backup_now ### Description Triggers an immediate backup. ### Method POST ### Endpoint `/mcp/tools/backup_now` ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of backups to list. #### Request Body - **name** (string) - Required - The name of the tool, must be "backup_now". - **arguments** (object) - Required - An empty object for this tool. ### Request Example ```json { "name": "backup_now", "arguments": {} } ``` ### Response #### Success Response (200) - **result** (object) - The result of the backup operation. - **error** (string) - An error message if the operation failed. #### Response Example ```json { "result": { "backup_id": "20240115-020000" }, "error": null } ``` ``` -------------------------------- ### list_backups Tool Source: https://github.com/localrivet/datasaver/blob/main/docs/mcp-integration.md Lists all available backups, with an optional limit. ```APIDOC ## POST /mcp/tools/list_backups ### Description Lists all available backups. ### Method POST ### Endpoint `/mcp/tools/list_backups` ### Parameters #### Request Body - **name** (string) - Required - The name of the tool, must be "list_backups". - **arguments** (object) - Required - Contains arguments for the tool. - **limit** (integer) - Optional - The maximum number of backups to list. ### Request Example ```json { "name": "list_backups", "arguments": { "limit": 10 } } ``` ### Response #### Success Response (200) - **result** (object) - The result of the list operation. - **backups** (array) - A list of backup objects. - **backup_id** (string) - The ID of the backup. - **timestamp** (string) - The timestamp of the backup. - **error** (string) - An error message if the operation failed. #### Response Example ```json { "result": { "backups": [ { "backup_id": "20240115-020000", "timestamp": "2024-01-15T02:00:00Z" } ] }, "error": null } ``` ``` -------------------------------- ### MCP Tool: backup_now (JSON) Source: https://github.com/localrivet/datasaver/blob/main/docs/mcp-integration.md Represents the JSON payload for the backup_now tool, which triggers an immediate backup. This tool takes no arguments. ```json { "name": "backup_now", "arguments": {} } ``` -------------------------------- ### Prometheus Metrics Endpoint Source: https://context7.com/localrivet/datasaver/llms.txt This endpoint exposes Prometheus-compatible metrics for monitoring and observability of the datasaver service, including backup duration, size, success rates, and storage utilization. ```APIDOC ## GET /metrics ### Description Exposes Prometheus metrics for observability. ### Method GET ### Endpoint /metrics ### Parameters None ### Request Example ```bash curl http://localhost:9090/metrics ``` ### Response #### Success Response (200) Returns a text-based response containing Prometheus metrics. Key metrics include: - **datasaver_backup_duration_seconds**: Histogram of backup duration. - **datasaver_backup_size_bytes**: Gauge of the last backup size. - **datasaver_backups_total**: Counter of total backup attempts. - **datasaver_backup_failures_total**: Counter of failed backups. - **datasaver_last_backup_timestamp**: Gauge of the last backup time. - **datasaver_last_backup_success**: Gauge (1 for success, 0 for failure). - **datasaver_storage_used_bytes**: Gauge of total storage used. #### Response Example ```text # HELP datasaver_backup_duration_seconds Histogram of backup duration # TYPE datasaver_backup_duration_seconds histogram datasaver_backup_duration_seconds_bucket{le="0.1"} 0 datasaver_backup_duration_seconds_bucket{le="0.5"} 1 datasaver_backup_duration_seconds_bucket{le="1"} 2 datasaver_backup_duration_seconds_bucket{le="+Inf"} 2 datasaver_backup_duration_seconds_sum 1.2345 datasaver_backup_duration_seconds_count 2 # HELP datasaver_backup_size_bytes Gauge of last backup size # TYPE datasaver_backup_size_bytes gauge datasaver_backup_size_bytes 10485760 # HELP datasaver_backups_total Counter of total backup attempts # TYPE datasaver_backups_total counter datasaver_backups_total 5 # HELP datasaver_backup_failures_total Counter of failed backups # TYPE datasaver_backup_failures_total counter datasaver_backup_failures_total 1 # HELP datasaver_last_backup_timestamp Gauge of last backup time # TYPE datasaver_last_backup_timestamp gauge datasaver_last_backup_timestamp 1673779215 # HELP datasaver_last_backup_success Gauge (1=success, 0=failure) # TYPE datasaver_last_backup_success gauge datasaver_last_backup_success 1 # HELP datasaver_storage_used_bytes Gauge of total storage used # TYPE datasaver_storage_used_bytes gauge datasaver_storage_used_bytes 524288000 ``` ``` -------------------------------- ### Querying Datasaver Health Endpoint Source: https://context7.com/localrivet/datasaver/llms.txt This command queries the Datasaver health endpoint to retrieve the current status of the backup system. The response includes the system's status ('healthy' or 'unhealthy'), the timestamp of the last backup, and the scheduled time for the next backup. An unhealthy response may also include the last error encountered. ```bash # Query health endpoint curl http://localhost:8080/health # Expected response: # status: healthy # last_backup: 2024-01-15T02:00:15Z # next_backup: 2024-01-16T02:00:00Z # Unhealthy response (503 status): # status: unhealthy # last_backup: 2024-01-15T02:00:15Z # last_error: database dump failed: connection refused # next_backup: 2024-01-16T02:00:00Z ``` -------------------------------- ### verify_backup Tool Source: https://github.com/localrivet/datasaver/blob/main/docs/mcp-integration.md Verifies the integrity of a specified backup. ```APIDOC ## POST /mcp/tools/verify_backup ### Description Verifies backup integrity. ### Method POST ### Endpoint `/mcp/tools/verify_backup` ### Parameters #### Request Body - **name** (string) - Required - The name of the tool, must be "verify_backup". - **arguments** (object) - Required - Contains arguments for the tool. - **backup_id** (string) - Required - The ID of the backup to verify. ### Request Example ```json { "name": "verify_backup", "arguments": { "backup_id": "20240115-020000" } } ``` ### Response #### Success Response (200) - **result** (object) - The result of the verification operation. - **is_valid** (boolean) - True if the backup is valid, false otherwise. - **error** (string) - An error message if the operation failed. #### Response Example ```json { "result": { "is_valid": true }, "error": null } ``` ``` -------------------------------- ### get_status Tool Source: https://github.com/localrivet/datasaver/blob/main/docs/mcp-integration.md Retrieves the current status of the backup system. ```APIDOC ## POST /mcp/tools/get_status ### Description Gets the current backup system status. ### Method POST ### Endpoint `/mcp/tools/get_status` ### Parameters #### Request Body - **name** (string) - Required - The name of the tool, must be "get_status". - **arguments** (object) - Required - An empty object for this tool. ### Request Example ```json { "name": "get_status", "arguments": {} } ``` ### Response #### Success Response (200) - **result** (object) - The status of the backup system. - **status** (string) - The current status (e.g., "idle", "running", "error"). - **message** (string) - A detailed message about the status. - **error** (string) - An error message if the operation failed. #### Response Example ```json { "result": { "status": "idle", "message": "Backup system is ready." }, "error": null } ``` ``` -------------------------------- ### Backup Metadata JSON Format Source: https://github.com/localrivet/datasaver/blob/main/prd.md Defines the structure of the metadata JSON file included in each backup. It contains information about the backup's ID, timestamp, database details, backup method, compression, size, duration, checksum, file list, and retention policy. ```json { "id": "backup_20240111_020015", "timestamp": "2024-01-11T02:00:15Z", "type": "daily", "database": { "name": "mydb", "host": "postgres", "version": "16.1" }, "backup": { "method": "pg_dump", "format": "custom", "compression": "gzip", "size_bytes": 131621888, "compressed_size_bytes": 45678912, "duration_seconds": 12.5, "checksum": "sha256:abcd1234..." }, "files": [ "backup_20240111_020015.dump.gz", "backup_20240111_020015.meta.json" ], "retention": { "keep_until": "2024-02-11T02:00:15Z", "policy": "daily" } } ```