FEATURE: Improve backup stats on admin dashboard

* Dashboard doesn't timeout anymore when Amazon S3 is used for backups
* Storage stats are now a proper report with the same caching rules
* Changing the backup_location, s3_backup_bucket or creating and deleting backups removes the report from the cache
* It shows the number of backups and the backup location
* It shows the used space for the correct backup location instead of always showing used space on local storage
* It shows the date of the last backup as relative date
This commit is contained in:
Gerhard Schlager
2018-12-14 23:14:46 +01:00
parent 040ddec63d
commit 1a8ca68ea3
20 changed files with 223 additions and 173 deletions

View File

@ -81,11 +81,19 @@ describe BackupRestore::S3BackupStore do
before { create_backups }
after(:all) { remove_backups }
it "doesn't delete files when cleanup is disabled" do
SiteSetting.maximum_backups = 1
SiteSetting.s3_disable_cleanup = true
describe "#delete_old" do
it "doesn't delete files when cleanup is disabled" do
SiteSetting.maximum_backups = 1
SiteSetting.s3_disable_cleanup = true
expect { store.delete_old }.to_not change { store.files }
expect { store.delete_old }.to_not change { store.files }
end
end
describe "#stats" do
it "returns nil for 'free_bytes'" do
expect(store.stats[:free_bytes]).to be_nil
end
end
end

View File

@ -29,6 +29,17 @@ shared_examples "backup store" do
expect(store.latest_file).to be_nil
end
end
describe "#stats" do
it "works when there are no files" do
stats = store.stats
expect(stats[:used_bytes]).to eq(0)
expect(stats).to have_key(:free_bytes)
expect(stats[:count]).to eq(0)
expect(stats[:last_backup_taken_at]).to be_nil
end
end
end
context "with backup files" do
@ -69,6 +80,18 @@ shared_examples "backup store" do
end
end
describe "#reset_cache" do
it "resets the storage stats report" do
report_type = "storage_stats"
report = Report.find(report_type)
Report.cache(report, 35.minutes)
expect(Report.find_cached(report_type)).to be_present
store.reset_cache
expect(Report.find_cached(report_type)).to be_nil
end
end
describe "#delete_old" do
it "does nothing if the number of files is <= maximum_backups" do
SiteSetting.maximum_backups = 3
@ -166,6 +189,17 @@ shared_examples "backup store" do
end
end
end
describe "#stats" do
it "returns the correct stats" do
stats = store.stats
expect(stats[:used_bytes]).to eq(57)
expect(stats).to have_key(:free_bytes)
expect(stats[:count]).to eq(3)
expect(stats[:last_backup_taken_at]).to eq(Time.parse("2018-09-13T15:10:00Z"))
end
end
end
end