1
0
Fork 0
mirror of synced 2024-07-01 04:21:06 +12:00

Minor fixes after testing manual backup system.

This commit is contained in:
mike12345567 2022-10-14 20:10:44 +01:00
parent a20ad3233e
commit 758c46ce83
4 changed files with 41 additions and 31 deletions

View file

@ -53,6 +53,9 @@ export const getTenantIDFromAppID = (appId: string) => {
if (!appId) { if (!appId) {
return null return null
} }
if (!isMultiTenant()) {
return DEFAULT_TENANT_ID
}
const split = appId.split(SEPARATOR) const split = appId.split(SEPARATOR)
const hasDev = split[1] === DocumentType.DEV const hasDev = split[1] === DocumentType.DEV
if ((hasDev && split.length === 3) || (!hasDev && split.length === 2)) { 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 appBackupRoutes = api.appBackups
const scheduleRoutes = api.schedules const scheduleRoutes = api.schedules
export const mainRoutes: Router[] = [ export const mainRoutes: Router[] = [
appBackupRoutes,
backupRoutes,
authRoutes, authRoutes,
deployRoutes, deployRoutes,
layoutRoutes, layoutRoutes,
@ -53,16 +55,14 @@ export const mainRoutes: Router[] = [
permissionRoutes, permissionRoutes,
datasourceRoutes, datasourceRoutes,
queryRoutes, queryRoutes,
backupRoutes,
metadataRoutes, metadataRoutes,
devRoutes, devRoutes,
cloudRoutes, 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, rowRoutes,
migrationRoutes, migrationRoutes,
pluginRoutes, pluginRoutes,
appBackupRoutes,
scheduleRoutes, 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,12 +10,13 @@ export async function init() {
const appId = job.data.appId, const appId = job.data.appId,
trigger = job.data.trigger, trigger = job.data.trigger,
name = job.data.name name = job.data.name
const tenantId = tenancy.getTenantIDFromAppID(appId)
await tenancy.doInTenant(tenantId, async () => {
const createdAt = new Date().toISOString() const createdAt = new Date().toISOString()
const tarPath = await exportApp(appId, { tar: true }) const tarPath = await exportApp(appId, { tar: true })
let filename = `${appId}/backup-${createdAt}.tar.gz` let filename = `${appId}/backup-${createdAt}.tar.gz`
// add the tenant to the bucket path if backing up within a multi-tenant environment // add the tenant to the bucket path if backing up within a multi-tenant environment
if (env.MULTI_TENANCY) { if (env.MULTI_TENANCY) {
const tenantId = tenancy.getTenantIDFromAppID(appId)
filename = `${tenantId}/${filename}` filename = `${tenantId}/${filename}`
} }
const bucket = objectStore.ObjectStoreBuckets.BACKUPS const bucket = objectStore.ObjectStoreBuckets.BACKUPS
@ -36,4 +37,5 @@ export async function init() {
// clear up the tarball after uploading it // clear up the tarball after uploading it
fs.rmSync(tarPath) fs.rmSync(tarPath)
}) })
})
} }

View file

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