@budibase/cli 3.38.5 → 3.39.15
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/dist/index.js +308 -308
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
- package/src/backups/objectStore.ts +35 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.39.15",
|
|
4
4
|
"description": "Budibase CLI, for developers, self hosting and migrations.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"@types/pouchdb": "^6.4.0",
|
|
42
42
|
"ts-node": "10.8.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "e409b00d4727dd9f3c5ba22401aa3d0d8c062cba"
|
|
45
45
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { objectStore } from "@budibase/backend-core"
|
|
2
2
|
import fs from "fs"
|
|
3
|
-
import { join } from "path"
|
|
3
|
+
import { dirname, join } from "path"
|
|
4
4
|
import { TEMP_DIR, MINIO_DIR } from "./utils"
|
|
5
5
|
import { progressBar } from "../utils"
|
|
6
6
|
import * as stream from "node:stream"
|
|
7
|
+
import { pipeline } from "stream/promises"
|
|
7
8
|
|
|
8
9
|
const {
|
|
9
10
|
ObjectStoreBuckets,
|
|
@@ -15,10 +16,36 @@ const {
|
|
|
15
16
|
|
|
16
17
|
const bucketList = Object.values(ObjectStoreBuckets)
|
|
17
18
|
|
|
19
|
+
type BackupObject = {
|
|
20
|
+
bucket: string
|
|
21
|
+
Key: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function listBucketObjects(
|
|
25
|
+
client: ReturnType<typeof ObjectStore>,
|
|
26
|
+
bucket: string
|
|
27
|
+
) {
|
|
28
|
+
const objects: BackupObject[] = []
|
|
29
|
+
let continuationToken: string | undefined
|
|
30
|
+
do {
|
|
31
|
+
const list = await client.listObjectsV2({
|
|
32
|
+
Bucket: bucket,
|
|
33
|
+
ContinuationToken: continuationToken,
|
|
34
|
+
})
|
|
35
|
+
objects.push(
|
|
36
|
+
...(list.Contents?.filter(
|
|
37
|
+
(object): object is typeof object & { Key: string } => !!object.Key
|
|
38
|
+
).map(object => ({ ...object, bucket, Key: object.Key })) || [])
|
|
39
|
+
)
|
|
40
|
+
continuationToken = list.NextContinuationToken
|
|
41
|
+
} while (continuationToken)
|
|
42
|
+
return objects
|
|
43
|
+
}
|
|
44
|
+
|
|
18
45
|
export async function exportObjects() {
|
|
19
46
|
const path = join(TEMP_DIR, MINIO_DIR)
|
|
20
|
-
fs.mkdirSync(path)
|
|
21
|
-
let fullList:
|
|
47
|
+
fs.mkdirSync(path, { recursive: true })
|
|
48
|
+
let fullList: BackupObject[] = []
|
|
22
49
|
let errorCount = 0
|
|
23
50
|
for (let bucket of bucketList) {
|
|
24
51
|
const client = ObjectStore()
|
|
@@ -30,12 +57,7 @@ export async function exportObjects() {
|
|
|
30
57
|
errorCount++
|
|
31
58
|
continue
|
|
32
59
|
}
|
|
33
|
-
|
|
34
|
-
Bucket: bucket,
|
|
35
|
-
})
|
|
36
|
-
fullList = fullList.concat(
|
|
37
|
-
list.Contents?.map(el => ({ ...el, bucket })) || []
|
|
38
|
-
)
|
|
60
|
+
fullList = fullList.concat(await listBucketObjects(client, bucket))
|
|
39
61
|
}
|
|
40
62
|
if (errorCount === bucketList.length) {
|
|
41
63
|
throw new Error("Unable to access MinIO/S3 - check environment config.")
|
|
@@ -46,16 +68,12 @@ export async function exportObjects() {
|
|
|
46
68
|
const filename = object.Key
|
|
47
69
|
const data = await retrieve(object.bucket, filename)
|
|
48
70
|
const possiblePath = filename.split("/")
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
fs.mkdirSync(join(path, object.bucket, ...dirs), { recursive: true })
|
|
52
|
-
}
|
|
71
|
+
const destination = join(path, object.bucket, ...possiblePath)
|
|
72
|
+
fs.mkdirSync(dirname(destination), { recursive: true })
|
|
53
73
|
if (data instanceof stream.Readable) {
|
|
54
|
-
data.
|
|
55
|
-
fs.createWriteStream(join(path, object.bucket, ...possiblePath))
|
|
56
|
-
)
|
|
74
|
+
await pipeline(data, fs.createWriteStream(destination))
|
|
57
75
|
} else {
|
|
58
|
-
fs.writeFileSync(
|
|
76
|
+
fs.writeFileSync(destination, data)
|
|
59
77
|
}
|
|
60
78
|
bar.update(++count)
|
|
61
79
|
}
|