97 lines
3.1 KiB
Ruby
97 lines
3.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# ==========================================================
|
|
# adn/tools/bkps/lib/proc_dasuten.rb
|
|
# ==========================================================
|
|
# Procesador de Backups DASUTEN
|
|
# Integra pipeline de backups en bkps.rb
|
|
# ==========================================================
|
|
|
|
module ADN
|
|
module BKPs
|
|
module Procesador
|
|
class Dasuten
|
|
DRONES_DIR = File.join(
|
|
File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))),
|
|
'cli', 'drones'
|
|
)
|
|
|
|
SCRIPTS = {
|
|
'dasuten_export_full' => 'dasuten_exportar_srvv-fenix.rb',
|
|
'dasuten_export_dif' => 'dasuten_exportar_diferencial_srvv-fenix.rb',
|
|
'dasuten_transferir' => 'dasuten_transferir_srvv-fenix-srv-ns8.rb',
|
|
'dasuten_upload' => 'dasuten_upload_srv-ns8-drive.rb',
|
|
'dasuten_download' => 'dasuten_download_drive-dasu-sql4.rb',
|
|
'dasuten_restaurar_full' => 'dasuten_restaurar_dasu-sql4.rb',
|
|
'dasuten_restaurar_dif' => 'dasuten_restaurar_diferencial_dasu-sql4.rb',
|
|
'dasuten_verificar' => 'dasuten_verificar-integridad_dasu-sql4.rb',
|
|
}.freeze
|
|
|
|
def initialize(logger)
|
|
@logger = logger
|
|
@dron_runner = File.join(
|
|
File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))),
|
|
'tools', 'run'
|
|
)
|
|
end
|
|
|
|
def ejecutar(tarea)
|
|
script_name = SCRIPTS[tarea[:id]]
|
|
unless script_name
|
|
@logger.error("Tarea DASUTEN desconocida: #{tarea[:id]}")
|
|
return false
|
|
end
|
|
|
|
script_path = File.join(DRONES_DIR, script_name)
|
|
unless File.exist?(script_path)
|
|
@logger.error("Script no encontrado: #{script_path}")
|
|
return false
|
|
end
|
|
|
|
nodo = tarea[:nodo] || detectar_nodo(tarea[:id])
|
|
nota = tarea[:texto] || "DASUTEN: #{tarea[:id]}"
|
|
|
|
# Lanzar dron con bitácora automática
|
|
cmd = "#{@dron_runner} dron lanzar --nota #{Shellwords.escape(nota)} --nodo #{Shellwords.escape(nodo)} -- ruby #{script_path}"
|
|
|
|
@logger.info("Ejecutando dron: #{nota}")
|
|
@logger.debug("Comando: #{cmd}")
|
|
|
|
exito = system(cmd)
|
|
codigo = $?.exitstatus
|
|
|
|
if exito
|
|
@logger.info("✅ Dron completado (código: #{codigo})")
|
|
true
|
|
else
|
|
@logger.error("❌ Dron fallido (código: #{codigo})")
|
|
false
|
|
end
|
|
end
|
|
|
|
# Para modo atómico (no aplica en DASUTEN - todos son pipelines)
|
|
def ejecutar_uno(tarea, archivo)
|
|
@logger.warn("Modo atómico no soportado para DASUTEN")
|
|
ejecutar(tarea)
|
|
end
|
|
|
|
# Listar archivos pendientes (no aplica - pipeline fijo)
|
|
def listar(tarea)
|
|
[]
|
|
end
|
|
|
|
private
|
|
|
|
def detectar_nodo(tarea_id)
|
|
case tarea_id
|
|
when /export/ then 'srvv-fenix'
|
|
when /transferir/, /upload/ then 'srv-ns8'
|
|
when /download/, /restaurar/, /verificar/ then 'dasu-sql4'
|
|
else 'srv-dasu'
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|