-
Notifications
You must be signed in to change notification settings - Fork 43
/
db-backup.ts
29 lines (24 loc) · 953 Bytes
/
db-backup.ts
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
import { SqlClient, Error } from 'msnodesqlv8/types'
const sql: SqlClient = require('msnodesqlv8')
const connectionString = 'Driver={SQL Server Native Client 11.0};Server=(localdb)\\node;Database=AdventureWorks2019;Trusted_Connection=yes;'
const sqlQuery = `BACKUP DATABASE [AdventureWorks2019] TO DISK = N'H:\\sql server\\backups\\AdventureWorks2019.bak' WITH COPY_ONLY,
NOFORMAT, INIT, NAME = N'SampleDb-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10`
const query = sql.query(connectionString, sqlQuery, (err, rows, more) => {
more = more ?? false
if (more) return
console.error(`cb more ${more ? 'T' : 'F'}`)
if (err != null) {
console.error('cb err')
} else {
console.log('cb rows')
}
})
query.on('info', (info: Error) => {
console.log(`info: ${JSON.stringify(info)}`)
})
query.on('error', (e: Error) => {
console.log(`error: ${JSON.stringify(e)}`)
})
query.on('done', () => {
console.log('done')
})