-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup.js
37 lines (31 loc) · 1009 Bytes
/
backup.js
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
const fs = require('fs')
const StorageManager = require('@slynova/flydrive')
const Sentry = require('@sentry/node')
const getMySQLData = require('./get-mysql-data')
const getPostgreSQLData = require('./get-pgsql-data')
const configStorage = require('./config/storage')
const configSentry = require('./config/sentry')
const configMysql = require('./config/mysql')
const configPgsql = require('./config/pgsql')
const database = process.env.DATABASE || 'mysql'
Sentry.init(configSentry);
async function backup() {
try {
const storage = new StorageManager(configStorage)
switch (database) {
case 'mysql':
await getMySQLData(configMysql, async (filename, stream) => {
await storage.put(filename, stream)
})
break
case 'pg':
await getPostgreSQLData(configPgsql, async (filename, stream) => {
await storage.put(filename, stream)
})
break
}
} catch (err) {
Sentry.captureException(err)
}
}
module.exports = backup