dbdock 1.1.0
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/LICENSE +21 -0
- package/README.md +596 -0
- package/dist/alerts/alert-templates.d.ts +3 -0
- package/dist/alerts/alert-templates.js +95 -0
- package/dist/alerts/alert-templates.js.map +1 -0
- package/dist/alerts/alert.module.d.ts +2 -0
- package/dist/alerts/alert.module.js +23 -0
- package/dist/alerts/alert.module.js.map +1 -0
- package/dist/alerts/alert.service.d.ts +23 -0
- package/dist/alerts/alert.service.js +210 -0
- package/dist/alerts/alert.service.js.map +1 -0
- package/dist/alerts/alert.types.d.ts +24 -0
- package/dist/alerts/alert.types.js +11 -0
- package/dist/alerts/alert.types.js.map +1 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +34 -0
- package/dist/app.module.js.map +1 -0
- package/dist/backup/backup.module.d.ts +2 -0
- package/dist/backup/backup.module.js +26 -0
- package/dist/backup/backup.module.js.map +1 -0
- package/dist/backup/backup.service.d.ts +23 -0
- package/dist/backup/backup.service.js +303 -0
- package/dist/backup/backup.service.js.map +1 -0
- package/dist/backup/backup.types.d.ts +42 -0
- package/dist/backup/backup.types.js +16 -0
- package/dist/backup/backup.types.js.map +1 -0
- package/dist/backup/compression.service.d.ts +6 -0
- package/dist/backup/compression.service.js +30 -0
- package/dist/backup/compression.service.js.map +1 -0
- package/dist/cli/commands/backup.d.ts +8 -0
- package/dist/cli/commands/backup.js +198 -0
- package/dist/cli/commands/backup.js.map +1 -0
- package/dist/cli/commands/cleanup.d.ts +6 -0
- package/dist/cli/commands/cleanup.js +160 -0
- package/dist/cli/commands/cleanup.js.map +1 -0
- package/dist/cli/commands/delete.d.ts +6 -0
- package/dist/cli/commands/delete.js +252 -0
- package/dist/cli/commands/delete.js.map +1 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.js +534 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/list.d.ts +8 -0
- package/dist/cli/commands/list.js +288 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/restore.d.ts +1 -0
- package/dist/cli/commands/restore.js +637 -0
- package/dist/cli/commands/restore.js.map +1 -0
- package/dist/cli/commands/schedule.d.ts +1 -0
- package/dist/cli/commands/schedule.js +197 -0
- package/dist/cli/commands/schedule.js.map +1 -0
- package/dist/cli/commands/start.d.ts +7 -0
- package/dist/cli/commands/start.js +267 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +1 -0
- package/dist/cli/commands/status.js +46 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/test.d.ts +1 -0
- package/dist/cli/commands/test.js +212 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +78 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/config.d.ts +80 -0
- package/dist/cli/utils/config.js +29 -0
- package/dist/cli/utils/config.js.map +1 -0
- package/dist/cli/utils/logger.d.ts +7 -0
- package/dist/cli/utils/logger.js +15 -0
- package/dist/cli/utils/logger.js.map +1 -0
- package/dist/cli/utils/progress.d.ts +21 -0
- package/dist/cli/utils/progress.js +130 -0
- package/dist/cli/utils/progress.js.map +1 -0
- package/dist/cli/utils/retention.d.ts +26 -0
- package/dist/cli/utils/retention.js +118 -0
- package/dist/cli/utils/retention.js.map +1 -0
- package/dist/config/config.module.d.ts +2 -0
- package/dist/config/config.module.js +29 -0
- package/dist/config/config.module.js.map +1 -0
- package/dist/config/config.schema.d.ts +56 -0
- package/dist/config/config.schema.js +219 -0
- package/dist/config/config.schema.js.map +1 -0
- package/dist/config/config.service.d.ts +13 -0
- package/dist/config/config.service.js +160 -0
- package/dist/config/config.service.js.map +1 -0
- package/dist/crypto/crypto.module.d.ts +2 -0
- package/dist/crypto/crypto.module.js +21 -0
- package/dist/crypto/crypto.module.js.map +1 -0
- package/dist/crypto/crypto.service.d.ts +22 -0
- package/dist/crypto/crypto.service.js +187 -0
- package/dist/crypto/crypto.service.js.map +1 -0
- package/dist/dbdock.d.ts +10 -0
- package/dist/dbdock.js +36 -0
- package/dist/dbdock.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +10 -0
- package/dist/main.js.map +1 -0
- package/dist/scheduler/schedule-manager.d.ts +22 -0
- package/dist/scheduler/schedule-manager.js +126 -0
- package/dist/scheduler/schedule-manager.js.map +1 -0
- package/dist/scheduler/scheduler.module.d.ts +2 -0
- package/dist/scheduler/scheduler.module.js +25 -0
- package/dist/scheduler/scheduler.module.js.map +1 -0
- package/dist/scheduler/scheduler.service.d.ts +28 -0
- package/dist/scheduler/scheduler.service.js +171 -0
- package/dist/scheduler/scheduler.service.js.map +1 -0
- package/dist/standalone/backup-standalone.d.ts +14 -0
- package/dist/standalone/backup-standalone.js +364 -0
- package/dist/standalone/backup-standalone.js.map +1 -0
- package/dist/storage/adapters/cloudinary.adapter.d.ts +23 -0
- package/dist/storage/adapters/cloudinary.adapter.js +215 -0
- package/dist/storage/adapters/cloudinary.adapter.js.map +1 -0
- package/dist/storage/adapters/local.adapter.d.ts +20 -0
- package/dist/storage/adapters/local.adapter.js +214 -0
- package/dist/storage/adapters/local.adapter.js.map +1 -0
- package/dist/storage/adapters/r2.adapter.d.ts +10 -0
- package/dist/storage/adapters/r2.adapter.js +33 -0
- package/dist/storage/adapters/r2.adapter.js.map +1 -0
- package/dist/storage/adapters/s3.adapter.d.ts +26 -0
- package/dist/storage/adapters/s3.adapter.js +199 -0
- package/dist/storage/adapters/s3.adapter.js.map +1 -0
- package/dist/storage/storage.interface.d.ts +38 -0
- package/dist/storage/storage.interface.js +3 -0
- package/dist/storage/storage.interface.js.map +1 -0
- package/dist/storage/storage.module.d.ts +2 -0
- package/dist/storage/storage.module.js +21 -0
- package/dist/storage/storage.module.js.map +1 -0
- package/dist/storage/storage.service.d.ts +10 -0
- package/dist/storage/storage.service.js +89 -0
- package/dist/storage/storage.service.js.map +1 -0
- package/dist/utils/logger.d.ts +12 -0
- package/dist/utils/logger.js +41 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/stream.pipe.d.ts +17 -0
- package/dist/utils/stream.pipe.js +54 -0
- package/dist/utils/stream.pipe.js.map +1 -0
- package/dist/wal/postgres-config.helper.d.ts +5 -0
- package/dist/wal/postgres-config.helper.js +117 -0
- package/dist/wal/postgres-config.helper.js.map +1 -0
- package/dist/wal/retention.service.d.ts +23 -0
- package/dist/wal/retention.service.js +158 -0
- package/dist/wal/retention.service.js.map +1 -0
- package/dist/wal/retention.types.d.ts +20 -0
- package/dist/wal/retention.types.js +3 -0
- package/dist/wal/retention.types.js.map +1 -0
- package/dist/wal/wal-archiver.service.d.ts +28 -0
- package/dist/wal/wal-archiver.service.js +263 -0
- package/dist/wal/wal-archiver.service.js.map +1 -0
- package/dist/wal/wal.module.d.ts +2 -0
- package/dist/wal/wal.module.js +26 -0
- package/dist/wal/wal.module.js.map +1 -0
- package/dist/wal/wal.types.d.ts +27 -0
- package/dist/wal/wal.types.js +11 -0
- package/dist/wal/wal.types.js.map +1 -0
- package/package.json +155 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DBDock Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
# DBDock
|
|
2
|
+
|
|
3
|
+
Enterprise-grade PostgreSQL backup and restore. Beautiful CLI with real-time progress tracking.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/dbdock)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](https://dbdock.mintlify.app)
|
|
9
|
+
|
|
10
|
+
📚 **[Full Documentation](https://dbdock.mintlify.app)** | 💬 **[Discussions](https://github.com/naheemolaide/dbdock-support/discussions)** | 🐛 **[Issues](https://github.com/naheemolaide/dbdock-support/issues)**
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx dbdock init # Interactive setup
|
|
16
|
+
npx dbdock backup # Create backup
|
|
17
|
+
npx dbdock restore # Restore backup
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Beautiful CLI** - Real-time progress bars, speed tracking, smart filtering
|
|
23
|
+
- **Multiple Storage** - Local, AWS S3, Cloudflare R2, Cloudinary
|
|
24
|
+
- **Security** - AES-256 encryption, Brotli compression
|
|
25
|
+
- **Retention Policies** - Automatic cleanup by count/age with safety nets
|
|
26
|
+
- **Smart UX** - Intelligent filtering for 100+ backups, clear error messages
|
|
27
|
+
- **Email Alerts** - SMTP notifications with custom templates
|
|
28
|
+
- **TypeScript Native** - Full type safety for programmatic usage
|
|
29
|
+
- **Automation** - Cron schedules, auto-cleanup after backups
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
**Global Installation (Recommended):**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install -g dbdock-cli
|
|
37
|
+
|
|
38
|
+
dbdock init # Use directly
|
|
39
|
+
dbdock backup
|
|
40
|
+
dbdock status
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Or use with npx (No installation needed):**
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx dbdock init
|
|
47
|
+
npx dbdock backup
|
|
48
|
+
npx dbdock status
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## CLI Commands
|
|
52
|
+
|
|
53
|
+
### `dbdock init`
|
|
54
|
+
|
|
55
|
+
Interactive setup wizard that creates `dbdock.config.json` with:
|
|
56
|
+
|
|
57
|
+
- Database connection (host, port, credentials)
|
|
58
|
+
- Storage provider (Local, S3, R2, Cloudinary)
|
|
59
|
+
- Encryption/compression settings
|
|
60
|
+
- Email alerts (optional)
|
|
61
|
+
|
|
62
|
+
Auto-adds config to `.gitignore` to protect credentials.
|
|
63
|
+
|
|
64
|
+
### `npx dbdock backup`
|
|
65
|
+
|
|
66
|
+
Creates database backup with real-time progress tracking:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
████████████████████ | 100% | 45.23/100 MB | Speed: 12.50 MB/s | ETA: 0s | Uploading to S3
|
|
70
|
+
✔ Backup completed successfully
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Options:**
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npx dbdock backup --encrypt --compress --compression-level 9
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- `--encrypt` / `--no-encrypt` - Toggle encryption
|
|
80
|
+
- `--compress` / `--no-compress` - Toggle compression
|
|
81
|
+
- `--encryption-key <key>` - 64-char hex key (must be exactly 64 hexadecimal characters)
|
|
82
|
+
- `--compression-level <1-11>` - Compression level (default: 6)
|
|
83
|
+
|
|
84
|
+
**Generate encryption key:**
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Backup Formats:**
|
|
91
|
+
|
|
92
|
+
- `custom` (default) - PostgreSQL custom binary format (.sql)
|
|
93
|
+
- `plain` - Plain SQL text format (.sql)
|
|
94
|
+
- `directory` - Directory format (.dir)
|
|
95
|
+
- `tar` - Tar archive format (.tar)
|
|
96
|
+
|
|
97
|
+
### `npx dbdock restore`
|
|
98
|
+
|
|
99
|
+
Interactive restore with smart filtering and multi-step progress:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
Progress:
|
|
103
|
+
────────────────────────────────────────────────────────
|
|
104
|
+
✔ Downloading backup
|
|
105
|
+
✔ Decrypting data
|
|
106
|
+
✔ Decompressing data
|
|
107
|
+
⟳ Restoring to database...
|
|
108
|
+
────────────────────────────────────────────────────────
|
|
109
|
+
✔ All steps completed in 8.42s
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Smart filtering** (auto-enabled for 20+ backups):
|
|
113
|
+
|
|
114
|
+
- Show recent (last 10)
|
|
115
|
+
- Date range (24h, 7d, 30d, 90d, custom)
|
|
116
|
+
- Search by keyword/ID
|
|
117
|
+
|
|
118
|
+
Shows database stats and requires confirmation before restore.
|
|
119
|
+
|
|
120
|
+
### `npx dbdock list`
|
|
121
|
+
|
|
122
|
+
View backups with smart filtering:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npx dbdock list # All backups
|
|
126
|
+
npx dbdock list --recent 10 # Last 10
|
|
127
|
+
npx dbdock list --search keyword # Search
|
|
128
|
+
npx dbdock list --days 7 # Last 7 days
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Auto-filtering** for 50+ backups with interactive prompts.
|
|
132
|
+
|
|
133
|
+
### `npx dbdock delete`
|
|
134
|
+
|
|
135
|
+
Delete backups interactively or by key:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npx dbdock delete # Interactive
|
|
139
|
+
npx dbdock delete --key <id> # Specific backup
|
|
140
|
+
npx dbdock delete --all # All (with confirmation)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `npx dbdock cleanup`
|
|
144
|
+
|
|
145
|
+
Clean up old backups based on retention policy:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npx dbdock cleanup # Interactive with preview
|
|
149
|
+
npx dbdock cleanup --dry-run # Preview only
|
|
150
|
+
npx dbdock cleanup --force # Skip confirmation
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Shows detailed preview of what will be deleted and space to reclaim.
|
|
154
|
+
|
|
155
|
+
### `dbdock status`
|
|
156
|
+
|
|
157
|
+
Quick view of all schedules and service status:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
dbdock status
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Output:**
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
📅 Scheduled Backups:
|
|
167
|
+
|
|
168
|
+
┌─────┬──────────────┬─────────────────┬──────────┐
|
|
169
|
+
│ # │ Name │ Cron Expression │ Status │
|
|
170
|
+
├─────┼──────────────┼─────────────────┼──────────┤
|
|
171
|
+
│ 1 │ daily │ 0 * * * * │ ✓ Active │
|
|
172
|
+
│ 2 │ weekly │ 0 0 * * 0 │ ✗ Paused │
|
|
173
|
+
└─────┴──────────────┴─────────────────┴──────────┘
|
|
174
|
+
|
|
175
|
+
Total: 2 schedule(s) - 1 active, 1 paused
|
|
176
|
+
|
|
177
|
+
🚀 Service Status:
|
|
178
|
+
|
|
179
|
+
🟢 Running (PM2)
|
|
180
|
+
PID: 12345
|
|
181
|
+
Uptime: 2d 5h
|
|
182
|
+
Memory: 45.23 MB
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### `dbdock test`
|
|
186
|
+
|
|
187
|
+
Validates database, storage, and email configuration.
|
|
188
|
+
|
|
189
|
+
### `dbdock schedule`
|
|
190
|
+
|
|
191
|
+
Manage backup schedules in configuration:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
dbdock schedule
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Features:**
|
|
198
|
+
|
|
199
|
+
- View current schedules with status
|
|
200
|
+
- Add new schedule with cron expression presets
|
|
201
|
+
- Remove or toggle (enable/disable) schedules
|
|
202
|
+
- Saves to `dbdock.config.json`
|
|
203
|
+
|
|
204
|
+
**Schedule Presets:**
|
|
205
|
+
|
|
206
|
+
- Every hour: `0 * * * *`
|
|
207
|
+
- Every day at midnight: `0 0 * * *`
|
|
208
|
+
- Every day at 2 AM: `0 2 * * *`
|
|
209
|
+
- Every week (Sunday): `0 0 * * 0`
|
|
210
|
+
- Every month (1st): `0 0 1 * *`
|
|
211
|
+
- Custom cron expression
|
|
212
|
+
|
|
213
|
+
**⚠️ Important:** Schedules only execute when DBDock is integrated into your NestJS application (see Programmatic Usage below). The CLI is for configuration only.
|
|
214
|
+
|
|
215
|
+
## Configuration
|
|
216
|
+
|
|
217
|
+
After running `npx dbdock init`, a `dbdock.config.json` file is created:
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"database": {
|
|
222
|
+
"type": "postgres",
|
|
223
|
+
"host": "localhost",
|
|
224
|
+
"port": 5432,
|
|
225
|
+
"username": "postgres",
|
|
226
|
+
"password": "your-password",
|
|
227
|
+
"database": "myapp"
|
|
228
|
+
},
|
|
229
|
+
"storage": {
|
|
230
|
+
"provider": "s3",
|
|
231
|
+
"s3": {
|
|
232
|
+
"bucket": "my-backups",
|
|
233
|
+
"region": "us-east-1",
|
|
234
|
+
"accessKeyId": "YOUR_ACCESS_KEY",
|
|
235
|
+
"secretAccessKey": "YOUR_SECRET_KEY"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"backup": {
|
|
239
|
+
"format": "custom",
|
|
240
|
+
"compression": {
|
|
241
|
+
"enabled": true,
|
|
242
|
+
"level": 6
|
|
243
|
+
},
|
|
244
|
+
"encryption": {
|
|
245
|
+
"enabled": true,
|
|
246
|
+
"key": "64-character-hex-key-generated-with-openssl-or-node-crypto"
|
|
247
|
+
},
|
|
248
|
+
"retention": {
|
|
249
|
+
"enabled": true,
|
|
250
|
+
"maxBackups": 100,
|
|
251
|
+
"maxAgeDays": 30,
|
|
252
|
+
"minBackups": 5,
|
|
253
|
+
"runAfterBackup": true
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
"alerts": {
|
|
257
|
+
"email": {
|
|
258
|
+
"enabled": true,
|
|
259
|
+
"smtp": {
|
|
260
|
+
"host": "smtp.gmail.com",
|
|
261
|
+
"port": 587,
|
|
262
|
+
"secure": false,
|
|
263
|
+
"auth": {
|
|
264
|
+
"user": "your-email@gmail.com",
|
|
265
|
+
"pass": "your-app-password"
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
"from": "backups@yourapp.com",
|
|
269
|
+
"to": ["admin@yourapp.com"]
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Storage Providers
|
|
276
|
+
|
|
277
|
+
**Local:**
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
{ "storage": { "provider": "local", "local": { "path": "./backups" } } }
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**AWS S3:**
|
|
284
|
+
|
|
285
|
+
```json
|
|
286
|
+
{
|
|
287
|
+
"storage": {
|
|
288
|
+
"provider": "s3",
|
|
289
|
+
"s3": {
|
|
290
|
+
"bucket": "my-backups",
|
|
291
|
+
"region": "us-east-1",
|
|
292
|
+
"accessKeyId": "YOUR_KEY",
|
|
293
|
+
"secretAccessKey": "YOUR_SECRET"
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Required permissions: `s3:PutObject`, `s3:GetObject`, `s3:ListBucket`, `s3:DeleteObject`
|
|
300
|
+
|
|
301
|
+
**Cloudflare R2:**
|
|
302
|
+
|
|
303
|
+
```json
|
|
304
|
+
{
|
|
305
|
+
"storage": {
|
|
306
|
+
"provider": "r2",
|
|
307
|
+
"s3": {
|
|
308
|
+
"bucket": "my-backups",
|
|
309
|
+
"region": "auto",
|
|
310
|
+
"endpoint": "https://ACCOUNT_ID.r2.cloudflarestorage.com",
|
|
311
|
+
"accessKeyId": "YOUR_KEY",
|
|
312
|
+
"secretAccessKey": "YOUR_SECRET"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Cloudinary:**
|
|
319
|
+
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"storage": {
|
|
323
|
+
"provider": "cloudinary",
|
|
324
|
+
"cloudinary": {
|
|
325
|
+
"cloudName": "your-cloud",
|
|
326
|
+
"apiKey": "YOUR_KEY",
|
|
327
|
+
"apiSecret": "YOUR_SECRET"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
All cloud backups stored in `dbdock_backups/` folder with format: `backup-YYYY-MM-DD-HH-MM-SS-BACKUPID.sql`
|
|
334
|
+
|
|
335
|
+
### Retention Policy
|
|
336
|
+
|
|
337
|
+
Automatic cleanup to prevent storage bloat from frequent backups:
|
|
338
|
+
|
|
339
|
+
```json
|
|
340
|
+
{
|
|
341
|
+
"backup": {
|
|
342
|
+
"retention": {
|
|
343
|
+
"enabled": true,
|
|
344
|
+
"maxBackups": 100,
|
|
345
|
+
"maxAgeDays": 30,
|
|
346
|
+
"minBackups": 5,
|
|
347
|
+
"runAfterBackup": true
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
**How it works:**
|
|
354
|
+
|
|
355
|
+
- Keeps most recent `minBackups` (safety net, never deleted)
|
|
356
|
+
- Deletes backups exceeding `maxBackups` limit (oldest first)
|
|
357
|
+
- Deletes backups older than `maxAgeDays` (respecting minBackups)
|
|
358
|
+
- Runs automatically after each backup (if `runAfterBackup: true`)
|
|
359
|
+
- Manual cleanup: `npx dbdock cleanup`
|
|
360
|
+
|
|
361
|
+
**Safety features:**
|
|
362
|
+
|
|
363
|
+
- Always preserves `minBackups` most recent backups
|
|
364
|
+
- Shows preview before deletion
|
|
365
|
+
- Detailed logging of what was deleted
|
|
366
|
+
- Error handling for failed deletions
|
|
367
|
+
|
|
368
|
+
## Programmatic Usage
|
|
369
|
+
|
|
370
|
+
### NestJS Integration
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
import { Module } from '@nestjs/common';
|
|
374
|
+
import { DBDockModule } from 'dbdock';
|
|
375
|
+
|
|
376
|
+
@Module({
|
|
377
|
+
imports: [
|
|
378
|
+
DBDockModule.forRoot({
|
|
379
|
+
database: {
|
|
380
|
+
type: 'postgres',
|
|
381
|
+
host: 'localhost',
|
|
382
|
+
port: 5432,
|
|
383
|
+
username: 'postgres',
|
|
384
|
+
password: process.env.DB_PASSWORD,
|
|
385
|
+
database: 'myapp',
|
|
386
|
+
},
|
|
387
|
+
storage: {
|
|
388
|
+
provider: 's3',
|
|
389
|
+
s3: {
|
|
390
|
+
bucket: 'my-backups',
|
|
391
|
+
region: 'us-east-1',
|
|
392
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
393
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
backup: {
|
|
397
|
+
compression: { enabled: true, level: 6 },
|
|
398
|
+
encryption: { enabled: true, key: process.env.ENCRYPTION_KEY },
|
|
399
|
+
schedules: [
|
|
400
|
+
{ name: 'Daily Backup', cron: '0 2 * * *', enabled: true },
|
|
401
|
+
{ name: 'Weekly Full', cron: '0 0 * * 0', enabled: true },
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
}),
|
|
405
|
+
],
|
|
406
|
+
})
|
|
407
|
+
export class AppModule {}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Creating and Restoring Backups
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
import { BackupService } from 'dbdock';
|
|
414
|
+
|
|
415
|
+
@Injectable()
|
|
416
|
+
export class MyService {
|
|
417
|
+
constructor(private backupService: BackupService) {}
|
|
418
|
+
|
|
419
|
+
async createBackup() {
|
|
420
|
+
const result = await this.backupService.createBackup({
|
|
421
|
+
compress: true,
|
|
422
|
+
encrypt: true,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
console.log(`Backup created: ${result.metadata.id}`);
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async restore(backupId: string) {
|
|
430
|
+
await this.backupService.restoreBackup(backupId);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Schedule Management API
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
import { ScheduleManager } from 'dbdock';
|
|
439
|
+
|
|
440
|
+
const scheduleManager = new ScheduleManager();
|
|
441
|
+
|
|
442
|
+
scheduleManager.addSchedule({
|
|
443
|
+
name: 'Hourly Backup',
|
|
444
|
+
cron: '0 * * * *',
|
|
445
|
+
enabled: true,
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const schedules = scheduleManager.getSchedules();
|
|
449
|
+
console.log('All schedules:', schedules);
|
|
450
|
+
|
|
451
|
+
scheduleManager.updateSchedule('Hourly Backup', {
|
|
452
|
+
cron: '0 */2 * * *',
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
scheduleManager.enableSchedule('Daily Backup');
|
|
456
|
+
scheduleManager.disableSchedule('Weekly Full');
|
|
457
|
+
|
|
458
|
+
scheduleManager.removeSchedule('Old Schedule');
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Complete Example with Schedules
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
import { NestFactory } from '@nestjs/core';
|
|
465
|
+
import { AppModule } from './app.module';
|
|
466
|
+
import { ScheduleManager } from 'dbdock';
|
|
467
|
+
|
|
468
|
+
async function bootstrap() {
|
|
469
|
+
const scheduleManager = new ScheduleManager();
|
|
470
|
+
|
|
471
|
+
scheduleManager.addSchedule({
|
|
472
|
+
name: 'Daily Backup',
|
|
473
|
+
cron: '0 2 * * *',
|
|
474
|
+
enabled: true,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
scheduleManager.addSchedule({
|
|
478
|
+
name: 'Weekly Archive',
|
|
479
|
+
cron: '0 0 * * 0',
|
|
480
|
+
enabled: true,
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
const app = await NestFactory.create(AppModule);
|
|
484
|
+
await app.listen(3000);
|
|
485
|
+
|
|
486
|
+
console.log('Application started with scheduled backups');
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
bootstrap();
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
## Requirements
|
|
493
|
+
|
|
494
|
+
- Node.js 18 or higher
|
|
495
|
+
- PostgreSQL 12+
|
|
496
|
+
- PostgreSQL client tools (`pg_dump`, `pg_restore`, `psql`)
|
|
497
|
+
|
|
498
|
+
**Installing PostgreSQL client tools:**
|
|
499
|
+
|
|
500
|
+
```bash
|
|
501
|
+
# macOS
|
|
502
|
+
brew install postgresql
|
|
503
|
+
|
|
504
|
+
# Ubuntu/Debian
|
|
505
|
+
sudo apt-get install postgresql-client
|
|
506
|
+
|
|
507
|
+
# Windows
|
|
508
|
+
# Download from https://www.postgresql.org/download/windows/
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## Troubleshooting
|
|
512
|
+
|
|
513
|
+
Run `npx dbdock test` to verify your configuration.
|
|
514
|
+
|
|
515
|
+
### Common Issues
|
|
516
|
+
|
|
517
|
+
**pg_dump not found:**
|
|
518
|
+
|
|
519
|
+
```bash
|
|
520
|
+
# macOS
|
|
521
|
+
brew install postgresql
|
|
522
|
+
|
|
523
|
+
# Ubuntu/Debian
|
|
524
|
+
sudo apt-get install postgresql-client
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
**Database connection errors:**
|
|
528
|
+
|
|
529
|
+
- Verify `host`, `port`, `username`, `password`, `database` in config
|
|
530
|
+
- Test connection: `psql -h HOST -p PORT -U USERNAME -d DATABASE`
|
|
531
|
+
- Check PostgreSQL server is running
|
|
532
|
+
- Verify network/firewall allows connection
|
|
533
|
+
|
|
534
|
+
**Storage errors:**
|
|
535
|
+
|
|
536
|
+
_AWS S3:_
|
|
537
|
+
|
|
538
|
+
- Verify credentials are correct
|
|
539
|
+
- Ensure IAM user has permissions: `s3:PutObject`, `s3:GetObject`, `s3:ListBucket`, `s3:DeleteObject`
|
|
540
|
+
- Check bucket name and region
|
|
541
|
+
|
|
542
|
+
_Cloudflare R2:_
|
|
543
|
+
|
|
544
|
+
- Verify API token is correct
|
|
545
|
+
- Check endpoint URL format: `https://ACCOUNT_ID.r2.cloudflarestorage.com`
|
|
546
|
+
- Ensure bucket exists and is accessible
|
|
547
|
+
- Verify R2 credentials have read/write permissions
|
|
548
|
+
|
|
549
|
+
_Cloudinary:_
|
|
550
|
+
|
|
551
|
+
- Verify cloud name, API key, and secret are correct
|
|
552
|
+
- Check your Cloudinary account is active
|
|
553
|
+
- Ensure API credentials have media library access
|
|
554
|
+
|
|
555
|
+
**Encryption key errors:**
|
|
556
|
+
|
|
557
|
+
```bash
|
|
558
|
+
# Generate a valid 64-character hex key
|
|
559
|
+
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
560
|
+
|
|
561
|
+
# Must be exactly 64 hexadecimal characters (0-9, a-f, A-F)
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
**R2 restore not working:**
|
|
565
|
+
|
|
566
|
+
- Ensure backups are in `dbdock_backups/` folder
|
|
567
|
+
- Verify backup files are named with `.sql` extension
|
|
568
|
+
- Check endpoint configuration matches R2 account ID
|
|
569
|
+
|
|
570
|
+
**No backups found:**
|
|
571
|
+
|
|
572
|
+
- Local: Check files exist in configured path
|
|
573
|
+
- S3/R2: Verify files are in `dbdock_backups/` folder
|
|
574
|
+
- Cloudinary: Check Media Library for `dbdock_backups` folder
|
|
575
|
+
- Ensure files match pattern: `backup-*.sql`
|
|
576
|
+
|
|
577
|
+
DBDock shows clear, actionable error messages for all issues with specific troubleshooting steps.
|
|
578
|
+
|
|
579
|
+
## Documentation
|
|
580
|
+
|
|
581
|
+
📚 **[Full Documentation](https://dbdock.mintlify.app)** - Comprehensive guides, API reference, and examples
|
|
582
|
+
|
|
583
|
+
## Support
|
|
584
|
+
|
|
585
|
+
- 💬 **[Discussions](https://github.com/naheemolaide/dbdock-support/discussions)** - Ask questions and share ideas
|
|
586
|
+
- 🐛 **[Issues](https://github.com/naheemolaide/dbdock-support/issues)** - Report bugs and request features
|
|
587
|
+
|
|
588
|
+
## Links
|
|
589
|
+
|
|
590
|
+
- 📦 **[npm Package](https://www.npmjs.com/package/dbdock)**
|
|
591
|
+
- 📖 **[Documentation](https://dbdock.mintlify.app)**
|
|
592
|
+
- 💻 **[GitHub Repository](https://github.com/naheemolaide/dbdock-support)**
|
|
593
|
+
|
|
594
|
+
## License
|
|
595
|
+
|
|
596
|
+
MIT
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_TEMPLATES = void 0;
|
|
4
|
+
exports.renderTemplate = renderTemplate;
|
|
5
|
+
const alert_types_1 = require("./alert.types");
|
|
6
|
+
exports.DEFAULT_TEMPLATES = {
|
|
7
|
+
[alert_types_1.AlertType.BACKUP_SUCCESS]: {
|
|
8
|
+
subject: '✅ DBDock Backup Successful - {{database}}',
|
|
9
|
+
body: `
|
|
10
|
+
<h2>Backup Completed Successfully</h2>
|
|
11
|
+
<p>Your database backup has been completed successfully.</p>
|
|
12
|
+
|
|
13
|
+
<h3>Backup Details</h3>
|
|
14
|
+
<ul>
|
|
15
|
+
<li><strong>Database:</strong> {{database}}</li>
|
|
16
|
+
<li><strong>Backup ID:</strong> {{backupId}}</li>
|
|
17
|
+
<li><strong>Size:</strong> {{size}} MB</li>
|
|
18
|
+
<li><strong>Compressed Size:</strong> {{compressedSize}} MB</li>
|
|
19
|
+
<li><strong>Duration:</strong> {{duration}} seconds</li>
|
|
20
|
+
<li><strong>Timestamp:</strong> {{timestamp}}</li>
|
|
21
|
+
</ul>
|
|
22
|
+
|
|
23
|
+
{{#if downloadUrl}}
|
|
24
|
+
<h3>Download URL</h3>
|
|
25
|
+
<p><a href="{{downloadUrl}}">Download Backup</a> (valid for 7 days)</p>
|
|
26
|
+
{{/if}}
|
|
27
|
+
|
|
28
|
+
<p><em>This is an automated message from DBDock.</em></p>
|
|
29
|
+
`,
|
|
30
|
+
},
|
|
31
|
+
[alert_types_1.AlertType.BACKUP_FAILURE]: {
|
|
32
|
+
subject: '❌ DBDock Backup Failed - {{database}}',
|
|
33
|
+
body: `
|
|
34
|
+
<h2>Backup Failed</h2>
|
|
35
|
+
<p>Your database backup has failed.</p>
|
|
36
|
+
|
|
37
|
+
<h3>Backup Details</h3>
|
|
38
|
+
<ul>
|
|
39
|
+
<li><strong>Database:</strong> {{database}}</li>
|
|
40
|
+
<li><strong>Backup ID:</strong> {{backupId}}</li>
|
|
41
|
+
<li><strong>Timestamp:</strong> {{timestamp}}</li>
|
|
42
|
+
</ul>
|
|
43
|
+
|
|
44
|
+
<h3>Error Details</h3>
|
|
45
|
+
<pre style="background: #f5f5f5; padding: 10px; border-radius: 5px;">{{error}}</pre>
|
|
46
|
+
|
|
47
|
+
<p><strong>Action Required:</strong> Please check your database configuration and try again.</p>
|
|
48
|
+
|
|
49
|
+
<p><em>This is an automated message from DBDock.</em></p>
|
|
50
|
+
`,
|
|
51
|
+
},
|
|
52
|
+
[alert_types_1.AlertType.RETENTION_CLEANUP]: {
|
|
53
|
+
subject: '🗑️ DBDock Retention Cleanup Completed',
|
|
54
|
+
body: `
|
|
55
|
+
<h2>Retention Cleanup Completed</h2>
|
|
56
|
+
<p>Old backups have been cleaned up according to your retention policy.</p>
|
|
57
|
+
|
|
58
|
+
<h3>Cleanup Summary</h3>
|
|
59
|
+
<ul>
|
|
60
|
+
<li><strong>Backups Deleted:</strong> {{backupsDeleted}}</li>
|
|
61
|
+
<li><strong>WAL Files Deleted:</strong> {{walFilesDeleted}}</li>
|
|
62
|
+
<li><strong>Space Freed:</strong> {{spaceFreed}} MB</li>
|
|
63
|
+
<li><strong>Timestamp:</strong> {{timestamp}}</li>
|
|
64
|
+
</ul>
|
|
65
|
+
|
|
66
|
+
<p><em>This is an automated message from DBDock.</em></p>
|
|
67
|
+
`,
|
|
68
|
+
},
|
|
69
|
+
[alert_types_1.AlertType.STORAGE_ERROR]: {
|
|
70
|
+
subject: '⚠️ DBDock Storage Error',
|
|
71
|
+
body: `
|
|
72
|
+
<h2>Storage Error Detected</h2>
|
|
73
|
+
<p>An error occurred while accessing storage.</p>
|
|
74
|
+
|
|
75
|
+
<h3>Error Details</h3>
|
|
76
|
+
<pre style="background: #f5f5f5; padding: 10px; border-radius: 5px;">{{error}}</pre>
|
|
77
|
+
|
|
78
|
+
<p><strong>Action Required:</strong> Please check your storage configuration and credentials.</p>
|
|
79
|
+
|
|
80
|
+
<p><em>This is an automated message from DBDock.</em></p>
|
|
81
|
+
`,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
function renderTemplate(template, context) {
|
|
85
|
+
let rendered = template;
|
|
86
|
+
for (const [key, value] of Object.entries(context)) {
|
|
87
|
+
const stringValue = value !== undefined && value !== null ? String(value) : '';
|
|
88
|
+
rendered = rendered.replace(new RegExp(`{{${key}}}`, 'g'), stringValue);
|
|
89
|
+
}
|
|
90
|
+
rendered = rendered.replace(/{{#if\s+(\w+)}}([\s\S]*?){{\/if}}/g, (match, key, content) => {
|
|
91
|
+
return context[key] ? content : '';
|
|
92
|
+
});
|
|
93
|
+
return rendered;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=alert-templates.js.map
|