2015-03-26 14:21:27 +08:00
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class ScheduleBackup < Jobs::Scheduled
|
2015-11-12 23:14:49 +08:00
|
|
|
daily at: 0.hours
|
2015-03-26 14:21:27 +08:00
|
|
|
sidekiq_options retry: false
|
|
|
|
|
|
|
|
def execute(args)
|
2017-12-22 04:21:28 +08:00
|
|
|
return unless SiteSetting.enable_backups? && SiteSetting.automatic_backups_enabled?
|
2015-08-07 23:34:58 +08:00
|
|
|
|
|
|
|
if latest_backup = Backup.all[0]
|
2015-11-13 01:35:03 +08:00
|
|
|
date = File.ctime(latest_backup.path).getutc.to_date
|
|
|
|
return if (date + SiteSetting.backup_frequency.days) > Time.now.utc.to_date
|
2015-08-07 23:34:58 +08:00
|
|
|
end
|
|
|
|
|
2015-11-12 23:14:49 +08:00
|
|
|
Jobs.cancel_scheduled_job(:create_backup)
|
|
|
|
|
|
|
|
time_of_day = Time.parse(SiteSetting.backup_time_of_day)
|
|
|
|
seconds = time_of_day.hour.hours + time_of_day.min.minutes + rand(10.minutes)
|
|
|
|
|
|
|
|
Jobs.enqueue_in(seconds, :create_backup)
|
2015-03-26 14:21:27 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|