donBarbos / telegram-bot-template

🤖 Template for telegram bot using postgres, pgbouncer, redis, docker, amplitude, prometheus, grafana, CI
GNU Lesser General Public License v3.0
240 stars 49 forks source link

Feature: Automatic database backups #294

Closed fordnox closed 3 weeks ago

fordnox commented 1 month ago

add to docker-compose.yml


  pgbackup:
    container_name: pgbackup
    image: prodrigestivill/postgres-backup-local
    restart: always
    volumes:
      - ./backup:/backups
    networks:
      - app
    depends_on:
      - postgres
    environment:
      - POSTGRES_HOST=postgres
      - POSTGRES_DB=${DB_NAME}
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASS}
      - POSTGRES_EXTRA_OPTS=-Z9 --schema=public --blobs
      - SCHEDULE=@every 0h30m00s
      - BACKUP_KEEP_DAYS=7
      - BACKUP_KEEP_WEEKS=4
      - BACKUP_KEEP_MONTHS=6
      - HEALTHCHECK_PORT=81

start

docker-compose up -d pgbackup

output

docker logs 1fc25aaab5d9
2024/08/09 07:11:35 Running version: v0.0.10
2024/08/09 07:11:35 new cron: @every 0h30m00s
2024/08/09 09:11:35 272 cmd: /backup.sh
2024/08/09 09:11:35 272: Creating dump of bot_db database from postgres...
2024/08/09 09:11:35 272: Replacing daily backup /backups/daily/bot_db-20240809.sql.gz file this last backup...
2024/08/09 09:11:35 272: '/backups/daily/bot_db-20240809.sql.gz' => '/backups/last/bot_db-20240809-091135.sql.gz'
2024/08/09 09:11:35 272: Replacing weekly backup /backups/weekly/bot_db-202432.sql.gz file this last backup...
2024/08/09 09:11:35 272: '/backups/weekly/bot_db-202432.sql.gz' => '/backups/last/bot_db-20240809-091135.sql.gz'
2024/08/09 09:11:35 272: Replacing monthly backup /backups/monthly/bot_db-202408.sql.gz file this last backup...
2024/08/09 09:11:35 272: '/backups/monthly/bot_db-202408.sql.gz' => '/backups/last/bot_db-20240809-091135.sql.gz'
2024/08/09 09:11:35 272: Point last backup file to this last backup...
2024/08/09 09:11:35 272: '/backups/last/bot_db-latest.sql.gz' -> 'bot_db-20240809-091135.sql.gz'
2024/08/09 09:11:35 272: Point latest daily backup to this last backup...
2024/08/09 09:11:35 272: '/backups/daily/bot_db-latest.sql.gz' -> 'bot_db-20240809.sql.gz'
2024/08/09 09:11:35 272: Point latest weekly backup to this last backup...
2024/08/09 09:11:35 272: '/backups/weekly/bot_db-latest.sql.gz' -> 'bot_db-202432.sql.gz'
2024/08/09 09:11:35 272: Point latest monthly backup to this last backup...
2024/08/09 09:11:35 272: '/backups/monthly/bot_db-latest.sql.gz' -> 'bot_db-202408.sql.gz'
2024/08/09 09:11:35 272: Cleaning older files for bot_db database from postgres...
2024/08/09 09:11:35 272: SQL backup created successfully
github-actions[bot] commented 1 month ago

Hello! 👋 Thank you for opening your first issue. We appreciate your contribution! 🎉

donBarbos commented 1 month ago

@fordnox nice idea! you can open PR, i'll accept him