Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create database backup on server startup #3069

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dudantas
Copy link
Contributor

@dudantas dudantas commented Nov 7, 2024

Description

This update introduces a refined automatic database backup feature during the server startup process and periodic save intervals. The main improvements include:

  1. Conditional Compression: The database backup can now be compressed using gzip. When the compress parameter is set to true, the backup file is compressed, saving disk space. Compression is applied for interval-based saves, which happen every 2 hours, to reduce storage usage over time.

  2. Backup Management: The system now organizes backup files into folders named by date. It also automatically deletes old backups:

    • Non-compressed backups: Backups older than 7 days are deleted.
    • Compressed backups: These are deleted after 24 hours, but only if another non-compressed backup is loaded and the compressed file is older than 24 hours.
  3. Automatic Cleanup: Compressed backups are only deleted when a non-compressed backup is being created, and they are older than 24 hours. This mechanism prevents accumulation of outdated compressed backups while ensuring that recent backups remain accessible.

The motivation behind these changes is to create a more efficient and reliable way of managing database backups, ensuring data safety while optimizing storage space usage. The feature can be highly useful for production servers, as it creates backups during startup and periodically, minimizing risks of data loss while efficiently managing disk usage.

Behaviour

Actual

On server startup or during periodic saves, no database backup was created automatically, potentially putting the data at risk of loss. There was no effective mechanism for managing old backup files.

Expected

On server startup, a backup of the entire database is automatically created, including all tables and data types, ensuring data is always safeguarded. Periodic saves occur every 2 hours, and compressed backups are generated. Older backups are managed automatically:

  • Non-compressed backups older than 7 days are deleted.
  • Compressed backups older than 24 hours are deleted when a new non-compressed backup is created.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested

The database backup feature has been tested by:

  • Running the server multiple times to ensure that backups are correctly created on each startup.
  • Running periodic saves to verify that compressed backups are created every 2 hours.
  • Verifying the integrity of the SQL files by restoring the database from both compressed and non-compressed backup files.
  • Confirming that old backups (both compressed and non-compressed) are properly deleted based on the specified timeframes.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

@dudantas dudantas changed the title feat: create database backup feat: create database backup on server startup Nov 7, 2024
@dudantas dudantas force-pushed the dudantas/create-database-backup-on-server-startup branch from f23e8a5 to 95a9d3e Compare November 7, 2024 06:26
@dudantas dudantas force-pushed the dudantas/create-database-backup-on-server-startup branch from 5c988af to b453b80 Compare November 12, 2024 19:12
Copy link

sonarcloud bot commented Nov 14, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants