[A04.P005] Simplificado flujo de backup a único destino (X:)
- dasuten_exportar_srvv-fenix.rb: Backup directo a X: sin copia local - dasuten_exportar_diferencial_srvv-fenix.rb: Mismo patrón simplificado - dasuten_transferir_srvv-fenix-srv-ns8.rb: Solo copia share → /var/tmp - dasuten_restaurar_dasu-sql4.rb: Ajustado para leer output correcto Flujo simplificado: FULL: srvv-fenix → X:\ → /var/tmp/ → Drive DIF: srvv-fenix → X:\ → /var/tmp/ → Drive Eliminados pasos intermedios innecesarios (E:\BK_SQL\sysdasuten\)
This commit is contained in:
@@ -15,14 +15,12 @@ require 'json'
|
||||
|
||||
# Nombre del archivo con timestamp
|
||||
TIMESTAMP = Time.now.strftime('%Y%m%d_%H%M%S')
|
||||
BACKUP_DIR = "E:\\BK_SQL\\sysdasuten"
|
||||
BACKUP_FILE = "#{BACKUP_DIR}\\sysdasuten_DIF_#{TIMESTAMP}.bak"
|
||||
BACKUP_FILE = "X:\\sysdasuten_DIF_#{TIMESTAMP}.bak"
|
||||
|
||||
puts "[*] Dron: Exportar backup DIFERENCIAL DASUTEN"
|
||||
puts " Nodo: srvv-fenix"
|
||||
puts " Destino: #{BACKUP_FILE}"
|
||||
puts " Tipo: DIFFERENTIAL (solo cambios desde último backup completo)"
|
||||
puts " Directorio: #{BACKUP_DIR}"
|
||||
|
||||
begin
|
||||
# Autorizar candados primero (necesario para acceder a la bóveda)
|
||||
@@ -48,14 +46,8 @@ begin
|
||||
)
|
||||
puts "[+] Conectado a SQL Server en #{sql_host} (auth: Windows)"
|
||||
|
||||
# Crear directorio si no existe
|
||||
puts "\n[0/3] Verificando directorio..."
|
||||
mkdir_sql = "EXEC master.sys.xp_create_subdir '#{BACKUP_DIR}'"
|
||||
client.execute(mkdir_sql)
|
||||
puts "[+] Directorio asegurado: #{BACKUP_DIR}"
|
||||
|
||||
# Generar backup diferencial
|
||||
puts "\n[1/2] Generando backup diferencial..."
|
||||
# Generar backup diferencial directamente en share X:
|
||||
puts "\n[0/2] Generando backup diferencial en share X:..."
|
||||
start = Time.now
|
||||
|
||||
sql = <<~SQL.strip
|
||||
@@ -72,42 +64,51 @@ begin
|
||||
duracion = (Time.now - start).round(2)
|
||||
puts "[+] Backup diferencial generado en #{duracion} segundos"
|
||||
|
||||
# Obtener tamaño del archivo (vía PowerShell remoto o xp_fileexist)
|
||||
puts "\n[2/2] Verificando archivo..."
|
||||
|
||||
# Verificar archivo en share
|
||||
puts "\n[1/2] Verificando archivo en share..."
|
||||
begin
|
||||
file_result = client.execute("EXEC master.sys.xp_fileexist '#{BACKUP_FILE}'")
|
||||
file_info = file_result.first
|
||||
|
||||
if file_info && file_result.to_a.any? { |f| f['File Exists'] == 1 }
|
||||
puts "[+] Archivo verificado: #{BACKUP_FILE}"
|
||||
|
||||
# Obtener tamaño aproximado
|
||||
size_info = client.execute("SELECT size_bytes = (SELECT size * 8192 FROM sys.database_files WHERE name = 'sysdasuten')")
|
||||
puts " Tamaño BD base: #{size_info.to_a.first['size_bytes'].to_i / 1024 / 1024} MB"
|
||||
else
|
||||
puts "[!] Advertencia: No se pudo verificar existencia del archivo"
|
||||
end
|
||||
verify_ps = <<~PSCMD.strip
|
||||
if (Test-Path "#{BACKUP_FILE}") {
|
||||
$size = (Get-Item "#{BACKUP_FILE}").Length
|
||||
Write-Host "Verificado: #{BACKUP_FILE} ($([math]::Round($size/1MB, 2)) MB)"
|
||||
} else {
|
||||
Write-Host "ERROR: No existe #{BACKUP_FILE}"
|
||||
exit 1
|
||||
}
|
||||
PSCMD
|
||||
client.execute("EXEC xp_cmdshell 'powershell -Command \"#{verify_ps.gsub('"', '\"')}\"'")
|
||||
puts "[+] Archivo verificado"
|
||||
rescue => e
|
||||
puts "[!] Advertencia: #{e.message}"
|
||||
puts "[!] Error al verificar en X: - #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# Tamaño aproximado de la BD base
|
||||
puts "\n[2/2] Información de tamaño..."
|
||||
begin
|
||||
size_info = client.execute("SELECT size_bytes = (SELECT size * 8192 FROM sys.database_files WHERE name = 'sysdasuten')")
|
||||
puts " Tamaño BD base: #{size_info.to_a.first['size_bytes'].to_i / 1024 / 1024} MB"
|
||||
rescue => e
|
||||
puts "[!] No se pudo obtener tamaño: #{e.message}"
|
||||
end
|
||||
|
||||
# Output para orquestador
|
||||
output = {
|
||||
paso: 'export_differential_complete',
|
||||
backup_ruta: BACKUP_FILE,
|
||||
backup_ruta_unix: BACKUP_FILE.gsub('X:\\', '/mnt/ns8Disco2/bkps-dasuten/'),
|
||||
backup_tipo: 'differential',
|
||||
nodo: 'srvv-fenix',
|
||||
nodo_destino: 'srv-ns8',
|
||||
duracion: duracion,
|
||||
timestamp: Time.now.iso8601,
|
||||
siguiente_paso: 'transferir'
|
||||
siguiente_paso: 'upload_drive'
|
||||
}
|
||||
|
||||
puts "\n✅ Export diferencial completado"
|
||||
puts " Output: #{output.to_json}"
|
||||
|
||||
# Escribir output para que el orquestador lo lea
|
||||
File.write('/tmp/dron_export_dif_output.json', output.to_json)
|
||||
File.write('/tmp/dron_export_output.json', output.to_json)
|
||||
|
||||
rescue => e
|
||||
puts "[!] Error fatal: #{e.message}"
|
||||
|
||||
Reference in New Issue
Block a user