Merge remote-tracking branch 'origin/feature/app-backups' into feature/backups-ui

This commit is contained in:
Peter Clement 2022-10-20 11:12:47 +01:00
commit 9d35e4f533
2 changed files with 37 additions and 21 deletions

View File

@ -1,6 +1,6 @@
import { backups } from "@budibase/pro"
import { objectStore, tenancy, db as dbCore } from "@budibase/backend-core"
import { AppBackupQueueData } from "@budibase/types"
import { db as dbCore, objectStore, tenancy } from "@budibase/backend-core"
import { AppBackupQueueData, AppBackupStatus } from "@budibase/types"
import { exportApp } from "./exports"
import { importApp } from "./imports"
import { calculateBackupStats } from "../statistics"
@ -42,6 +42,11 @@ async function importProcessor(job: Job) {
await removeExistingApp(devAppId)
await performImport(backupTarPath)
}
await backups.updateRestoreStatus(
data.docId,
data.docRev,
AppBackupStatus.COMPLETE
)
fs.rmSync(backupTarPath)
})
}
@ -64,13 +69,6 @@ async function exportProcessor(job: Job) {
filename = `${tenantId}/${filename}`
}
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
const metadata = {
appId: prodAppId,
timestamp,
trigger,
name,
contents,
}
await objectStore.upload({
path: tarPath,
type: "application/gzip",
@ -83,7 +81,13 @@ async function exportProcessor(job: Job) {
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
fs.rmSync(tarPath)
})

View File

@ -1,31 +1,41 @@
import { Document } from "../document"
export enum AppBackupType {
BACKUP = "backup",
RESTORE = "restore",
}
export enum AppBackupStatus {
STARTED = "started",
COMPLETE = "complete",
FAILED = "failed",
}
export enum AppBackupTrigger {
PUBLISH = "publish",
MANUAL = "manual",
SCHEDULED = "scheduled",
}
export enum AppBackupEventType {
EXPORT = "export",
IMPORT = "import",
}
export interface AppBackupMetadata {
appId: string
trigger: AppBackupTrigger
name?: string
createdBy?: string
timestamp: string
contents: {
export interface AppBackupContents {
datasources: string[]
screens: 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 {
filename: string
filename?: string
}
export type AppBackupFetchOpts = {
@ -38,8 +48,9 @@ export type AppBackupFetchOpts = {
}
export interface AppBackupQueueData {
eventType: AppBackupEventType
appId: string
docId: string
docRev: string
export?: {
trigger: AppBackupTrigger
name?: string
@ -47,5 +58,6 @@ export interface AppBackupQueueData {
}
import?: {
backupId: string
createdBy?: string
}
}