smoonb 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,644 +1,663 @@
1
- # Supa Moonbase (smoonb)
2
-
3
- **Complete Supabase backup and migration tool**
4
-
5
- Backup and restore: complete and simple, as it should be
6
-
7
- > **Commercial product.** You need an **active license** and a **valid subscription** (or be on a trial period) to use smoonb. [www.smoonb.com/#price](https://www.smoonb.com/#price). Use is governed by the [Terms of Service](https://www.smoonb.com/terms) and [Privacy Policy](https://www.smoonb.com/privacy). We do not assume any liability for damage caused by smoonb; the legal disclaimers below remain in effect.
8
-
9
- **Read this in other languages:** [Português (Brasil)](README.pt-BR.md)
10
-
11
- **Developed by:** Goalmoon Tecnologia LTDA
12
- **Website:** https://www.smoonb.com
13
- **GitHub:** https://github.com/almmello/smoonb
14
-
15
- ## 🎯 Objective
16
-
17
- **smoonb** solves the problem of existing tools that only backup the PostgreSQL database, ignoring critical Supabase components.
18
-
19
- ## 📦 Backup Components
20
-
21
- smoonb performs a complete backup of all components of your Supabase project:
22
-
23
- - ✅ **Database PostgreSQL** (backup completo via `pg_dumpall` + SQL separados, idêntico ao Dashboard)
24
- - ✅ **Database Extensions and Settings** (extensões PostgreSQL e configurações)
25
- - ✅ **Custom Roles** (roles personalizados do PostgreSQL)
26
- - ✅ **Edge Functions** (download automático do servidor)
27
- - ✅ **Auth Settings** (configurações de autenticação via Management API)
28
- - ✅ **Storage Buckets** (backup completo: metadados, configurações e todos os arquivos via Management API + Supabase Client, cria ZIP no padrão do Dashboard)
29
- - ✅ **Realtime Settings** (7 parâmetros capturados interativamente)
30
- - ✅ **Supabase .temp** (arquivos temporários do Supabase CLI)
31
- - ✅ **Migrations** (todas as migrations do projeto via `supabase migration fetch`)
32
-
33
- ## ⚠️ Universal Disclaimer / Legal Notice
34
-
35
- By continuing, you acknowledge and agree that Supa Moonbase (smoonb) is provided "AS IS" and "AS AVAILABLE", with no warranties of any kind—express, implied, or statutory—including but not limited to merchantability, fitness for a particular purpose, and non-infringement, to the maximum extent permitted by applicable law. Backup and restore operations inherently carry risk, environments vary widely, and we cannot foresee or validate all user setups. You are solely responsible for validating your own environment, keeping independent copies, and verifying results before relying on them in production. We build Supa Moonbase (smoonb) on public, auditable, open-source repositories to help people simplify their workflows, but this does not create any warranty, promise of support, or service-level commitment.
36
-
37
- **Limitation of liability** — To the maximum extent permitted by law, Goalmoon Tecnologia LTDA, its contributors, and licensors will not be liable for any indirect, incidental, special, consequential, exemplary, or punitive damages (including loss of data, interruption of business, or lost profits) arising from or related to the use of, inability to use, backup/restore operations performed by, or results produced by Supa Moonbase (smoonb).
38
-
39
- ## 🚀 Installation
40
-
41
- **⚠️ IMPORTANT: Install ONLY locally in the project!**
42
-
43
- **Install locally in the project:**
44
- ```bash
45
- npm install smoonb
46
- ```
47
-
48
- **Use with npx:**
49
- ```bash
50
- npx smoonb --help
51
- ```
52
-
53
- **Do not install globally** (blocked):
54
- ```bash
55
- npm install -g smoonb
56
- ```
57
-
58
- ### 🔄 Update to Latest Version
59
-
60
- To update smoonb to the latest available version, run in the current project:
61
-
62
- ```bash
63
- npm install smoonb@latest
64
- ```
65
-
66
- **⚠️ IMPORTANT:** smoonb must be installed locally in the project. Using without installing (e.g., `npx smoonb@latest`) is not allowed.
67
-
68
- **💡 Why local only?**
69
- - **🔒 Security**: Avoids version conflicts
70
- - **📦 Isolation**: Each project uses its own version
71
- - **🔄 Updates**: Granular control per project
72
- - **🛡️ Stability**: Prevents breaking other projects
73
-
74
- ## 📋 Prerequisites
75
-
76
- ### 1. Docker Desktop (REQUIRED)
77
-
78
- Install from [Docker Desktop](https://docs.docker.com/desktop/install/) (Windows/macOS) or [Docker Engine](https://docs.docker.com/engine/install/) (Linux). Then verify it is running:
79
-
80
- ```bash
81
- docker --version
82
- docker ps
83
- ```
84
-
85
- **⚠️ IMPORTANT:** Docker is required for:
86
- - Database backup via `pg_dumpall` (compatible with Supabase Dashboard)
87
- - Compression of `.backup.gz` files
88
- - Restoration of `.backup` and `.backup.gz` backups
89
-
90
- ### 2. Supabase CLI
91
- ```bash
92
- npm install -g supabase
93
- ```
94
-
95
- **Version policy:** smoonb accepts any Supabase CLI version that is **at most 1 minor behind the latest** (same major). We recommend always using the latest version. Versions that are too old are blocked with an error message.
96
-
97
- If your package manager (e.g. **Scoop** on Windows) lags behind on updates and you want to proceed anyway, use the `--skip-supabase-version-check` flag (see usage section below).
98
-
99
- To update the Supabase CLI: [Updating the Supabase CLI](https://supabase.com/docs/guides/cli/getting-started#updating-the-supabase-cli).
100
-
101
- ### 3. Supabase Personal Access Token
102
- You need to obtain a Supabase personal access token to use the Management API:
103
-
104
- 1. Visit: https://supabase.com/dashboard/account/tokens
105
- 2. Click "Generate new token"
106
- 3. Copy the token (format: `sbp_...`)
107
- 4. Add to `.env.local` as `SUPABASE_ACCESS_TOKEN`
108
-
109
- ### 4. License Key (REQUIRED for backup and restore)
110
- **smoonb** requires a valid license to run backup and restore:
111
-
112
- 1. Get your license from the desktop app at https://www.smoonb.com
113
- 2. Set in environment or `.env.local`: `SMOONB_LICENSE_KEY=[your-license-key]`
114
- 3. License is validated at the start of each run (step 00); no caching. If validation fails (network/server), the CLI aborts. The license is **not** shown in the interactive variable-mapping wizard (it is already validated before that).
115
-
116
- ## ⚙️ Configuration
117
-
118
- ### Modern Method: `.env.local` (RECOMMENDED)
119
-
120
- **smoonb** now uses `.env.local` for configuration, following industry standards. This makes the process simpler and more integrated with your workflow.
121
-
122
- #### 1. Create or edit `.env.local` in the project root
123
-
124
- ```bash
125
- touch .env.local
126
- ```
127
-
128
- #### 2. Add required environment variables
129
-
130
- ```env
131
- SMOONB_LICENSE_KEY=[your-license-key]
132
- NEXT_PUBLIC_SUPABASE_URL=[your-supabase-url]
133
- NEXT_PUBLIC_SUPABASE_ANON_KEY=[your-anon-key]
134
- SUPABASE_SERVICE_ROLE_KEY=[your-service-role]
135
- SUPABASE_DB_URL=postgresql://postgres:[your-database-password]@db.[your-project-id].supabase.co:5432/postgres
136
- SUPABASE_PROJECT_ID=[your-project-id]
137
- SUPABASE_ACCESS_TOKEN=[your-access-token]
138
- SUPABASE_POSTGRES_MAJOR=17
139
- SMOONB_TELEMETRY_ENABLED=true
140
- SMOONB_OUTPUT_DIR=./backups
141
- ```
142
-
143
- Required: `SMOONB_LICENSE_KEY` (from [www.smoonb.com](https://www.smoonb.com) desktop app), `SUPABASE_POSTGRES_MAJOR` (e.g. 17; see Dashboard → Project Settings → Infrastructure → Service Versions). Optional: `SMOONB_TELEMETRY_ENABLED`, `SMOONB_OUTPUT_DIR` (default `./backups`).
144
-
145
- #### 3. Interactive Mapping
146
-
147
- When running `backup` or `restore` for the first time, **smoonb** will:
148
-
149
- 1. **Read** your current `.env.local`
150
- 2. **Identify** the keys you already have
151
- 3. **Ask interactively** which keys correspond to the expected ones (if names are different)
152
- 4. **Add** missing keys if necessary
153
- 5. **Create automatic backup** of `.env.local` before any changes
154
- 6. **Save mapping** for future executions
155
-
156
- **Mapping example:**
157
- ```
158
- 🔧 Mapping variable: NEXT_PUBLIC_SUPABASE_URL
159
- Current value: https://abc123.supabase.co
160
- Is this the correct value for the target project? (Y/n): Y
161
- ```
162
-
163
- ## 🌐 Internationalization (i18n)
164
-
165
- **smoonb** supports multiple languages automatically. Currently supported languages are:
166
-
167
- - **English (en)** - Default language
168
- - **Portuguese (Brazil) (pt-BR)** - Full support
169
-
170
- ### Automatic Language Detection
171
-
172
- Language is detected automatically in the following order of precedence:
173
-
174
- 1. **Environment variable `SMOONB_LANG`** (in `.env.local` or in the environment)
175
- 2. **System locale** (LANG, LC_ALL, LC_MESSAGES). Example: `LANG=pt_BR.UTF-8` → pt-BR
176
- 3. **Fallback to English (en)** if none of the above are detected
177
-
178
- ### Supported Languages and Aliases
179
-
180
- - `en` or `en-US` → English
181
- - `pt-BR`, `pt_BR` or `pt` → Portuguese (Brazil)
182
-
183
- ### Important Notes
184
-
185
- - **Machine outputs** (e.g., `--json` if implemented) are **not** translated; fields and keys remain in English
186
- - If a translation key is missing in a language, the system automatically **falls back to English**
187
- - Language is detected once at the start of execution and applied to all CLI messages
188
-
189
- ## 🎯 Usage
190
-
191
- ### Full Backup
192
-
193
- ```bash
194
- npx smoonb backup
195
- ```
196
-
197
- **Available options:**
198
-
199
- | Flag | Description |
200
- |------|-------------|
201
- | `--skip-supabase-version-check` | Skips the Supabase CLI version check. Use when your package manager (e.g. Scoop) lags behind on updates. A warning is shown and the user assumes the risk. |
202
-
203
- **Example with flag:**
204
- ```bash
205
- npx smoonb backup --skip-supabase-version-check
206
- ```
207
-
208
- **Interactive backup flow:**
209
-
210
- 1. **Terms of use** - Displays and requests acceptance of terms
211
- 2. **License validation** - Validates `SMOONB_LICENSE_KEY` (env or prompt); no cache; aborts if validation fails
212
- 3. **Docker validation** - Verifies if Docker is running
213
- 4. **Consent** - Asks permission to read/write `.env.local`
214
- 5. **Variable mapping** - Maps your environment variables (first time; license is not in the wizard—already validated)
215
- 6. **.env.local backup** - Creates automatic backup before changes
216
- 7. **Component selection** - Asks which components to include:
217
- - ⚡ Edge Functions (explanation about link reset and download)
218
- - 📦 Storage (explanation about full backup: file download + ZIP in Dashboard format)
219
- - 🔐 Auth Settings (explanation about configurations)
220
- - 🔄 Realtime Settings (explanation about interactive capture of 7 parameters)
221
- - 🗑️ Cleanup options (functions, .temp, migrations after backup)
222
- 8. **Configuration summary** - Shows everything that will be done
223
- 9. **Final confirmation** - Confirms before starting
224
- 10. **Step execution:**
225
- - 📊 1/10 - Database Backup via `pg_dumpall` (Docker)
226
- - 📊 2/10 - Separate Database SQL (schema, data, roles)
227
- - 🔧 3/10 - Database Extensions and Settings Backup
228
- - 🔐 4/10 - Auth Settings Backup (if selected)
229
- - 🔄 5/10 - Realtime Settings Backup (if selected) - 7 parameters captured interactively
230
- - 📦 6/10 - Storage Backup (if selected) - Full file download + ZIP in Dashboard format
231
- - 👥 7/10 - Custom Roles Backup
232
- - ⚡ 8/10 - Edge Functions Backup (if selected)
233
- - 📁 9/10 - Supabase .temp Backup (if selected)
234
- - 📋 10/10 - Migrations Backup (if selected)
235
-
236
- **Result:** A folder `backups/backup-YYYY-MM-DD-HH-MM-SS/` containing for example:
237
-
238
- ```
239
- backups/backup-2025-10-31-09-37-54/
240
- ├── backup-manifest.json
241
- ├── db_cluster-31-10-2025@09-38-57.backup.gz
242
- ├── schema.sql
243
- ├── data.sql
244
- ├── roles.sql
245
- ├── database-settings-*.json
246
- ├── auth-settings.json
247
- ├── realtime-settings.json
248
- ├── storage/
249
- │ └── [bucket-name].json
250
- ├── [project-id].storage.zip
251
- ├── storage_temp/
252
- │ └── [project-id]/
253
- │ └── [bucket-name]/
254
- ├── edge-functions/
255
- │ └── [function-name]/
256
- ├── supabase-temp/
257
- ├── migrations/
258
- └── env/
259
- ├── .env.local
260
- └── env-map.json
261
- ```
262
-
263
- ### Interactive Restoration
264
-
265
- **Restore existing backup:**
266
- ```bash
267
- npx smoonb restore
268
- ```
269
-
270
- **Available options:**
271
-
272
- | Flag | Description |
273
- |------|-------------|
274
- | `--skip-supabase-version-check` | Skips the Supabase CLI version check. Use when your package manager (e.g. Scoop) lags behind on updates. A warning is shown and the user assumes the risk. |
275
-
276
- **Example with flag:**
277
- ```bash
278
- npx smoonb restore --skip-supabase-version-check
279
- ```
280
-
281
- **Interactive restore flow:**
282
-
283
- 1. **Terms of use** - Displays and requests acceptance of terms
284
- 2. **License validation** - Validates `SMOONB_LICENSE_KEY` (env or prompt); aborts if validation fails
285
- 3. **Docker validation** - Verifies if Docker is running
286
- 4. **Consent** - Asks permission to read/write `.env.local`
287
- 5. **Variable mapping** - Maps variables to target project (includes `SUPABASE_POSTGRES_MAJOR`)
288
- 6. **.env.local backup** - Creates automatic backup
289
- 7. **Backup selection** - Lists and allows choosing which backup to restore
290
- 8. **Component selection** - Asks which components to restore:
291
- - 📊 Database (always available)
292
- - ⚡ Edge Functions (if available in backup)
293
- - 🔐 Auth Settings (if available in backup)
294
- - 📦 Storage (if available in backup)
295
- - 🔧 Database Extensions and Settings (if available in backup)
296
- - 🔄 Realtime Settings (if available in backup)
297
- 9. **Detailed summary** - Shows selected backup, target project and components
298
- 10. **Final confirmation** - Confirms before starting
299
- 11. **Disclaimer** - Explains that errors during restore are expected; link to [Supabase Dashboard Restore docs](https://supabase.com/docs/guides/platform/migrating-within-supabase/dashboard-restore); you should wait for the process to finish and then test the result before accepting to proceed
300
- 12. **Restore execution:**
301
- - 📊 Database - Restores via `psql` (supports `.backup.gz` and `.backup`)
302
- - ⚡ Edge Functions - Copies and deploys to target project
303
- - 🔐 Auth Settings - Displays configurations for manual application
304
- - 📦 Storage - Restores buckets and files from ZIP (if available) or displays information for manual migration
305
- - 🔧 Database Settings - Restores extensions and settings via SQL
306
- - 🔄 Realtime Settings - Displays configurations for manual application
307
-
308
- **Supported file formats:**
309
- - ✅ `.backup.gz` (compressed) - Automatically decompresses before restoring
310
- - ✅ `.backup` (uncompressed) - Restores directly
311
-
312
- ### Import Backup from Supabase Dashboard
313
-
314
- If you downloaded a backup directly from the Supabase Dashboard (`.backup.gz` format), you can import it to the format expected by smoonb. The command also supports optionally importing storage files (`.storage.zip`).
315
-
316
- **Import database only:**
317
- ```bash
318
- npx smoonb import --file "full/path/to/db_cluster-04-03-2024@14-16-59.backup.gz"
319
- ```
320
-
321
- **Import database and storage together:**
322
- ```bash
323
- npx smoonb import --file "backup.backup.gz" --storage "my-project.storage.zip"
324
- ```
325
-
326
- **What the command does:**
327
- 1. Reads the `.backup.gz` file from Dashboard (required)
328
- 2. If provided, reads the `.storage.zip` file from Dashboard (optional)
329
- 3. Extracts information from backup file name (date and time)
330
- 4. Creates a backup folder in expected format (`backup-YYYY-MM-DD-HH-MM-SS`)
331
- 5. Copies backup file to created folder
332
- 6. If provided, copies storage file to same folder
333
- 7. Makes backup ready to be found by `restore` command
334
-
335
- **Complete example - Database only (using import + restore):**
336
-
337
- 1. Download backup from Supabase Dashboard (e.g. `db_cluster-04-03-2024@14-16-59.backup.gz`).
338
- 2. Import the file, then restore:
339
-
340
- ```bash
341
- npx smoonb import --file "C:\Downloads\db_cluster-04-03-2024@14-16-59.backup.gz"
342
- npx smoonb restore
343
- ```
344
-
345
- The imported backup will appear in the list of available backups.
346
-
347
- **Complete example - Database and Storage (using import + restore):**
348
-
349
- 1. Download backup and storage from Supabase Dashboard (e.g. `db_cluster-04-03-2024@14-16-59.backup.gz` and `my-project.storage.zip`).
350
- 2. Import both files, then restore:
351
-
352
- ```bash
353
- npx smoonb import --file "C:\Downloads\db_cluster-04-03-2024@14-16-59.backup.gz" --storage "C:\Downloads\my-project.storage.zip"
354
- npx smoonb restore
355
- ```
356
-
357
- The imported backup will appear in the list of available backups.
358
-
359
- **Important:**
360
- - Backup file is **required** and must be in Dashboard format: `db_cluster-DD-MM-YYYY@HH-MM-SS.backup.gz`
361
- - Storage file is **optional** and must be in format: `*.storage.zip`
362
- - Storage depends on a backup, but backup does not depend on storage
363
- - Both files will be copied to the same backup folder
364
- - Path can be absolute or relative
365
- - Command will automatically create necessary folder structure
366
-
367
- After running `import`, run `restore` to choose the imported backup from the list and restore it.
368
-
369
- ## 🔧 Available Commands
370
-
371
- | Command | Description |
372
- |---------|-------------|
373
- | `npx smoonb backup` | Full interactive backup using Docker |
374
- | `npx smoonb backup --skip-supabase-version-check` | Backup skipping the Supabase CLI version check |
375
- | `npx smoonb restore` | Interactive restoration using psql (Docker) |
376
- | `npx smoonb restore --skip-supabase-version-check` | Restore skipping the Supabase CLI version check |
377
- | `npx smoonb import --file <path> [--storage <path>]` | Import .backup.gz file and optionally .storage.zip from Supabase Dashboard |
378
-
379
- ## 🏗️ Technical Architecture
380
-
381
- ### Modular Structure
382
-
383
- The code has been refactored to a **modular architecture** with independent steps:
384
-
385
- #### Backup (`src/commands/backup/`)
386
- ```
387
- backup/
388
- ├── index.js
389
- ├── utils.js
390
- └── steps/
391
- ├── 00-license.js
392
- ├── 01-docker-validation.js
393
- ├── 02-database.js
394
- ├── 03-database-separated.js
395
- ├── 04-database-settings.js
396
- ├── 05-auth-settings.js
397
- ├── 06-realtime-settings.js
398
- ├── 07-storage.js
399
- ├── 08-custom-roles.js
400
- ├── 09-edge-functions.js
401
- ├── 10-supabase-temp.js
402
- └── 11-migrations.js
403
- ```
404
-
405
- #### Restore (`src/commands/restore/`)
406
- License validation (same as backup, `00-license.js` from backup steps) runs at start. Then:
407
- ```
408
- restore/
409
- ├── index.js
410
- ├── utils.js
411
- └── steps/
412
- ├── 00-backup-selection.js
413
- ├── 01-components-selection.js
414
- ├── 02-confirmation.js
415
- ├── 03-database.js
416
- ├── 04-edge-functions.js
417
- ├── 05-auth-settings.js
418
- ├── 06-storage.js
419
- ├── 07-database-settings.js
420
- └── 08-realtime-settings.js
421
- ```
422
-
423
- ### Backup Strategy
424
-
425
- #### Database
426
- - **Main Backup**: `pg_dumpall` via Docker (identical to Dashboard)
427
- - File: `db_cluster-XX-XX-XXXX@XX-XX-XX.backup.gz`
428
- - Compatible with restoration via Supabase Dashboard
429
- - **Separate Backup**: SQL in separate files via Supabase CLI
430
- - `schema.sql` - Table structure
431
- - `data.sql` - Data (COPY statements)
432
- - `roles.sql` - Roles and permissions
433
-
434
- #### Edge Functions
435
- - **Automatic Download**: Via Supabase CLI `supabase functions download`
436
- - **Link Reset**: Ensures clean link with project before download
437
- - **Complete Backup**: Full code of each function
438
-
439
- #### Migrations
440
- - **Automatic Download**: Via `supabase migration fetch`
441
- - **Link Reset**: Ensures clean link with project
442
- - **Complete Backup**: All server migrations
443
-
444
- #### Storage
445
- - **Complete Backup**: Download of all files from all buckets
446
- - **Temporary Structure**: Creates `storage_temp/project-id/bucket-name/files...` inside backupDir
447
- - **ZIP in Dashboard Format**: Creates `{project-id}.storage.zip` with structure `project-id/bucket-name/files...`
448
- - **Restore Compatible**: Created ZIP is compatible with restore process (same format as Dashboard)
449
- - **Interactive Question**: After creating ZIP, asks if you want to clean temporary structure
450
- - **Fallback**: If Supabase credentials are not available, backs up metadata only
451
- - **Management API**: Uses Personal Access Token to list buckets and objects
452
- - **Supabase Client**: Uses Service Role Key for file downloads
453
-
454
- #### Auth, Realtime
455
- - **Management API**: Uses Personal Access Token
456
- - **JSON Export**: Configurations exported as JSON
457
- - **Realtime Settings**: Interactive capture of 7 parameters:
458
- 1. Enable Realtime service
459
- 2. Allow public access
460
- 3. Database connection pool size
461
- 4. Max concurrent clients
462
- 5. Max events per second
463
- 6. Max presence events per second
464
- 7. Max payload size in KB
465
- - **Manual for some**: Some settings need to be applied manually for security
466
-
467
- ### Restore Strategy
468
-
469
- #### Database
470
- - **Format Support**:
471
- - `.backup.gz` - Automatically decompresses via Docker
472
- - `.backup` - Restores directly via `psql` (Docker)
473
- - **Clean Restore**: Can overwrite existing data (with confirmation)
474
-
475
- #### Edge Functions
476
- - **Clean Deploy**: Cleans `supabase/functions` before deploy
477
- - **Link Reset**: Ensures correct link with target project
478
- - **Automatic Deploy**: Uses `supabase functions deploy`
479
-
480
- #### Other Components
481
- - **Database Settings**: Restores via SQL
482
- - **Storage**: Restores buckets and files from ZIP (if available) or displays information for manual configuration
483
- - **Auth/Realtime**: Displays information for manual configuration in Dashboard
484
-
485
- ### Cross-Platform
486
-
487
- - **Windows/macOS/Linux**: Automatic binary detection
488
- - **Cross-platform**: Uses `fs.promises.cp`, `path.join`, Docker
489
- - **Docker for Everything**: Backup, restore and compression via Docker (ensures consistency)
490
-
491
- ## 📊 Recommended Flow
492
-
493
- 1. **Configure `.env.local`** (first time) with your source project credentials.
494
- 2. **Backup source project:**
495
- ```bash
496
- npx smoonb backup
497
- ```
498
- (Maps variables interactively on first run, selects components, executes full backup.)
499
- 3. **Create new Supabase project** (via Dashboard or Supabase CLI).
500
- 4. **Edit `.env.local`** with new project credentials (point variables to target project).
501
- 5. **Restore backup** (interactive mode):
502
- ```bash
503
- npx smoonb restore
504
- ```
505
- (Select desired backup, select components, execute restoration.)
506
- 6. **Apply manual configurations** if necessary: Auth Settings (Dashboard → Authentication → Settings), Realtime (Dashboard → Database → Replication). Storage is restored automatically from ZIP when available.
507
-
508
- ## 🎨 User Experience
509
-
510
- ### Multi-Language Interface
511
-
512
- All interactions are **automatically translated** based on system locale or `SMOONB_LANG`:
513
- - Clear and direct questions
514
- - Explanations before each process
515
- - Detailed summaries before confirming
516
- - Confirmations with `(Y/n)` or `(y/N)` in English, `(S/n)` or `(s/N)` in Portuguese
517
-
518
- ### Intelligent Variable Mapping
519
-
520
- - **Automatic Detection**: If key already exists with expected name, skips selection
521
- - **Add Option**: Allows adding new keys if they don't exist
522
- - **Value Validation**: Confirms values before saving
523
- - **Automatic Backup**: Always creates backup of `.env.local` before changes
524
-
525
- ### Guided Process
526
-
527
- - **Prior Validation**: Verifies Docker before starting
528
- - **Contextual Explanations**: Explains each process before asking
529
- - **Final Summary**: Shows everything that will be done before executing
530
- - **Visual Feedback**: Colors and icons for better experience
531
-
532
- ## 🐛 Troubleshooting
533
-
534
- ### Docker not found or not running
535
-
536
- Verify Docker is installed and running:
537
-
538
- ```bash
539
- docker --version
540
- docker ps
541
- ```
542
-
543
- If not, start Docker Desktop (Windows/macOS) or run `sudo systemctl start docker` (Linux).
544
-
545
- ### Supabase CLI not found
546
- ```bash
547
- npm install -g supabase
548
- ```
549
-
550
- ### Supabase CLI outdated (below minimum accepted version)
551
-
552
- smoonb accepts versions up to **1 minor behind the latest**. If your installed version is below that threshold, you will see a message like:
553
-
554
- ```
555
- ❌ Supabase CLI X.Y.Z is below the minimum accepted version (X.W.0). Latest: X.V.Z. Update to at least version X.W.0.
556
- ```
557
-
558
- **Option 1 — Update the Supabase CLI:**
559
- ```bash
560
- npm install -g supabase@latest # global install
561
- npm install supabase@latest # local/project install
562
- ```
563
-
564
- **Option 2 — Skip the check (temporary, user assumes the risk):**
565
- ```bash
566
- npx smoonb backup --skip-supabase-version-check
567
- npx smoonb restore --skip-supabase-version-check
568
- ```
569
-
570
- > **Note for Scoop users (Windows):** the Scoop repository may take a few days to update after a release. Use `--skip-supabase-version-check` until Scoop ships the updated version.
571
-
572
- ### Invalid or missing Personal Access Token
573
-
574
- 1. Verify if `SUPABASE_ACCESS_TOKEN` is in `.env.local`
575
- 2. Generate new token: https://supabase.com/dashboard/account/tokens
576
- 3. Update `.env.local` with new token
577
-
578
- ### Incorrect Database URL
579
- - Verify password in connection URL
580
- - Use Connection string from Supabase Dashboard (Settings → Database)
581
- - Test connection: `psql "your-database-url" -c "SELECT 1"`
582
-
583
- ### .backup.gz file cannot be restored
584
-
585
- smoonb automatically supports:
586
- - ✅ `.backup.gz` - Decompresses via Docker before restoring
587
- - ✅ `.backup` - Restores directly
588
-
589
- If there are problems:
590
- 1. Verify if Docker is running
591
- 2. Verify file permissions
592
- 3. Verify disk space
593
-
594
- ### Error downloading Edge Functions
595
-
596
- 1. Verify if `SUPABASE_ACCESS_TOKEN` is configured
597
- 2. Verify if project is linked: `supabase link`
598
- 3. Verify if functions exist on server
599
-
600
- ### Error downloading Migrations
601
-
602
- 1. Verify if `SUPABASE_ACCESS_TOKEN` is configured
603
- 2. Verify if project is linked: `supabase link`
604
- 3. Verify if there are migrations on server
605
-
606
- ## 🔒 Security
607
-
608
- - **Automatic Backup**: Always creates backup of `.env.local` before changes
609
- - **Local Mapping**: Variable mapping saved only locally
610
- - **No Sensitive Data**: No sensitive data is sent outside your environment
611
- - **Isolated Docker**: Database operations via Docker (isolation)
612
-
613
- ## 💼 Access and subscription
614
-
615
- Supa Moonbase code is provided under MIT license (see `LICENSE`). To use smoonb you must have an **active license** and a **valid subscription**, or be within a **trial period**. License validation runs at the start of backup and restore; without a valid license and subscription (or trial), the CLI will not run those operations.
616
-
617
- [www.smoonb.com/#price](https://www.smoonb.com/#price).
618
-
619
- ## 🔒 Privacy and LGPD (summary)
620
-
621
- Supa Moonbase adopts the data minimization principle. We process only the information strictly necessary for access control and billing (e.g., account identifier and contact). Purposes, legal bases and data subject rights are described in the [Privacy Policy](https://www.smoonb.com/privacy).
622
-
623
- ## 📋 Terms of Service and brand usage
624
-
625
- The code license (MIT) does not replace the [Terms of Service](https://www.smoonb.com/terms) that govern operational access and subscription validation.
626
-
627
- "Supa Moonbase" and visual identity elements are trademarks of Goalmoon Tecnologia Ltda.; use of brand and branding assets is restricted as per [Terms of Service](https://www.smoonb.com/terms).
628
-
629
- [FAQ](https://www.smoonb.com/#faq).
630
-
631
- ## 📝 License
632
-
633
- Supa Moonbase code is provided under MIT license. See [LICENSE](LICENSE) for the full license text. A Portuguese translation is available in [LICENSE.pt-BR.md](LICENSE.pt-BR.md) for convenience only.
634
-
635
- ## 🤝 Contributing
636
-
637
- Contributions are welcome. [www.smoonb.com/#price](https://www.smoonb.com/#price).
638
-
639
-
640
- ---
641
-
642
- **Developed by:** Goalmoon Tecnologia LTDA
643
- **Website:** https://www.smoonb.com
644
- **GitHub:** https://github.com/almmello/smoonb
1
+ # Supa Moonbase (smoonb)
2
+
3
+ **Complete Supabase backup and migration tool**
4
+
5
+ Backup and restore: complete and simple, as it should be
6
+
7
+ > **Commercial product.** You need an **active license** and a **valid subscription** (or be on a trial period) to use smoonb. [www.smoonb.com/#price](https://www.smoonb.com/#price). Use is governed by the [Terms of Service](https://www.smoonb.com/terms) and [Privacy Policy](https://www.smoonb.com/privacy). We do not assume any liability for damage caused by smoonb; the legal disclaimers below remain in effect.
8
+
9
+ **Read this in other languages:** [Português (Brasil)](README.pt-BR.md)
10
+
11
+ **Developed by:** Goalmoon Tecnologia LTDA
12
+ **Website:** https://www.smoonb.com
13
+ **GitHub:** https://github.com/almmello/smoonb
14
+
15
+ ## 🎯 Objective
16
+
17
+ **smoonb** solves the problem of existing tools that only backup the PostgreSQL database, ignoring critical Supabase components.
18
+
19
+ ## 📦 Backup Components
20
+
21
+ smoonb performs a complete backup of all components of your Supabase project:
22
+
23
+ - ✅ **Database PostgreSQL** (backup completo via `pg_dumpall` + SQL separados, idêntico ao Dashboard)
24
+ - ✅ **Database Extensions and Settings** (extensões PostgreSQL e configurações)
25
+ - ✅ **Custom Roles** (roles personalizados do PostgreSQL)
26
+ - ✅ **Edge Functions** (download automático do servidor)
27
+ - ✅ **Auth Settings** (configurações de autenticação via Management API)
28
+ - ✅ **Storage Buckets** (backup completo: metadados, configurações e todos os arquivos via Management API + Supabase Client, cria ZIP no padrão do Dashboard)
29
+ - ✅ **Realtime Settings** (7 parâmetros capturados interativamente)
30
+ - ✅ **Supabase .temp** (arquivos temporários do Supabase CLI)
31
+ - ✅ **Migrations** (todas as migrations do projeto via `supabase migration fetch`)
32
+
33
+ ## ⚠️ Universal Disclaimer / Legal Notice
34
+
35
+ By continuing, you acknowledge and agree that Supa Moonbase (smoonb) is provided "AS IS" and "AS AVAILABLE", with no warranties of any kind—express, implied, or statutory—including but not limited to merchantability, fitness for a particular purpose, and non-infringement, to the maximum extent permitted by applicable law. Backup and restore operations inherently carry risk, environments vary widely, and we cannot foresee or validate all user setups. You are solely responsible for validating your own environment, keeping independent copies, and verifying results before relying on them in production. We build Supa Moonbase (smoonb) on public, auditable, open-source repositories to help people simplify their workflows, but this does not create any warranty, promise of support, or service-level commitment.
36
+
37
+ **Limitation of liability** — To the maximum extent permitted by law, Goalmoon Tecnologia LTDA, its contributors, and licensors will not be liable for any indirect, incidental, special, consequential, exemplary, or punitive damages (including loss of data, interruption of business, or lost profits) arising from or related to the use of, inability to use, backup/restore operations performed by, or results produced by Supa Moonbase (smoonb).
38
+
39
+ ## 🚀 Installation
40
+
41
+ **⚠️ IMPORTANT: Install ONLY locally in the project!**
42
+
43
+ **Install locally in the project:**
44
+ ```bash
45
+ npm install smoonb
46
+ ```
47
+
48
+ **Use with npx:**
49
+ ```bash
50
+ npx smoonb --help
51
+ ```
52
+
53
+ **Do not install globally** (blocked):
54
+ ```bash
55
+ npm install -g smoonb
56
+ ```
57
+
58
+ ### 🔄 Update to Latest Version
59
+
60
+ To update smoonb to the latest available version, run in the current project:
61
+
62
+ ```bash
63
+ npm install smoonb@latest
64
+ ```
65
+
66
+ **⚠️ IMPORTANT:** smoonb must be installed locally in the project. Using without installing (e.g., `npx smoonb@latest`) is not allowed.
67
+
68
+ **💡 Why local only?**
69
+ - **🔒 Security**: Avoids version conflicts
70
+ - **📦 Isolation**: Each project uses its own version
71
+ - **🔄 Updates**: Granular control per project
72
+ - **🛡️ Stability**: Prevents breaking other projects
73
+
74
+ ## 📋 Prerequisites
75
+
76
+ ### 1. Docker Desktop (REQUIRED)
77
+
78
+ Install from [Docker Desktop](https://docs.docker.com/desktop/install/) (Windows/macOS) or [Docker Engine](https://docs.docker.com/engine/install/) (Linux). Then verify it is running:
79
+
80
+ ```bash
81
+ docker --version
82
+ docker ps
83
+ ```
84
+
85
+ **⚠️ IMPORTANT:** Docker is required for:
86
+ - Database backup via `pg_dumpall` (compatible with Supabase Dashboard)
87
+ - Compression of `.backup.gz` files
88
+ - Restoration of `.backup` and `.backup.gz` backups
89
+
90
+ ### 2. Supabase CLI
91
+ ```bash
92
+ npm install -g supabase
93
+ ```
94
+
95
+ **Version policy:** smoonb accepts any Supabase CLI version that is **at most 1 minor behind the latest** (same major). We recommend always using the latest version. Versions that are too old are blocked with an error message.
96
+
97
+ If your package manager (e.g. **Scoop** on Windows) lags behind on updates and you want to proceed anyway, use the `--skip-supabase-version-check` flag (see usage section below).
98
+
99
+ To update the Supabase CLI: [Updating the Supabase CLI](https://supabase.com/docs/guides/cli/getting-started#updating-the-supabase-cli).
100
+
101
+ ### 3. Supabase Personal Access Token
102
+ You need to obtain a Supabase personal access token to use the Management API:
103
+
104
+ 1. Visit: https://supabase.com/dashboard/account/tokens
105
+ 2. Click "Generate new token"
106
+ 3. Copy the token (format: `sbp_...`)
107
+ 4. Add to `.env.local` as `SUPABASE_ACCESS_TOKEN`
108
+
109
+ ### 4. License Key (REQUIRED for backup and restore)
110
+ **smoonb** requires a valid license to run backup and restore:
111
+
112
+ 1. Get your license from the desktop app at https://www.smoonb.com
113
+ 2. Set in environment or `.env.local`: `SMOONB_LICENSE_KEY=[your-license-key]`
114
+ 3. License is validated at the start of each run (step 00); no caching. If validation fails (network/server), the CLI aborts. The license is **not** shown in the interactive variable-mapping wizard (it is already validated before that).
115
+
116
+ ## ⚙️ Configuration
117
+
118
+ ### Modern Method: `.env.local` (RECOMMENDED)
119
+
120
+ **smoonb** now uses `.env.local` for configuration, following industry standards. This makes the process simpler and more integrated with your workflow.
121
+
122
+ #### 1. Create or edit `.env.local` in the project root
123
+
124
+ ```bash
125
+ touch .env.local
126
+ ```
127
+
128
+ #### 2. Add required environment variables
129
+
130
+ ```env
131
+ SMOONB_LICENSE_KEY=[your-license-key]
132
+ NEXT_PUBLIC_SUPABASE_URL=[your-supabase-url]
133
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=[your-anon-key]
134
+ SUPABASE_SERVICE_ROLE_KEY=[your-service-role]
135
+ SUPABASE_DB_URL=postgresql://postgres:[your-database-password]@db.[your-project-id].supabase.co:5432/postgres
136
+ SUPABASE_PROJECT_ID=[your-project-id]
137
+ SUPABASE_ACCESS_TOKEN=[your-access-token]
138
+ SUPABASE_POSTGRES_MAJOR=17
139
+ SMOONB_TELEMETRY_ENABLED=true
140
+ SMOONB_OUTPUT_DIR=./backups
141
+ ```
142
+
143
+ Required: `SMOONB_LICENSE_KEY` (from [www.smoonb.com](https://www.smoonb.com) desktop app), `SUPABASE_POSTGRES_MAJOR` (e.g. 17; see Dashboard → Project Settings → Infrastructure → Service Versions). Optional: `SMOONB_TELEMETRY_ENABLED`, `SMOONB_OUTPUT_DIR` (default `./backups`).
144
+
145
+ #### 3. Interactive Mapping
146
+
147
+ When running `backup` or `restore` for the first time, **smoonb** will:
148
+
149
+ 1. **Read** your current `.env.local`
150
+ 2. **Identify** the keys you already have
151
+ 3. **Ask interactively** which keys correspond to the expected ones (if names are different)
152
+ 4. **Add** missing keys if necessary
153
+ 5. **Create automatic backup** of `.env.local` before any changes
154
+ 6. **Save mapping** for future executions
155
+
156
+ **Mapping example:**
157
+ ```
158
+ 🔧 Mapping variable: NEXT_PUBLIC_SUPABASE_URL
159
+ Current value: https://abc123.supabase.co
160
+ Is this the correct value for the target project? (Y/n): Y
161
+ ```
162
+
163
+ ## 🌐 Internationalization (i18n)
164
+
165
+ **smoonb** supports multiple languages automatically. Currently supported languages are:
166
+
167
+ - **English (en)** - Default language
168
+ - **Portuguese (Brazil) (pt-BR)** - Full support
169
+
170
+ ### Automatic Language Detection
171
+
172
+ Language is detected automatically in the following order of precedence:
173
+
174
+ 1. **Environment variable `SMOONB_LANG`** (in `.env.local` or in the environment)
175
+ 2. **System locale** (LANG, LC_ALL, LC_MESSAGES). Example: `LANG=pt_BR.UTF-8` → pt-BR
176
+ 3. **Fallback to English (en)** if none of the above are detected
177
+
178
+ ### Supported Languages and Aliases
179
+
180
+ - `en` or `en-US` → English
181
+ - `pt-BR`, `pt_BR` or `pt` → Portuguese (Brazil)
182
+
183
+ ### Important Notes
184
+
185
+ - **Machine outputs** (e.g., `--json` if implemented) are **not** translated; fields and keys remain in English
186
+ - If a translation key is missing in a language, the system automatically **falls back to English**
187
+ - Language is detected once at the start of execution and applied to all CLI messages
188
+
189
+ ## 🎯 Usage
190
+
191
+ ### Full Backup
192
+
193
+ ```bash
194
+ npx smoonb backup
195
+ ```
196
+
197
+ **Available options:**
198
+
199
+ | Flag | Description |
200
+ |------|-------------|
201
+ | `--skip-supabase-version-check` | Skips the Supabase CLI version check. Use when your package manager (e.g. Scoop) lags behind on updates. A warning is shown and the user assumes the risk. |
202
+
203
+ **Example with flag:**
204
+ ```bash
205
+ npx smoonb backup --skip-supabase-version-check
206
+ ```
207
+
208
+ **Interactive backup flow:**
209
+
210
+ 1. **Terms of use** - Displays and requests acceptance of terms
211
+ 2. **License validation** - Validates `SMOONB_LICENSE_KEY` (env or prompt); no cache; aborts if validation fails
212
+ 3. **Docker validation** - Verifies if Docker is running
213
+ 4. **Consent** - Asks permission to read/write `.env.local`
214
+ 5. **Variable mapping** - Maps your environment variables (first time; license is not in the wizard—already validated)
215
+ 6. **.env.local backup** - Creates automatic backup before changes
216
+ 7. **Component selection** - Asks which components to include:
217
+ - ⚡ Edge Functions (explanation about link reset and download)
218
+ - 📦 Storage (explanation about full backup: file download + ZIP in Dashboard format)
219
+ - 🔐 Auth Settings (explanation about configurations)
220
+ - 🔄 Realtime Settings (explanation about interactive capture of 7 parameters)
221
+ - 🗑️ Cleanup options (functions, .temp, migrations after backup)
222
+ 8. **Configuration summary** - Shows everything that will be done
223
+ 9. **Final confirmation** - Confirms before starting
224
+ 10. **Step execution:**
225
+ - 📊 1/10 - Database Backup via `pg_dumpall` (Docker)
226
+ - 📊 2/10 - Separate Database SQL (schema, data, roles)
227
+ - 🔧 3/10 - Database Extensions and Settings Backup
228
+ - 🔐 4/10 - Auth Settings Backup (if selected)
229
+ - 🔄 5/10 - Realtime Settings Backup (if selected) - 7 parameters captured interactively
230
+ - 📦 6/10 - Storage Backup (if selected) - Full file download + ZIP in Dashboard format
231
+ - 👥 7/10 - Custom Roles Backup
232
+ - ⚡ 8/10 - Edge Functions Backup (if selected)
233
+ - 📁 9/10 - Supabase .temp Backup (if selected)
234
+ - 📋 10/10 - Migrations Backup (if selected)
235
+
236
+ **Result:** A folder `backups/backup-YYYY-MM-DD-HH-MM-SS/` containing for example:
237
+
238
+ ```
239
+ backups/backup-2025-10-31-09-37-54/
240
+ ├── backup-manifest.json
241
+ ├── db_cluster-31-10-2025@09-38-57.backup.gz
242
+ ├── schema.sql
243
+ ├── data.sql
244
+ ├── roles.sql
245
+ ├── database-settings-*.json
246
+ ├── auth-settings.json
247
+ ├── realtime-settings.json
248
+ ├── storage/
249
+ │ └── [bucket-name].json
250
+ ├── [project-id].storage.zip
251
+ ├── storage_temp/
252
+ │ └── [project-id]/
253
+ │ └── [bucket-name]/
254
+ ├── edge-functions/
255
+ │ └── [function-name]/
256
+ ├── supabase-temp/
257
+ ├── migrations/
258
+ └── env/
259
+ ├── .env.local
260
+ └── env-map.json
261
+ ```
262
+
263
+ ### Interactive Restoration
264
+
265
+ **Restore existing backup:**
266
+ ```bash
267
+ npx smoonb restore
268
+ ```
269
+
270
+ **Available options:**
271
+
272
+ | Flag | Description |
273
+ |------|-------------|
274
+ | `--skip-supabase-version-check` | Skips the Supabase CLI version check. Use when your package manager (e.g. Scoop) lags behind on updates. A warning is shown and the user assumes the risk. |
275
+
276
+ **Example with flag:**
277
+ ```bash
278
+ npx smoonb restore --skip-supabase-version-check
279
+ ```
280
+
281
+ **Interactive restore flow:**
282
+
283
+ 1. **Terms of use** - Displays and requests acceptance of terms
284
+ 2. **License validation** - Validates `SMOONB_LICENSE_KEY` (env or prompt); aborts if validation fails
285
+ 3. **Docker validation** - Verifies if Docker is running
286
+ 4. **Consent** - Asks permission to read/write `.env.local`
287
+ 5. **Variable mapping** - Maps variables to target project (includes `SUPABASE_POSTGRES_MAJOR`)
288
+ 6. **.env.local backup** - Creates automatic backup
289
+ 7. **Backup selection** - Lists and allows choosing which backup to restore
290
+ 8. **Component selection** - Asks which components to restore:
291
+ - 📊 Database (always available)
292
+ - ⚡ Edge Functions (if available in backup)
293
+ - 🔐 Auth Settings (if available in backup)
294
+ - 📦 Storage (if available in backup)
295
+ - 🔧 Database Extensions and Settings (if available in backup)
296
+ - 🔄 Realtime Settings (if available in backup)
297
+ 9. **Detailed summary** - Shows selected backup, target project and components
298
+ 10. **Final confirmation** - Confirms before starting
299
+ 11. **Disclaimer** - Explains that errors during restore are expected; link to [Supabase Dashboard Restore docs](https://supabase.com/docs/guides/platform/migrating-within-supabase/dashboard-restore); you should wait for the process to finish and then test the result before accepting to proceed
300
+ 12. **Restore execution:**
301
+ - 📊 Database - Restores via `psql` (supports `.backup.gz` and `.backup`)
302
+ - ⚡ Edge Functions - Copies and deploys to target project
303
+ - 🔐 Auth Settings - Displays configurations for manual application
304
+ - 📦 Storage - Restores buckets and files from ZIP (if available) or displays information for manual migration
305
+ - 🔧 Database Settings - Restores extensions and settings via SQL
306
+ - 🔄 Realtime Settings - Displays configurations for manual application
307
+
308
+ **Supported file formats:**
309
+ - ✅ `.backup.gz` (compressed) - Automatically decompresses before restoring
310
+ - ✅ `.backup` (uncompressed) - Restores directly
311
+
312
+ ### Import Backup from Supabase Dashboard
313
+
314
+ If you downloaded a backup directly from the Supabase Dashboard (`.backup.gz` format), you can import it to the format expected by smoonb. The command also supports optionally importing storage files (`.storage.zip`).
315
+
316
+ **Import database only:**
317
+ ```bash
318
+ npx smoonb import --file "full/path/to/db_cluster-04-03-2024@14-16-59.backup.gz"
319
+ ```
320
+
321
+ **Import database and storage together:**
322
+ ```bash
323
+ npx smoonb import --file "backup.backup.gz" --storage "my-project.storage.zip"
324
+ ```
325
+
326
+ **What the command does:**
327
+ 1. Reads the `.backup.gz` file from Dashboard (required)
328
+ 2. If provided, reads the `.storage.zip` file from Dashboard (optional)
329
+ 3. Extracts information from backup file name (date and time)
330
+ 4. Creates a backup folder in expected format (`backup-YYYY-MM-DD-HH-MM-SS`)
331
+ 5. Copies backup file to created folder
332
+ 6. If provided, copies storage file to same folder
333
+ 7. Makes backup ready to be found by `restore` command
334
+
335
+ **Complete example - Database only (using import + restore):**
336
+
337
+ 1. Download backup from Supabase Dashboard (e.g. `db_cluster-04-03-2024@14-16-59.backup.gz`).
338
+ 2. Import the file, then restore:
339
+
340
+ ```bash
341
+ npx smoonb import --file "C:\Downloads\db_cluster-04-03-2024@14-16-59.backup.gz"
342
+ npx smoonb restore
343
+ ```
344
+
345
+ The imported backup will appear in the list of available backups.
346
+
347
+ **Complete example - Database and Storage (using import + restore):**
348
+
349
+ 1. Download backup and storage from Supabase Dashboard (e.g. `db_cluster-04-03-2024@14-16-59.backup.gz` and `my-project.storage.zip`).
350
+ 2. Import both files, then restore:
351
+
352
+ ```bash
353
+ npx smoonb import --file "C:\Downloads\db_cluster-04-03-2024@14-16-59.backup.gz" --storage "C:\Downloads\my-project.storage.zip"
354
+ npx smoonb restore
355
+ ```
356
+
357
+ The imported backup will appear in the list of available backups.
358
+
359
+ **Important:**
360
+ - Backup file is **required** and must be in Dashboard format: `db_cluster-DD-MM-YYYY@HH-MM-SS.backup.gz`
361
+ - Storage file is **optional** and must be in format: `*.storage.zip`
362
+ - Storage depends on a backup, but backup does not depend on storage
363
+ - Both files will be copied to the same backup folder
364
+ - Path can be absolute or relative
365
+ - Command will automatically create necessary folder structure
366
+
367
+ After running `import`, run `restore` to choose the imported backup from the list and restore it.
368
+
369
+ ## 🔧 Available Commands
370
+
371
+ | Command | Description |
372
+ |---------|-------------|
373
+ | `npx smoonb backup` | Full interactive backup using Docker |
374
+ | `npx smoonb backup --skip-supabase-version-check` | Backup skipping the Supabase CLI version check |
375
+ | `npx smoonb restore` | Interactive restoration using psql (Docker) |
376
+ | `npx smoonb restore --skip-supabase-version-check` | Restore skipping the Supabase CLI version check |
377
+ | `npx smoonb import --file <path> [--storage <path>]` | Import .backup.gz file and optionally .storage.zip from Supabase Dashboard |
378
+
379
+ ## 🏗️ Technical Architecture
380
+
381
+ ### Modular Structure
382
+
383
+ The code has been refactored to a **modular architecture** with independent steps:
384
+
385
+ #### Backup (`src/commands/backup/`)
386
+ ```
387
+ backup/
388
+ ├── index.js
389
+ ├── utils.js
390
+ └── steps/
391
+ ├── 00-license.js
392
+ ├── 01-docker-validation.js
393
+ ├── 02-database.js
394
+ ├── 03-database-separated.js
395
+ ├── 04-database-settings.js
396
+ ├── 05-auth-settings.js
397
+ ├── 06-realtime-settings.js
398
+ ├── 07-storage.js
399
+ ├── 08-custom-roles.js
400
+ ├── 09-edge-functions.js
401
+ ├── 10-supabase-temp.js
402
+ └── 11-migrations.js
403
+ ```
404
+
405
+ #### Restore (`src/commands/restore/`)
406
+ License validation (same as backup, `00-license.js` from backup steps) runs at start. Then:
407
+ ```
408
+ restore/
409
+ ├── index.js
410
+ ├── utils.js
411
+ └── steps/
412
+ ├── 00-backup-selection.js
413
+ ├── 01-components-selection.js
414
+ ├── 02-confirmation.js
415
+ ├── 03-database.js
416
+ ├── 04-edge-functions.js
417
+ ├── 05-auth-settings.js
418
+ ├── 06-storage.js
419
+ ├── 07-database-settings.js
420
+ └── 08-realtime-settings.js
421
+ ```
422
+
423
+ ### Backup Strategy
424
+
425
+ #### Database
426
+ - **Main Backup**: `pg_dumpall` via Docker (identical to Dashboard)
427
+ - File: `db_cluster-XX-XX-XXXX@XX-XX-XX.backup.gz`
428
+ - Compatible with restoration via Supabase Dashboard
429
+ - **Separate Backup**: SQL in separate files via Supabase CLI
430
+ - `schema.sql` - Table structure
431
+ - `data.sql` - Data (COPY statements)
432
+ - `roles.sql` - Roles and permissions
433
+
434
+ #### Edge Functions
435
+ - **Automatic Download**: Via Supabase CLI `supabase functions download`
436
+ - **Link Reset**: Ensures clean link with project before download
437
+ - **Complete Backup**: Full code of each function
438
+
439
+ #### Migrations
440
+ - **Automatic Download**: Via `supabase migration fetch`
441
+ - **Link Reset**: Ensures clean link with project
442
+ - **Complete Backup**: All server migrations
443
+
444
+ #### Storage
445
+ - **Complete Backup**: Download of all files from all buckets
446
+ - **Temporary Structure**: Creates `storage_temp/project-id/bucket-name/files...` inside backupDir
447
+ - **ZIP in Dashboard Format**: Creates `{project-id}.storage.zip` with structure `project-id/bucket-name/files...`
448
+ - **Restore Compatible**: Created ZIP is compatible with restore process (same format as Dashboard)
449
+ - **Interactive Question**: After creating ZIP, asks if you want to clean temporary structure
450
+ - **Fallback**: If Supabase credentials are not available, backs up metadata only
451
+ - **Management API**: Uses Personal Access Token to list buckets and objects
452
+ - **Supabase Client**: Uses Service Role Key for file downloads
453
+
454
+ #### Auth, Realtime
455
+ - **Management API**: Uses Personal Access Token
456
+ - **JSON Export**: Configurations exported as JSON
457
+ - **Realtime Settings**: Interactive capture of 7 parameters:
458
+ 1. Enable Realtime service
459
+ 2. Allow public access
460
+ 3. Database connection pool size
461
+ 4. Max concurrent clients
462
+ 5. Max events per second
463
+ 6. Max presence events per second
464
+ 7. Max payload size in KB
465
+ - **Manual for some**: Some settings need to be applied manually for security
466
+
467
+ ### Restore Strategy
468
+
469
+ #### Database
470
+ - **Format Support**:
471
+ - `.backup.gz` - Automatically decompresses via Docker
472
+ - `.backup` - Restores directly via `psql` (Docker)
473
+ - **Clean Restore**: Can overwrite existing data (with confirmation)
474
+
475
+ #### Edge Functions
476
+ - **Clean Deploy**: Cleans `supabase/functions` before deploy
477
+ - **Link Reset**: Ensures correct link with target project
478
+ - **Automatic Deploy**: Uses `supabase functions deploy`
479
+
480
+ #### Other Components
481
+ - **Database Settings**: Restores via SQL
482
+ - **Storage**: Restores buckets and files from ZIP (if available) or displays information for manual configuration
483
+ - **Auth/Realtime**: Displays information for manual configuration in Dashboard
484
+
485
+ ### Cross-Platform
486
+
487
+ - **Windows/macOS/Linux**: Automatic binary detection
488
+ - **Cross-platform**: Uses `fs.promises.cp`, `path.join`, Docker
489
+ - **Docker for Everything**: Backup, restore and compression via Docker (ensures consistency)
490
+
491
+ ## 📊 Recommended Flow
492
+
493
+ 1. **Configure `.env.local`** (first time) with your source project credentials.
494
+ 2. **Backup source project:**
495
+ ```bash
496
+ npx smoonb backup
497
+ ```
498
+ (Maps variables interactively on first run, selects components, executes full backup.)
499
+ 3. **Create new Supabase project** (via Dashboard or Supabase CLI).
500
+ 4. **Edit `.env.local`** with new project credentials (point variables to target project).
501
+ 5. **Restore backup** (interactive mode):
502
+ ```bash
503
+ npx smoonb restore
504
+ ```
505
+ (Select desired backup, select components, execute restoration.)
506
+ 6. **Apply manual configurations** if necessary: Auth Settings (Dashboard → Authentication → Settings), Realtime (Dashboard → Database → Replication). Storage is restored automatically from ZIP when available.
507
+
508
+ ## 🎨 User Experience
509
+
510
+ ### Multi-Language Interface
511
+
512
+ All interactions are **automatically translated** based on system locale or `SMOONB_LANG`:
513
+ - Clear and direct questions
514
+ - Explanations before each process
515
+ - Detailed summaries before confirming
516
+ - Confirmations with `(Y/n)` or `(y/N)` in English, `(S/n)` or `(s/N)` in Portuguese
517
+
518
+ ### Intelligent Variable Mapping
519
+
520
+ - **Automatic Detection**: If key already exists with expected name, skips selection
521
+ - **Add Option**: Allows adding new keys if they don't exist
522
+ - **Value Validation**: Confirms values before saving
523
+ - **Automatic Backup**: Always creates backup of `.env.local` before changes
524
+
525
+ ### Guided Process
526
+
527
+ - **Prior Validation**: Verifies Docker before starting
528
+ - **Contextual Explanations**: Explains each process before asking
529
+ - **Final Summary**: Shows everything that will be done before executing
530
+ - **Visual Feedback**: Colors and icons for better experience
531
+
532
+ ## 🐛 Troubleshooting
533
+
534
+ ### Circular foreign-key warnings during data export
535
+
536
+ Tables can reference each other (or themselves). PostgreSQL warns that a **data-only** dump cannot always be restored with ordinary foreign-key checks. This warning alone is not an export failure: check the exit result and the backup manifest.
537
+
538
+ smoonb consolidates these known warnings, lists the affected tables, and records the original diagnostics in `backup-manifest.json` under `components.database_separated.warnings`. Other warnings and errors remain visible. A failed schema, data, or roles export marks this component as incomplete.
539
+
540
+ The Supabase CLI currently prepends `SET session_replication_role = replica;` to `data.sql`. smoonb checks the first line before reporting its presence. This is **not a restore validation**: the destination role must be allowed to change that setting. Restore schema before data and stop on SQL errors. For a controlled restore into an appropriate, separate target, follow the [Supabase backup/restore guide](https://supabase.com/docs/guides/platform/migrating-within-supabase/backup-restore):
541
+
542
+ ```bash
543
+ psql --dbname "$TARGET_DB_URL" --single-transaction --variable ON_ERROR_STOP=1 --file roles.sql --file schema.sql --command 'SET session_replication_role = replica' --file data.sql
544
+ ```
545
+
546
+ The setting affects that restore connection; it does not modify the source database. Verify row counts and references in the restored target before relying on the backup. Do not remove foreign keys from your application to silence these warnings. The main `.backup.gz` is a full cluster dump; the separate SQL files are additional artifacts.
547
+
548
+ ### Development checks
549
+
550
+ Use Node.js 22 for development checks: `npm test`, `npm run lint`, and `npm run build`. The explicit `npm run test:docker` integration test requires Docker, the `postgres:17` image and Supabase CLI. It creates only synthetic data in its own disposable PostgreSQL container, tests protected and unprotected restores, and removes that container afterward. It does not use a project's credentials or remote database.
551
+
552
+
553
+ ### Docker not found or not running
554
+
555
+ Verify Docker is installed and running:
556
+
557
+ ```bash
558
+ docker --version
559
+ docker ps
560
+ ```
561
+
562
+ If not, start Docker Desktop (Windows/macOS) or run `sudo systemctl start docker` (Linux).
563
+
564
+ ### Supabase CLI not found
565
+ ```bash
566
+ npm install -g supabase
567
+ ```
568
+
569
+ ### Supabase CLI outdated (below minimum accepted version)
570
+
571
+ smoonb accepts versions up to **1 minor behind the latest**. If your installed version is below that threshold, you will see a message like:
572
+
573
+ ```
574
+ ❌ Supabase CLI X.Y.Z is below the minimum accepted version (X.W.0). Latest: X.V.Z. Update to at least version X.W.0.
575
+ ```
576
+
577
+ **Option 1 — Update the Supabase CLI:**
578
+ ```bash
579
+ npm install -g supabase@latest # global install
580
+ npm install supabase@latest # local/project install
581
+ ```
582
+
583
+ **Option 2 — Skip the check (temporary, user assumes the risk):**
584
+ ```bash
585
+ npx smoonb backup --skip-supabase-version-check
586
+ npx smoonb restore --skip-supabase-version-check
587
+ ```
588
+
589
+ > **Note for Scoop users (Windows):** the Scoop repository may take a few days to update after a release. Use `--skip-supabase-version-check` until Scoop ships the updated version.
590
+
591
+ ### Invalid or missing Personal Access Token
592
+
593
+ 1. Verify if `SUPABASE_ACCESS_TOKEN` is in `.env.local`
594
+ 2. Generate new token: https://supabase.com/dashboard/account/tokens
595
+ 3. Update `.env.local` with new token
596
+
597
+ ### Incorrect Database URL
598
+ - Verify password in connection URL
599
+ - Use Connection string from Supabase Dashboard (Settings → Database)
600
+ - Test connection: `psql "your-database-url" -c "SELECT 1"`
601
+
602
+ ### .backup.gz file cannot be restored
603
+
604
+ smoonb automatically supports:
605
+ - ✅ `.backup.gz` - Decompresses via Docker before restoring
606
+ - ✅ `.backup` - Restores directly
607
+
608
+ If there are problems:
609
+ 1. Verify if Docker is running
610
+ 2. Verify file permissions
611
+ 3. Verify disk space
612
+
613
+ ### Error downloading Edge Functions
614
+
615
+ 1. Verify if `SUPABASE_ACCESS_TOKEN` is configured
616
+ 2. Verify if project is linked: `supabase link`
617
+ 3. Verify if functions exist on server
618
+
619
+ ### Error downloading Migrations
620
+
621
+ 1. Verify if `SUPABASE_ACCESS_TOKEN` is configured
622
+ 2. Verify if project is linked: `supabase link`
623
+ 3. Verify if there are migrations on server
624
+
625
+ ## 🔒 Security
626
+
627
+ - **Automatic Backup**: Always creates backup of `.env.local` before changes
628
+ - **Local Mapping**: Variable mapping saved only locally
629
+ - **No Sensitive Data**: No sensitive data is sent outside your environment
630
+ - **Isolated Docker**: Database operations via Docker (isolation)
631
+
632
+ ## 💼 Access and subscription
633
+
634
+ Supa Moonbase code is provided under MIT license (see `LICENSE`). To use smoonb you must have an **active license** and a **valid subscription**, or be within a **trial period**. License validation runs at the start of backup and restore; without a valid license and subscription (or trial), the CLI will not run those operations.
635
+
636
+ [www.smoonb.com/#price](https://www.smoonb.com/#price).
637
+
638
+ ## 🔒 Privacy and LGPD (summary)
639
+
640
+ Supa Moonbase adopts the data minimization principle. We process only the information strictly necessary for access control and billing (e.g., account identifier and contact). Purposes, legal bases and data subject rights are described in the [Privacy Policy](https://www.smoonb.com/privacy).
641
+
642
+ ## 📋 Terms of Service and brand usage
643
+
644
+ The code license (MIT) does not replace the [Terms of Service](https://www.smoonb.com/terms) that govern operational access and subscription validation.
645
+
646
+ "Supa Moonbase" and visual identity elements are trademarks of Goalmoon Tecnologia Ltda.; use of brand and branding assets is restricted as per [Terms of Service](https://www.smoonb.com/terms).
647
+
648
+ [FAQ](https://www.smoonb.com/#faq).
649
+
650
+ ## 📝 License
651
+
652
+ Supa Moonbase code is provided under MIT license. See [LICENSE](LICENSE) for the full license text. A Portuguese translation is available in [LICENSE.pt-BR.md](LICENSE.pt-BR.md) for convenience only.
653
+
654
+ ## 🤝 Contributing
655
+
656
+ Contributions are welcome. [www.smoonb.com/#price](https://www.smoonb.com/#price).
657
+
658
+
659
+ ---
660
+
661
+ **Developed by:** Goalmoon Tecnologia LTDA
662
+ **Website:** https://www.smoonb.com
663
+ **GitHub:** https://github.com/almmello/smoonb