opentibiabr / canary

Canary Server 13.x for OpenTibia community.
https://docs.opentibiabr.com/
GNU General Public License v2.0
384 stars 638 forks source link

feat: create database backup on server startup #3069

Open dudantas opened 3 weeks ago

dudantas commented 3 weeks ago

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:

Type of change

How Has This Been Tested

The database backup feature has been tested by:

Checklist

sonarcloud[bot] commented 3 days ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud