Skip to content

Latest commit

 

History

History
164 lines (115 loc) · 3.31 KB

File metadata and controls

164 lines (115 loc) · 3.31 KB

Medusa Backup (Forked & Enhanced)

Medusa backup logo

Medusa Backup (Enhanced Fork)

Database backup plugin for Medusa v2.10+ with improved reliability


✨ What’s New in This Fork

This project is a fork of AmeerRizvi/medusa-backup, updated and optimized with the following improvements:

  • ✅ Full compatibility with Medusa v2.10+
  • Automatic rollback → if a backup fails midway, the database is safely restored to its previous state

🚀 Installation

If published under your npm scope (example: @anubus298/medusa-backup):

npm i @anubus298/medusa-backup

Or install directly from GitHub:

npm install github:anubus298/medusa-backup

⚙️ Configuration

medusa.config.ts

module.exports = defineConfig({
  ...,
  plugins: [
    {
      resolve: "@anubus298/medusa-backup",
      options: {},
    },
  ],
})

Run database migrations:

npx medusa db:migrate

🔑 Environment Variables

Default setup:

DATABASE_URL=postgres://[USERNAME]:[PASSWORD]@[HOST]/[DB]

If you separate the DB base and name:

DB_BASE=postgres://[USERNAME]:[PASSWORD]@[HOST]
DB_NAME=[DB]

🛠 Requirements

  • PostgreSQL client (pg_dump) must be installed:

    pg_dump --version
  • S3 configuration must be set up as described in Medusa documentation.

Example S3 config in medusa.config.ts:

module.exports = defineConfig({
  modules: [
    {
      resolve: "@medusajs/medusa/file",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/file-s3",
            id: "s3",
            options: {
              file_url: process.env.S3_FILE_URL,
              access_key_id: process.env.S3_ACCESS_KEY_ID,
              secret_access_key: process.env.S3_SECRET_ACCESS_KEY,
              region: process.env.S3_REGION,
              bucket: process.env.S3_BUCKET,
              endpoint: process.env.S3_ENDPOINT,
              prefix: "resources/",
            },
          },
        ],
      },
    },
  ],
})

🔄 Automatic Backups

Enable automatic backups in .env:

DB_BACKUP_AUTO=true

Default schedule: daily at 1 AM. Customize with CRON:

DB_BACKUP_SCHEDULE="0 1 * * *"

For more details, see crontab.guru. ⚠️ Automatic backups run only in production.

📝 Notes

  • Backups are compressed (~70% smaller size).
  • Backup failures are now handled gracefully with rollback support.
  • PostgreSQL version should match your installed pg_dump and psql tools.
  • Safe to restore production backups into local environments for testing.

📜 Changelog

v2.10.x+

  • Added compatibility with Medusa v2.10+
  • Introduced rollback mechanism for failed backups
  • Optimized performance of backup creation

🙏 Credits

Forked from AmeerRizvi/medusa-backup. Big thanks to the original author for building the foundation of this plugin.