refactor(mikrotikBackupRoutes, mikrotikBackupScheduler, mikrotikApplyService): replace direct export command with file-based export method for improved reliability and error handling
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 3m59s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 3m59s
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
const { readServersFromS3 } = require('../routes/serversRoutes');
|
||||
const { createRosClient } = require('./mikrotikApplyService');
|
||||
const { createRosClient, fetchExportViaFile } = require('./mikrotikApplyService');
|
||||
const { saveBackupForServer } = require('../routes/mikrotikBackupRoutes');
|
||||
const { decrypt } = require('../utils/encryption');
|
||||
const { readS3TextObject } = require('../services/s3Service');
|
||||
@@ -53,32 +53,8 @@ async function getServerIdsFromUiSettings(logger) {
|
||||
}
|
||||
|
||||
async function fetchRouterExport(client) {
|
||||
// Используем /rest/execute с командой "/export compact terse", чтобы гарантированно получить вывод в ответе.
|
||||
const res = await client.command('execute', { script: '/export compact terse' });
|
||||
const data = res && res.data;
|
||||
if (!data) return '';
|
||||
|
||||
if (typeof data === 'string') return data;
|
||||
if (Array.isArray(data)) {
|
||||
// Некоторые версии могут вернуть массив строк/объектов
|
||||
return data
|
||||
.map((line) => {
|
||||
if (typeof line === 'string') return line;
|
||||
if (line && typeof line === 'object') {
|
||||
// Пытаемся собрать строку из полей, если они есть
|
||||
if (line.rsc) return String(line.rsc);
|
||||
if (line.config) return String(line.config);
|
||||
return JSON.stringify(line);
|
||||
}
|
||||
return String(line ?? '');
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
if (typeof data === 'object') {
|
||||
// Fallback: сериализуем объект
|
||||
return JSON.stringify(data, null, 2);
|
||||
}
|
||||
return String(data);
|
||||
// API не возвращает текст /export напрямую — экспортируем в файл, читаем, удаляем
|
||||
return fetchExportViaFile(client);
|
||||
}
|
||||
|
||||
async function runBackupOnce(logger) {
|
||||
|
||||
Reference in New Issue
Block a user