check backup v2 base

This commit is contained in:
Ruben Blanco 2024-04-18 10:28:22 +02:00
parent 4c528c4b5c
commit a0fc543707
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python3
import os
import datetime
import sys
def check_backups(directory, filenames):
# Obtener la fecha actual en formato año-mes-día
today = datetime.datetime.now().strftime("%Y-%m-%d")
missing_files = []
# Comprobar todos los archivos esperados
for base_name in filenames:
expected_filename = f"{base_name}-{today}.tar.gz"
full_path = os.path.join(directory, expected_filename)
if not os.path.exists(full_path):
missing_files.append(expected_filename)
if missing_files:
print(f"CRITICAL: Missing backup files in {directory}: " + ", ".join(missing_files))
return 2 # Código de salida para CRITICAL
print("OK: All backup files exist.")
return 0 # Código de salida para OK
if __name__ == "__main__":
# Chequear si se proporcionaron suficientes argumentos
if len(sys.argv) < 3:
print("Usage: {} <directory> <filename1> [<filename2> ...]".format(sys.argv[0]))
sys.exit(3) # Código de salida para UNKNOWN
backup_directory = sys.argv[1]
filenames = sys.argv[2:]
# Llamar a la función de comprobación y salir con el código de estado adecuado
result = check_backups(backup_directory, filenames)
sys.exit(result)