Some type updates and processor handling for backup document being created before backup/restore occurs.
This commit is contained in:
parent
e5ebd97ecc
commit
6112d097af
|
@ -1,6 +1,6 @@
|
||||||
import { backups } from "@budibase/pro"
|
import { backups } from "@budibase/pro"
|
||||||
import { objectStore, tenancy, db as dbCore } from "@budibase/backend-core"
|
import { db as dbCore, objectStore, tenancy } from "@budibase/backend-core"
|
||||||
import { AppBackupQueueData } from "@budibase/types"
|
import { AppBackupQueueData, AppBackupStatus } from "@budibase/types"
|
||||||
import { exportApp } from "./exports"
|
import { exportApp } from "./exports"
|
||||||
import { importApp } from "./imports"
|
import { importApp } from "./imports"
|
||||||
import { calculateBackupStats } from "../statistics"
|
import { calculateBackupStats } from "../statistics"
|
||||||
|
@ -42,6 +42,11 @@ async function importProcessor(job: Job) {
|
||||||
await removeExistingApp(devAppId)
|
await removeExistingApp(devAppId)
|
||||||
await performImport(backupTarPath)
|
await performImport(backupTarPath)
|
||||||
}
|
}
|
||||||
|
await backups.updateRestoreStatus(
|
||||||
|
data.docId,
|
||||||
|
data.docRev,
|
||||||
|
AppBackupStatus.COMPLETE
|
||||||
|
)
|
||||||
fs.rmSync(backupTarPath)
|
fs.rmSync(backupTarPath)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -64,13 +69,6 @@ async function exportProcessor(job: Job) {
|
||||||
filename = `${tenantId}/${filename}`
|
filename = `${tenantId}/${filename}`
|
||||||
}
|
}
|
||||||
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
|
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
|
||||||
const metadata = {
|
|
||||||
appId: prodAppId,
|
|
||||||
timestamp,
|
|
||||||
trigger,
|
|
||||||
name,
|
|
||||||
contents,
|
|
||||||
}
|
|
||||||
await objectStore.upload({
|
await objectStore.upload({
|
||||||
path: tarPath,
|
path: tarPath,
|
||||||
type: "application/gzip",
|
type: "application/gzip",
|
||||||
|
@ -83,7 +81,13 @@ async function exportProcessor(job: Job) {
|
||||||
appId: prodAppId,
|
appId: prodAppId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
await backups.storeAppBackupMetadata(filename, metadata)
|
await backups.updateBackupStatus(
|
||||||
|
data.docId,
|
||||||
|
data.docRev,
|
||||||
|
AppBackupStatus.COMPLETE,
|
||||||
|
contents,
|
||||||
|
filename
|
||||||
|
)
|
||||||
// clear up the tarball after uploading it
|
// clear up the tarball after uploading it
|
||||||
fs.rmSync(tarPath)
|
fs.rmSync(tarPath)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,31 +1,41 @@
|
||||||
import { Document } from "../document"
|
import { Document } from "../document"
|
||||||
|
|
||||||
|
export enum AppBackupType {
|
||||||
|
BACKUP = "backup",
|
||||||
|
RESTORE = "restore",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum AppBackupStatus {
|
||||||
|
STARTED = "started",
|
||||||
|
COMPLETE = "complete",
|
||||||
|
FAILED = "failed",
|
||||||
|
}
|
||||||
|
|
||||||
export enum AppBackupTrigger {
|
export enum AppBackupTrigger {
|
||||||
PUBLISH = "publish",
|
PUBLISH = "publish",
|
||||||
MANUAL = "manual",
|
MANUAL = "manual",
|
||||||
SCHEDULED = "scheduled",
|
SCHEDULED = "scheduled",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AppBackupEventType {
|
export interface AppBackupContents {
|
||||||
EXPORT = "export",
|
|
||||||
IMPORT = "import",
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AppBackupMetadata {
|
|
||||||
appId: string
|
|
||||||
trigger: AppBackupTrigger
|
|
||||||
name?: string
|
|
||||||
createdBy?: string
|
|
||||||
timestamp: string
|
|
||||||
contents: {
|
|
||||||
datasources: string[]
|
datasources: string[]
|
||||||
screens: string[]
|
screens: string[]
|
||||||
automations: string[]
|
automations: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AppBackupMetadata {
|
||||||
|
appId: string
|
||||||
|
trigger?: AppBackupTrigger
|
||||||
|
type: AppBackupType
|
||||||
|
status: AppBackupStatus
|
||||||
|
name?: string
|
||||||
|
createdBy?: string
|
||||||
|
timestamp: string
|
||||||
|
contents?: AppBackupContents
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppBackup extends Document, AppBackupMetadata {
|
export interface AppBackup extends Document, AppBackupMetadata {
|
||||||
filename: string
|
filename?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AppBackupFetchOpts = {
|
export type AppBackupFetchOpts = {
|
||||||
|
@ -38,8 +48,9 @@ export type AppBackupFetchOpts = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppBackupQueueData {
|
export interface AppBackupQueueData {
|
||||||
eventType: AppBackupEventType
|
|
||||||
appId: string
|
appId: string
|
||||||
|
docId: string
|
||||||
|
docRev: string
|
||||||
export?: {
|
export?: {
|
||||||
trigger: AppBackupTrigger
|
trigger: AppBackupTrigger
|
||||||
name?: string
|
name?: string
|
||||||
|
@ -47,5 +58,6 @@ export interface AppBackupQueueData {
|
||||||
}
|
}
|
||||||
import?: {
|
import?: {
|
||||||
backupId: string
|
backupId: string
|
||||||
|
createdBy?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue