Skip to main content

Herramienta de backup PostgreSQL multiplataforma (Linux + Windows)

Project description

yeboyebo-backup-tools

Herramienta de backup PostgreSQL multiplataforma (Linux + Windows) con montaje remoto, replicacion, test de integridad y alertas por email.

Instalacion

pip install yeboyebo-backup-tools

# Opcional: logging remoto a Grafana Loki
pip install yeboyebo-backup-tools[loki]

Uso rapido

# Backup de todas las BBDD listadas en lista.txt
backup-tools db dump lista.txt
backup-tools -v db dump lista.txt        # con log detallado
backup-tools -vv db dump lista.txt       # con log muy detallado

# Restaurar el backup mas reciente de cada BBDD
backup-tools db restore lista.txt

# Dump + restore en servidor replica
backup-tools db replicate lista.txt

# Test de integridad: restaura cada backup en BBDD temporal y verifica
backup-tools db test lista.txt

# Sincronizar backups a NAS / disco remoto (ultimas 12h)
backup-tools file remote /mnt/nas //192.168.1.200/backups
backup-tools file remote /mnt/nas //192.168.1.200/backups 24   # ultimas 24h

# Informe diario por email: ficheros generados en las ultimas 24h
backup-tools resume

# Monitorizar conectividad (envia email si no responde)
backup-tools alive 192.168.1.1

# Gestion de parametros de configuracion
backup-tools config server_name MI_SERVIDOR
backup-tools config user_db postgres true    # true = ofuscar valor

# Version
backup-tools version

Acciones

Accion Argumentos Descripcion
db dump lista.txt Vuelca cada BBDD, comprime con gzip, verifica tamano minimo
db restore lista.txt Restaura el backup mas reciente de cada BBDD
db replicate lista.txt Dump local + restore en servidor replica (replicate_host_db)
db test lista.txt Restaura en BBDD temporal, comprueba integridad, envia email
file remote dir dispositivo [horas] Copia backups recientes a NAS/CIFS
resume (sin args) Informe diario por email de backups generados
alive host Ping a un host. Si falla, envia alerta por email
config param valor [true] Establece parametro en config.ini. true = ofuscar
version (sin args) Imprime la version

Configuracion

El fichero config.ini se busca en este orden:

  1. Variable de entorno BACKUP_TOOLS_CONFIG
  2. ~/.config/backup_tools/config.ini (XDG, recomendado)
  3. config.ini junto al modulo (legado)

Parametros principales:

Parametro Default Descripcion
days_alive 20 Dias de retencion de backups
local_folder_backups /backups Directorio donde se almacenan los backups
host_db 127.0.0.1 Host PostgreSQL
port_db 5432 Puerto PostgreSQL
user_db Usuario PostgreSQL (ofuscado)
pass_db Contrasena PostgreSQL (ofuscada)
replicate_host_db Host replica (para db replicate)
user_email Cuenta Gmail para envio de alertas
pass_email Contrasena Gmail (ofuscada)
list_mails Destinatarios de alertas (separados por coma)
current_copies 1 Nº de backups recientes en carpeta currents/
min_size 5000 Tamano minimo en bytes (alerta si es menor)
loki_url (monitor.yeboyebo.es) Endpoint Loki para logging remoto

Requisitos

  • Python >= 3.8
  • pg_dump, psql (PostgreSQL client tools)
  • Linux: mount/mount.cifs (solo para file remote)
  • Sin dependencias externas de sistema para tar, ping, find, touch (todo stdlib Python)

Compatibilidad Windows

Desde v1.1. Particularidades:

  • Montaje: net use en vez de mount/mount.cifs
  • nice no disponible (se ignora)
  • ping -n en vez de ping -c
  • Compresion via tarfile (stdlib), no requiere tar externo
  • Programar tareas con Task Scheduler en vez de cron

Ejemplo crontab

# Backup diario 3:17 AM
17 3 * * * cd /opt/backup_tools && backup-tools db dump lista.txt

# Replica a contingencia 5:17 AM
17 5 * * * cd /opt/backup_tools && backup-tools db replicate lista.txt

# Test integridad domingos 7:17 AM
17 7 * * 0 cd /opt/backup_tools && backup-tools db test lista.txt

# Informe diario 8:17 AM
17 8 * * * cd /opt/backup_tools && backup-tools resume

# Ping cada 30 min
*/30 * * * * cd /opt/backup_tools && backup-tools alive 192.168.1.1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yeboyebo_backup_tools-1.2.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yeboyebo_backup_tools-1.2.2-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file yeboyebo_backup_tools-1.2.2.tar.gz.

File metadata

  • Download URL: yeboyebo_backup_tools-1.2.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.14.4

File hashes

Hashes for yeboyebo_backup_tools-1.2.2.tar.gz
Algorithm Hash digest
SHA256 08f46d8ac857b4e9646fd1cadc9c316b7c32820118406e612f2ce77bcb4269d3
MD5 fe9c633b4c6ae8e43ec73425de7c8536
BLAKE2b-256 d713935c3bc341785b06d765cd54cf773ec0cf8d2805f9b3d58a16b0c67e0a40

See more details on using hashes here.

File details

Details for the file yeboyebo_backup_tools-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for yeboyebo_backup_tools-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e56509260bab0965d21953faedc72ede4a6b3d851aa59e428e08a7175a2afec
MD5 f666dab8de7a9baa7f30b406cfbbf561
BLAKE2b-256 a33de38eb817caec5b047db6f6b216ddcea4be6fd8866210ab5b999ab5a84697

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page