Skip to content

Commit 71ea236

Browse files
authored
FIX: Use a valid value for disabling backups using backup_frequency (#34245)
In #33558 we removed automatic_backups_enabled setting, and instead rely on backup_frequency being blank to disable. There was a big oversight there with the site setting type system, which will coerce the value to an integer. It also makes it so you can't blank the value out in the UI. This is a "fix forward" solution where instead of "set to blank to disable" we do "set to 0 to disable". This works along the grain of the site setting type system for a workable fix where we don't have to deal with the irreversible migration in the previous change. We can potentially go and add in "nullable" to the type system at a later point.
1 parent 470b289 commit 71ea236

File tree

8 files changed

+33
-6
lines changed

8 files changed

+33
-6
lines changed

app/jobs/scheduled/schedule_backup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ScheduleBackup < ::Jobs::Scheduled
88
def execute(args)
99
delete_prior_to_n_days
1010
return if !SiteSetting.enable_backups?
11-
return if SiteSetting.backup_frequency.blank?
11+
return if SiteSetting.backup_frequency.zero?
1212

1313
store = BackupRestore::BackupStore.create
1414
if latest_backup = store.latest_file

config/locales/server.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ en:
20262026
allow_restore: "Allow restore, which can replace ALL site data! Leave disabled unless you plan to restore a backup"
20272027
maximum_backups: "The maximum amount of backups to keep. Older backups are automatically deleted"
20282028
remove_older_backups: "Remove backups older than the specified number of days. Leave blank to disable."
2029-
backup_frequency: "Specifies the interval, in days, at which automatic backups of the site are created. If set to 7, for example, a new backup will be generated every week. Leave blank to disable."
2029+
backup_frequency: "Specifies the interval, in days, at which automatic backups of the site are created. If set to 7, for example, a new backup will be generated every week. Set to 0 to disable."
20302030
s3_backup_bucket: "The remote bucket to hold backups. WARNING: Make sure it is a private bucket."
20312031
s3_endpoint: "The endpoint can be modified to backup to an S3 compatible service like DigitalOcean Spaces or Minio. WARNING: Leave blank if using AWS S3."
20322032
s3_configure_tombstone_policy: "Enable automatic deletion policy for tombstone uploads. IMPORTANT: If disabled, no space will be reclaimed after uploads are deleted."

config/site_settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,7 @@ backups:
31263126
client: true
31273127
default: ""
31283128
backup_frequency:
3129-
min: 1
3129+
min: 0
31303130
max: 30
31313131
default: 7
31323132
s3_backup_bucket:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
class ReplaceNullWithZeroInBackupFrequency < ActiveRecord::Migration[8.0]
3+
def change
4+
execute <<~SQL
5+
UPDATE site_settings
6+
SET value = 0
7+
WHERE name = 'backup_frequency'
8+
AND value IS NULL
9+
SQL
10+
end
11+
end

script/bulk_import/vanilla.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def execute
6363

6464
# SiteSetting.port = 3000
6565
# SiteSetting.permalink_normalizations = "/discussion\/(\d+)\/.*/discussion/\1"
66-
# SiteSetting.backup_frequency = nil
66+
# SiteSetting.backup_frequency = 0
6767
# SiteSetting.disable_emails = "non-staff"
6868
# SiteSetting.authorized_extensions = '*'
6969
# SiteSetting.max_image_size_kb = 102400

script/bulk_import/vbulletin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def initialize
4848

4949
def execute
5050
# enable as per requirement:
51-
# SiteSetting.backup_frequency = nil
51+
# SiteSetting.backup_frequency = 0
5252
# SiteSetting.disable_emails = "non-staff"
5353
# SiteSetting.authorized_extensions = '*'
5454
# SiteSetting.max_image_size_kb = 102400

script/bulk_import/vbulletin5.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def initialize
5858

5959
def execute
6060
# enable as per requirement:
61-
#SiteSetting.backup_frequency = nil
61+
#SiteSetting.backup_frequency = 0
6262
#SiteSetting.disable_emails = "non-staff"
6363
#SiteSetting.authorized_extensions = '*'
6464
#SiteSetting.max_image_size_kb = 102400

spec/lib/backup_restore/shared_examples_for_backup_store.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@
185185
scheduleBackup.expects(:delete_prior_to_n_days)
186186
scheduleBackup.perform
187187
end
188+
189+
it "doesn't run if SiteSetting.backup_frequency is set to 0" do
190+
base_backup_s3_url = "https://s3-backup-bucket.s3.dualstack.us-west-1.amazonaws.com"
191+
stub_request(:get, "#{base_backup_s3_url}/?list-type=2&prefix=default/").to_return(
192+
status: 200,
193+
body: "",
194+
headers: {
195+
},
196+
)
197+
stub_request(:head, "#{base_backup_s3_url}/").to_return(status: 200, body: "", headers: {})
198+
199+
SiteSetting.backup_frequency = 0
200+
scheduleBackup = Jobs::ScheduleBackup.new
201+
scheduleBackup.expects(:delete_prior_to_n_days)
202+
scheduleBackup.perform
203+
end
188204
end
189205

190206
describe "#file" do

0 commit comments

Comments
 (0)