You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the BackupDatabaseJob successfully creates and uploads backups of the database but does not automatically delete old backups. Over time, this could lead to storage accumulation, especially if backups are retained indefinitely.
This feature request proposes the addition of an automatic cleanup mechanism that deletes old backups after a configurable period, ensuring efficient disk usage and preventing backup directory bloat.
Proposed Solution
Add a method within BackupDatabaseJob to delete backups older than a configurable number of days (e.g., 7 days).
The method should:
Identify and delete .tar.gz files in the db/backups directory.
Calculate the file age using the file's mtime (modification time).
If the file is older than the configured maximum age (e.g., 7 days), delete the file.
Example logic:
ruby
Copy code
def cleanup_old_backups
backup_directory = "db/backups"
max_age_days = 7 # Number of days to keep backups
Dir.glob("#{backup_directory}/*.tar.gz").each do |file|
file_age_in_days = (Time.now - File.mtime(file)) / (60 * 60 * 24)
if file_age_in_days > max_age_days
File.delete(file)
Rails.logger.info "Deleted old backup file: #{file}"
end
end
end
Additional Considerations
Add configuration options to easily adjust the backup retention policy (e.g., via environment variables or settings).
Ensure proper logging of cleanup actions for traceability.
Optional: Provide an additional method to retain only the latest N backups, rather than using time-based deletion.
Related Files
app/jobs/backup_database_job.rb
Priority
Low/Medium (adjust based on your workflow)
The text was updated successfully, but these errors were encountered:
Currently, the
BackupDatabaseJob
successfully creates and uploads backups of the database but does not automatically delete old backups. Over time, this could lead to storage accumulation, especially if backups are retained indefinitely.This feature request proposes the addition of an automatic cleanup mechanism that deletes old backups after a configurable period, ensuring efficient disk usage and preventing backup directory bloat.
Proposed Solution
Add a method within
BackupDatabaseJob
to delete backups older than a configurable number of days (e.g., 7 days).The method should:
.tar.gz
files in thedb/backups
directory.mtime
(modification time).Example logic:
Additional Considerations
Related Files
app/jobs/backup_database_job.rb
Priority
Low/Medium (adjust based on your workflow)
The text was updated successfully, but these errors were encountered: