Skip to content

Conversation

@VineethReddy02
Copy link

@VineethReddy02 VineethReddy02 commented Nov 7, 2025

Working example:

$ tiger db restore public_schema_dump.sql cjfk38bq1w
⚙️  Preparing restore...
📦 Restoring database...

✓ Restore completed in 1.4s

📊 1 table • 3 views • 1005 functions • 1 sequence • 1 index
📈 10.0K rows

Detailed Upload CMD functionality:

$ tiger db restore --help
Restore a PostgreSQL database from a dump file to a database service.

The service ID can be provided as an argument or will use the default service
from your configuration.

Supports multiple dump formats:
  - Plain SQL (.sql, .sql.gz) - Restored using psql
  - Custom format (.dump, .custom) - Restored using pg_restore
  - Tar format (.tar) - Restored using pg_restore
  - Directory format - Restored using pg_restore

For TimescaleDB databases, automatically detects and runs pre_restore() and
post_restore() hooks for optimal hypertable restoration.

Cloud-Friendly Defaults:
  - Continues past benign errors (like "already exists") by default
  - Uses --no-owner and --no-privileges for custom/tar/directory formats
  - Performs preflight checks before starting restore

Examples:
  # Restore plain SQL dump to default service
  tiger db restore backup.sql

  # Restore to specific service
  tiger db restore backup.sql svc-12345

  # Restore custom format dump with 4 parallel jobs (faster)
  tiger db restore backup.dump --jobs 4

  # Read from stdin
  pg_dump -Fc mydb | tiger db restore - --format custom

  # Clean existing objects before restore (DESTRUCTIVE - requires confirmation)
  tiger db restore backup.sql --clean --if-exists

  # Stop on first error (not recommended for cloud environments)
  tiger db restore backup.sql --on-error-stop

  # Verbose mode for debugging
  tiger db restore backup.sql --verbose

Note for AI agents: This command may be destructive when used with --clean.
Always confirm with the user before executing, especially with --clean flag.

Usage:
  tiger db restore <file-path> [service-id] [flags]

Flags:
      --clean                  Drop database objects before recreating (DESTRUCTIVE)
      --confirm                Skip confirmation prompts (for automation)
  -d, --database string        Target database name (defaults to tsdb)
      --format string          Dump format: plain, custom, directory, tar (auto-detected if not specified)
  -h, --help                   help for restore
      --if-exists              Use IF EXISTS when dropping objects (use with --clean)
  -j, --jobs int               Parallel restore jobs (for custom/directory/tar formats only) (default 1)
      --no-owner               Skip restoration of object ownership (recommended for cloud) (default true)
      --no-privileges          Skip restoration of access privileges (recommended for cloud) (default true)
      --no-timescaledb-hooks   Disable TimescaleDB hooks (even if detected)
      --on-error-stop          Stop on first error (default: continue past errors like 'already exists')
      --quiet                  Suppress progress output
      --role string            Database role/username (default "tsdbadmin")
      --single-transaction     Wrap restore in a single transaction (slower but safer)
      --timescaledb-hooks      Force enable TimescaleDB pre/post restore hooks
      --verbose                Show detailed restore process

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive database restore functionality to the tiger CLI, enabling users to restore PostgreSQL/TimescaleDB databases from various dump formats. The implementation includes automatic format detection, TimescaleDB hook support, and cloud-friendly defaults.

Key Changes

  • Added restore command (tiger db restore) with support for multiple dump formats (plain SQL, custom, tar, directory)
  • Implemented preflight validation, connection management, and progress tracking
  • Added TimescaleDB-specific pre/post restore hooks for optimal hypertable restoration

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/tiger/restore/restore.go Core restore orchestration logic with workflow management
internal/tiger/restore/psql.go Plain SQL restore using psql with statistics collection
internal/tiger/restore/pg_restore.go Custom/tar/directory format restore using pg_restore
internal/tiger/restore/preflight.go Pre-flight validation and service connectivity checks
internal/tiger/restore/format.go Dump format detection from file content and extensions
internal/tiger/restore/timescaledb.go TimescaleDB pre/post restore hook execution
internal/tiger/restore/util.go Utility functions for formatting and error handling
internal/tiger/restore/confirm.go User confirmation prompts for destructive operations
internal/tiger/restore/psql_test.go Unit tests for formatting and pluralization functions
internal/tiger/cmd/db.go CLI command definition with flags and documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

VineethReddy02 and others added 5 commits November 8, 2025 16:57
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Vineeth Pothulapati <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Vineeth Pothulapati <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Vineeth Pothulapati <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Vineeth Pothulapati <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant