FEATURE: New site setting to enable a daily automatic backup

This commit is contained in:
Robin Ward 2014-03-12 13:26:51 -04:00
parent 9ca516e58d
commit 42ca83ece5
4 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,14 @@
require_dependency "backup_restore"
module Jobs
class CreateBackup < Jobs::Scheduled
every 1.day
sidekiq_options retry: false
def execute(args)
return unless SiteSetting.backup_daily?
BackupRestore.backup!(Discourse.system_user.id, false)
end
end
end

View file

@ -713,6 +713,7 @@ en:
allow_restore: "Allow restore, which can replace ALL site data! Leave false unless you plan to do restore a backup"
maximum_backups: "The maximum amount of backups to keep on disk. Older backups are automatically deleted"
backup_daily: "Automatically create a site backup once a day"
active_user_rate_limit_secs: "How frequently we update the 'last_seen_at' field, in seconds"
previous_visit_timeout_hours: "How long a visit lasts before we consider it the 'previous' visit, in hours"

View file

@ -416,6 +416,9 @@ backups:
maximum_backups:
client: true
default: 7
backup_daily:
client: false
default: false
uncategorized:

View file

@ -0,0 +1,18 @@
require 'spec_helper'
require_dependency 'jobs/scheduled/create_backup'
describe Jobs::CreateBackup do
it "does nothing when daily backups are disabled" do
SiteSetting.stubs(:backup_daily?).returns(false)
BackupRestore.expects(:backup!).never
Jobs::CreateBackup.new.execute({})
end
it "calls `backup!` when the daily backups are enabled" do
SiteSetting.stubs(:backup_daily?).returns(true)
BackupRestore.expects(:backup!).with(Discourse.system_user.id, false).once
Jobs::CreateBackup.new.execute({})
end
end