-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.old.js
More file actions
44 lines (35 loc) · 1.47 KB
/
index.old.js
File metadata and controls
44 lines (35 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// libs
import path from 'path'
import stayAwak from 'stay-awake'
// src
import { ensureDirectory, writeFile, readFile, logger, getRequestCount } from './utils'
import conf from './configuration'
import requestData from './requestData'
import downloadAttachmentsBySpace from './downloadAttachmentsBySpace'
import flatten from './flatten'
// FIXIT Backup generates duplicate milestones and labels
(async () => {
try {
stayAwak.prevent()
const startTimestamp = Date.now()
const root = await ensureDirectory(path.resolve(conf.outputDirectory))
const data = await requestData()
for (let space of data.spaces) {
if ( conf.blacklist.spaces.indexOf(space.name) > -1 ) {
continue
}
// create new directory for this space
const dirSpace = await ensureDirectory(path.join(root, space.name))
const fileOutputJSON = conf.outputStructure === 'flat' ? flatten( space ) : space
// write data space by space
await writeFile(path.join(dirSpace, 'backup.json'), JSON.stringify(fileOutputJSON))
// download attachments
await downloadAttachmentsBySpace(space, dirSpace)
}
stayAwak.allow()
logger.append(`Data backup completed in ${(Date.now() - startTimestamp) / 1000} seconds with ${getRequestCount()} requests`)
} catch (e) {
logger.append(e)
logger.append(e.stack)
}
})()