2020-09-18 10:29:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# This script is used by BackupRestore.backup! and BackupRestore.restore!
|
|
|
|
|
2020-10-13 10:40:21 -05:00
|
|
|
fork do
|
|
|
|
require File.expand_path("../../config/environment", __FILE__)
|
2020-09-18 10:29:43 -05:00
|
|
|
|
2020-10-13 10:40:21 -05:00
|
|
|
def backup
|
|
|
|
user_id, opts = parse_params
|
|
|
|
BackupRestore::Backuper.new(user_id, opts).run
|
|
|
|
end
|
2020-09-18 10:29:43 -05:00
|
|
|
|
2020-10-13 10:40:21 -05:00
|
|
|
def restore
|
|
|
|
user_id, opts = parse_params
|
2020-09-18 10:29:43 -05:00
|
|
|
|
2020-10-13 10:40:21 -05:00
|
|
|
BackupRestore::Restorer.new(
|
2020-09-18 10:29:43 -05:00
|
|
|
user_id: user_id,
|
2020-10-13 10:40:21 -05:00
|
|
|
filename: opts[:filename],
|
2023-01-07 05:53:14 -06:00
|
|
|
factory: BackupRestore::Factory.new(user_id: user_id, client_id: opts[:client_id]),
|
|
|
|
disable_emails: opts.fetch(:disable_emails, true),
|
2020-10-13 10:40:21 -05:00
|
|
|
).run
|
|
|
|
end
|
2020-09-18 10:29:43 -05:00
|
|
|
|
2020-10-13 10:40:21 -05:00
|
|
|
def parse_params
|
|
|
|
user_id = ARGV[1].to_i
|
|
|
|
opts = JSON.parse(ARGV[2], symbolize_names: true)
|
|
|
|
[user_id, opts]
|
|
|
|
end
|
2020-09-18 10:29:43 -05:00
|
|
|
|
2020-10-13 10:40:21 -05:00
|
|
|
case ARGV[0]
|
|
|
|
when "backup"
|
|
|
|
backup
|
|
|
|
when "restore"
|
|
|
|
restore
|
|
|
|
else
|
|
|
|
raise "Unknown argument: #{ARGV[0]}"
|
|
|
|
end
|
2020-09-18 10:29:43 -05:00
|
|
|
end
|