Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Db Snapshots Laravel Package

spatie/laravel-db-snapshots

Laravel package that adds Artisan commands to quickly create, load, list, and clean up database snapshots (dumps) for your app. Works with MySQL, PostgreSQL, and SQLite—ideal for resetting state in development or tests.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Database-Centric Workflow: The package is a perfect fit for Laravel applications requiring database state management (e.g., CI/CD pipelines, local development, testing, or rollback scenarios). It abstracts raw SQL dump/load operations into Laravel’s Artisan CLI, aligning with Laravel’s command-driven architecture.
  • Event-Driven Extensibility: Built-in events (CreatingSnapshot, LoadedSnapshot, etc.) allow custom pre/post-processing (e.g., notifications, logging, or triggering sidecar services). This enables integration with monitoring tools (e.g., Datadog), workflow orchestration (e.g., GitHub Actions), or audit trails.
  • Multi-DB Support: Supports MySQL, PostgreSQL, SQLite, and MariaDB, making it versatile for microservices or polyglot persistence setups. The --connection flag enables targeted snapshots (e.g., snapshot:create --connection=replica).
  • Selective Dumping: Fine-grained control via --table/--exclude flags reduces snapshot size and speeds up operations, critical for large databases or partial state restoration.

Integration Feasibility

  • Laravel Native: Zero boilerplate—works out-of-the-box with Laravel’s service container, filesystem, and database configurations. No external dependencies beyond spatie/db-dumper (v4+).
  • Configuration-Driven: Centralized settings in config/db-snapshots.php allow environment-specific overrides (e.g., compress: true in staging, false in dev).
  • Artisan Integration: Commands (snapshot:create, snapshot:load) fit Laravel’s CLI ecosystem, enabling CI/CD automation (e.g., php artisan snapshot:create pre-prod-backup in a deploy script).
  • Storage Agnostic: Uses Laravel’s filesystem (default: local disk), enabling S3/Cloud storage for backups via config/filesystems.php.

Technical Risk

Risk Area Assessment Mitigation
Large Database Performance Streaming (--stream) and compression (--compress) mitigate memory/IO bottlenecks, but large tables may still cause timeouts. Benchmark with production-like data; use --stream for loads >1GB. Consider partial snapshots (e.g., --table=users,orders) or chunked loading (custom event listeners).
Schema Migrations Snapshots do not include migrations. Loading a snapshot onto a mismatched schema (e.g., missing tables) will fail. Enforce schema versioning (e.g., schema_migrations table) or use migration locks in CI/CD.
Concurrency Not thread-safe. Concurrent snapshot:load operations may corrupt the database. Use database locks (e.g., DB::transaction() with lock_timeout) or queue delayed jobs for non-critical loads.
Cross-Environment Compatibility Snapshots may fail if DBMS versions (e.g., PostgreSQL 12 → 15) or collations differ between environments. Test snapshots across environments; use --no-owner (PostgreSQL) or --skip-triggers (MySQL) flags where needed.
Security Snapshots contain plaintext data. Storing in cloud storage (e.g., S3) requires encryption. Enable S3 server-side encryption or client-side encryption (e.g., Laravel Encryption). Restrict IAM permissions for snapshot storage.

Key Questions for Stakeholders

  1. Use Case Prioritization:

    • Will snapshots be used for development reset, CI/CD rollback, or disaster recovery? This dictates retention policies (e.g., snapshot:cleanup --keep=5).
    • Are there compliance requirements (e.g., GDPR) for snapshot retention/deletion?
  2. Environment Scope:

    • Should snapshots be environment-specific (e.g., dev_2024-05-01.sql) or shared across environments?
    • How will multi-tenant databases (e.g., shared schema) be handled? (Hint: Use --connection or custom event listeners to filter data.)
  3. Performance SLAs:

    • What is the maximum acceptable duration for snapshot:load in production? (Test with --stream and --compress.)
    • Are there peak hours when snapshots should be avoided?
  4. Monitoring & Alerting:

    • Should failed snapshots trigger Slack/PagerDuty alerts? (Use events + Laravel Notifications.)
    • How will snapshot metadata (e.g., size, duration) be logged for auditing?
  5. Disaster Recovery:

    • Is there a fallback plan if snapshots are corrupted or inaccessible?
    • Should snapshots be geographically replicated (e.g., S3 cross-region)?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Seamless integration with:
    • Artisan: Extend existing CLI workflows (e.g., php artisan migrate --seed && php artisan snapshot:create pre-migration).
    • Events: Hook into CreatedSnapshot to trigger webhooks (e.g., notify a backup service) or database observers.
    • Filesystem: Leverage Laravel’s disk system for local/S3 backups with minimal config changes.
    • Testing: Use snapshot:load in PHPUnit/Pest tests to reset state (e.g., @beforeEach fn() => $this->loadSnapshot('fresh_db')).
  • CI/CD Pipelines:
    • GitHub Actions: Add steps like:
      - name: Create snapshot before deploy
        run: php artisan snapshot:create pre-deploy-$(date +%s)
      
    • Rollback: Use snapshot:load in deployment scripts if health checks fail.
  • DevOps Tools:
    • Terraform: Store snapshot paths in state for infrastructure-as-code recovery.
    • Prometheus: Expose snapshot metrics (e.g., snapshot_duration_seconds) via custom events.

Migration Path

Phase Action Tools/Commands
Assessment Audit current backup strategy (e.g., mysqldump, custom scripts). Identify gaps (e.g., no selective table dumps, no compression). php artisan snapshot:list (post-install to verify compatibility).
Pilot Test in non-production (e.g., staging) with:
  • Selective table snapshots (--table=users,orders).
  • Compression (--compress) for large DBs.
  • Event listeners for logging. | php artisan snapshot:create pilot-snapshot --compress; monitor performance. | | Integration | Replace legacy backup scripts with Artisan commands. | Replace mysqldump cron jobs with php artisan schedule:run (if using Laravel Scheduler). | | Automation | Embed snapshots in:
  • Deploy scripts (pre/post-deploy hooks).
  • CI pipelines (e.g., create snapshot before destructive tests).
  • Monitoring alerts (e.g., fail snapshot if DB size > threshold). | Custom Artisan commands or Laravel Events. | | Optimization | Tune for production:
  • Adjust temporary_directory_path to high-I/O storage.
  • Use --stream for loads >500MB.
  • Set up automated cleanup (e.g., snapshot:cleanup --keep=30 --daily). | php artisan snapshot:cleanup --dry-run to validate policies. |

Compatibility

Component Compatibility Notes Workarounds
Laravel Versions Supports Laravel 10–13 (and PHP 8.1+). Use ^2.7 for Laravel 11/12; ^2.8 for Laravel 13.
Database Drivers MySQL, PostgreSQL, SQLite, MariaDB. No SQL Server. For SQL Server, consider spatie/db-dumper directly or a custom wrapper.
Storage Backends Local, S3, FTP, etc. (via Laravel Filesystem). Configure snapshots disk in config/filesystems.php.
Custom DB Configs Supports `dump.addExtraOption
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata