ante-erp-cli 1.10.1 → 1.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/backup.js +41 -3
package/package.json
CHANGED
package/src/commands/backup.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import ora from 'ora';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
3
4
|
import { join } from 'path';
|
|
4
5
|
import { readdirSync, readFileSync } from 'fs';
|
|
5
6
|
import { execa } from 'execa';
|
|
@@ -7,6 +8,29 @@ import Table from 'cli-table3';
|
|
|
7
8
|
import { getInstallDir } from '../utils/config.js';
|
|
8
9
|
import { dumpDatabase, parseMongoUrl } from '../utils/mongodb.js';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Generate timestamp with AM/PM format
|
|
13
|
+
* @returns {string} Timestamp in format YYYY-MM-DD_HH-MM-SS-AM/PM
|
|
14
|
+
*/
|
|
15
|
+
function generateTimestamp() {
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const year = now.getFullYear();
|
|
18
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
19
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
20
|
+
|
|
21
|
+
let hours = now.getHours();
|
|
22
|
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
23
|
+
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
24
|
+
const ampm = hours >= 12 ? 'PM' : 'AM';
|
|
25
|
+
|
|
26
|
+
// Convert to 12-hour format
|
|
27
|
+
hours = hours % 12;
|
|
28
|
+
hours = hours ? hours : 12; // 0 should be 12
|
|
29
|
+
const hoursStr = String(hours).padStart(2, '0');
|
|
30
|
+
|
|
31
|
+
return `${year}-${month}-${day}_${hoursStr}-${minutes}-${seconds}-${ampm}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
10
34
|
/**
|
|
11
35
|
* Create backup of ANTE ERP databases (PostgreSQL and MongoDB)
|
|
12
36
|
*/
|
|
@@ -16,10 +40,24 @@ export async function backup(options) {
|
|
|
16
40
|
const composeFile = join(installDir, 'docker-compose.yml');
|
|
17
41
|
const backupDir = join(installDir, 'backups');
|
|
18
42
|
|
|
43
|
+
// Prompt for keyword if not provided via flag
|
|
44
|
+
let keyword = options.keyword;
|
|
45
|
+
if (!keyword) {
|
|
46
|
+
const { backupKeyword } = await inquirer.prompt([
|
|
47
|
+
{
|
|
48
|
+
type: 'input',
|
|
49
|
+
name: 'backupKeyword',
|
|
50
|
+
message: 'Add a keyword to identify this backup? (optional, press Enter to skip)',
|
|
51
|
+
default: ''
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
keyword = backupKeyword.trim();
|
|
55
|
+
}
|
|
56
|
+
|
|
19
57
|
// Generate backup filename with optional keyword
|
|
20
|
-
const timestamp =
|
|
21
|
-
const keywordPart =
|
|
22
|
-
? `-${
|
|
58
|
+
const timestamp = generateTimestamp();
|
|
59
|
+
const keywordPart = keyword
|
|
60
|
+
? `-${keyword.replace(/[^a-zA-Z0-9-_]/g, '-')}`
|
|
23
61
|
: '';
|
|
24
62
|
const backupFile = options.output || join(backupDir, `ante-backup-${timestamp}${keywordPart}.tar.gz`);
|
|
25
63
|
|