File tree Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 99 "node" : " ^12.20.0 || ^14.13.1 || >=16.0.0"
1010 },
1111 "scripts" : {
12- "start" : " NODE_ENV=dev tsc && node dist/app.js backup --name test- ref --source ~/Documents/Personal --dest ./dev" ,
12+ "start" : " NODE_ENV=dev tsc && node dist/app.js restore --ref 1bc41083-afd2-4b5e-8270-5e475844ba50 --dest ./dev/restore " ,
1313 "build" : " NODE_ENV=production tsc" ,
1414 "lint" : " NODE_ENV=test eslint \" {src,libs,test}/**/*.ts\" --fix" ,
1515 "test" : " echo \" WARN: no test specified\" && exit 0"
Original file line number Diff line number Diff line change 11#! /usr/bin/env node
22
33// Entrypoint to application
4- import { makeBackup } from './common/commands/backup.js'
4+ import { listBackups , makeBackup } from './common/commands/backup.js'
55import { parseArgs } from './common/commands/parsing.js'
66import { restoreBackup } from './common/commands/restore.js'
77import { ppRecord , sayHello } from './common/functions.js'
@@ -14,8 +14,8 @@ const cmdArgs = parseArgs()
1414
1515const run = async ( ) => {
1616 sayHello ( )
17- // Handle: Perform all app configurations first
1817
18+ // Handle: Perform all app configurations first
1919 if ( cmdArgs [ '_' ] . toString ( ) === 'config' ) {
2020 const conf = AppConfig . getInstance ( )
2121 const options = Object . keys ( cmdArgs ) . slice ( 1 )
@@ -62,6 +62,13 @@ const run = async () => {
6262 log ( `Backup with ID, ${ res } , successfully restored to ${ cmdArgs [ 'dest' ] } ` )
6363 break
6464 }
65+ case 'list' : {
66+ const err = await listBackups ( cmdArgs [ 'name' ] )
67+ if ( err ) {
68+ log ( `Could not list backups. Reason: ${ err . message } ` )
69+ }
70+ break
71+ }
6572 default : {
6673 log ( `WARN: Invalid command specified` )
6774 process . exit ( 2 )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import ora from 'ora'
22import { resolve } from 'path/posix'
33import { cwd } from 'process'
44import { BackupManager } from '../../lib/backup.js'
5+ import { DatabaseManager } from '../../lib/database.js'
56import { log } from '../../lib/logger.js'
67import { BackupRecord } from '../types.js'
78
@@ -27,6 +28,36 @@ export async function makeBackup(
2728 return [ null , err ]
2829 }
2930}
31+ export async function listBackups ( name ?: string ) : Promise < Error > {
32+ const db : DatabaseManager = DatabaseManager . getInstance ( )
33+ const [ records , err ] = await db . findAllRecords ( )
34+ if ( err ) return err
35+ let fRecords = records
36+
37+ if ( name && name . length > 0 ) {
38+ // Filter by name
39+ fRecords = fRecords . filter ( ( r ) => r . name . match ( name ) )
40+ }
41+
42+ if ( fRecords . length === 0 ) {
43+ log ( `No records were found ...` )
44+ return
45+ }
46+
47+ const tableData = fRecords . map ( ( r ) => {
48+ return {
49+ id : r . id ,
50+ name : r . name ,
51+ created : r . created ,
52+ type : r . type ,
53+ size : `${ Math . round ( r . bytelength / 1024 / 1024 ) } MB`
54+ }
55+ } )
56+
57+ // Print the result
58+ log ( `Found a total of ${ fRecords . length } record(s) matching list criteria...` )
59+ console . table ( tableData )
60+ }
3061
3162export async function differentialBackup (
3263 name : string ,
Original file line number Diff line number Diff line change @@ -28,6 +28,17 @@ export function parseArgs():
2828 } )
2929 } )
3030
31+ cmd . command (
32+ 'list' ,
33+ 'displays a list of all backups that are currently known by the system. Use --name to filter backups by name' ,
34+ ( yargs ) => {
35+ return yargs . option ( 'name' , {
36+ describe : 'An optional variable used for some info commands to refine info operations' ,
37+ type : 'string'
38+ } )
39+ }
40+ )
41+
3142 // Configure custom backups
3243 cmd . command ( 'backup' , 'performs a custom backup of a select directory(s)' , ( yargs ) => {
3344 return yargs
Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ export class DatabaseManager {
4040 }
4141 }
4242
43+ async findAllRecords ( ) : Promise < [ BackupRecord [ ] , Error ] > {
44+ try {
45+ return [ this . dbClient . data . backups , null ]
46+ } catch ( err ) {
47+ return [ null , err ]
48+ }
49+ }
50+
4351 findRecordById ( id : string , table : RecordTable = RecordTable . BACKUPS ) : [ BackupRecord , Error ] {
4452 try {
4553 let backup : BackupRecord
You can’t perform that action at this time.
0 commit comments