1
0
Fork 0
mirror of synced 2024-09-19 10:48:30 +12:00
budibase/packages/server/src/api/controllers/backup.js

42 lines
1 KiB
JavaScript
Raw Normal View History

2021-01-28 02:55:46 +13:00
const { performDump } = require("../../utilities/templates")
const path = require("path")
const os = require("os")
const fs = require("fs-extra")
exports.exportAppDump = async function(ctx) {
2021-01-30 10:52:45 +13:00
const { appId } = ctx.query
2021-01-28 02:55:46 +13:00
const backupsDir = path.join(os.homedir(), ".budibase", "backups")
fs.ensureDirSync(backupsDir)
const backupIdentifier = `${appId} Backup: ${new Date()}.txt`
await performDump({
dir: backupsDir,
appId,
name: backupIdentifier,
})
ctx.status = 200
2021-01-30 10:52:45 +13:00
const backupFile = path.join(backupsDir, backupIdentifier)
ctx.attachment(backupIdentifier)
ctx.body = fs.createReadStream(backupFile)
// ctx.body = {
// url: `/api/backups/download/${backupIdentifier}`,
// }
2021-01-28 02:55:46 +13:00
}
2021-01-30 10:52:45 +13:00
// exports.downloadAppDump = async function(ctx) {
// const fileName = ctx.params.fileName
2021-01-28 02:55:46 +13:00
2021-01-30 10:52:45 +13:00
// const backupsDir = path.join(os.homedir(), ".budibase", "backups")
// fs.ensureDirSync(backupsDir)
2021-01-28 02:55:46 +13:00
2021-01-30 10:52:45 +13:00
// const backupFile = path.join(backupsDir, fileName)
2021-01-28 02:55:46 +13:00
2021-01-30 10:52:45 +13:00
// ctx.attachment(fileName)
// ctx.body = fs.createReadStream(backupFile)
// }