Minor fixes after testing manual backup system.

This commit is contained in:
mike12345567 2022-10-14 20:10:44 +01:00
parent 0bd2a18e46
commit 1373630b33
4 changed files with 41 additions and 31 deletions

View File

@ -53,6 +53,9 @@ export const getTenantIDFromAppID = (appId: string) => {
if (!appId) {
return null
}
if (!isMultiTenant()) {
return DEFAULT_TENANT_ID
}
const split = appId.split(SEPARATOR)
const hasDev = split[1] === DocumentType.DEV
if ((hasDev && split.length === 3) || (!hasDev && split.length === 2)) {

View File

@ -34,6 +34,8 @@ export { default as publicRoutes } from "./public"
const appBackupRoutes = api.appBackups
const scheduleRoutes = api.schedules
export const mainRoutes: Router[] = [
appBackupRoutes,
backupRoutes,
authRoutes,
deployRoutes,
layoutRoutes,
@ -53,16 +55,14 @@ export const mainRoutes: Router[] = [
permissionRoutes,
datasourceRoutes,
queryRoutes,
backupRoutes,
metadataRoutes,
devRoutes,
cloudRoutes,
// these need to be handled last as they still use /api/:tableId
// this could be breaking as koa may recognise other routes as this
tableRoutes,
rowRoutes,
migrationRoutes,
pluginRoutes,
appBackupRoutes,
scheduleRoutes,
// these need to be handled last as they still use /api/:tableId
// this could be breaking as koa may recognise other routes as this
tableRoutes,
]

View File

@ -10,30 +10,32 @@ export async function init() {
const appId = job.data.appId,
trigger = job.data.trigger,
name = job.data.name
const createdAt = new Date().toISOString()
const tarPath = await exportApp(appId, { tar: true })
let filename = `${appId}/backup-${createdAt}.tar.gz`
// add the tenant to the bucket path if backing up within a multi-tenant environment
if (env.MULTI_TENANCY) {
const tenantId = tenancy.getTenantIDFromAppID(appId)
filename = `${tenantId}/${filename}`
}
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
const metadata = {
appId,
createdAt,
trigger,
name,
}
await objectStore.upload({
path: tarPath,
type: "application/gzip",
bucket,
filename,
metadata,
const tenantId = tenancy.getTenantIDFromAppID(appId)
await tenancy.doInTenant(tenantId, async () => {
const createdAt = new Date().toISOString()
const tarPath = await exportApp(appId, { tar: true })
let filename = `${appId}/backup-${createdAt}.tar.gz`
// add the tenant to the bucket path if backing up within a multi-tenant environment
if (env.MULTI_TENANCY) {
filename = `${tenantId}/${filename}`
}
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
const metadata = {
appId,
createdAt,
trigger,
name,
}
await objectStore.upload({
path: tarPath,
type: "application/gzip",
bucket,
filename,
metadata,
})
await backups.storeAppBackupMetadata(filename, metadata)
// clear up the tarball after uploading it
fs.rmSync(tarPath)
})
await backups.storeAppBackupMetadata(filename, metadata)
// clear up the tarball after uploading it
fs.rmSync(tarPath)
})
}

View File

@ -7,7 +7,12 @@ export interface ContextUser extends User {
license: License
}
export interface BBContext extends Context {
export interface BBContext {
user?: ContextUser
body: any
request: {
body: any
}
params: any
body?: any
redirect?: any
}