feat: create database backup on server startup #3069
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This update introduces a refined automatic database backup feature during the server startup process and periodic save intervals. The main improvements include:
Conditional Compression: The database backup can now be compressed using gzip. When the
compress
parameter is set totrue
, 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.Backup Management: The system now organizes backup files into folders named by date. It also automatically deletes old backups:
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