Class: BackupNexus::BackupController
- Inherits:
-
ApplicationController
- Object
- RailsNexus::ApplicationController
- ApplicationController
- BackupNexus::BackupController
- Defined in:
- app/controllers/backup_nexus/backup_controller.rb
Instance Method Summary collapse
-
#all_history ⇒ Object
GET /backup_nexus/backup/history.
-
#create ⇒ Object
POST /backup_nexus/backup.
-
#destroy ⇒ Object
DELETE /backup_nexus/backup/:id.
-
#edit ⇒ Object
GET /backup_nexus/backup/:id/edit.
-
#history ⇒ Object
GET /backup_nexus/backup/:id/history.
-
#index ⇒ Object
GET /backup_nexus/backup.
-
#new ⇒ Object
GET /backup_nexus/backup/new.
-
#trigger ⇒ Object
POST /backup_nexus/backup/:id/trigger.
-
#update ⇒ Object
PATCH /backup_nexus/backup/:id.
Methods included from ApplicationHelper
#backup_config_history_path, #backup_destroy_path, #backup_history_path, #backup_path, #backup_trigger_path, #backup_update_path, #edit_backup_path, #new_backup_path
Instance Method Details
#all_history ⇒ Object
GET /backup_nexus/backup/history
86 87 88 89 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 86 def all_history @records = BackupNexus::Backup.order(started_at: :desc).limit(100) render :history end |
#create ⇒ Object
POST /backup_nexus/backup
26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 26 def create @config = BackupNexus::BackupConfig.new(config_params) if @config.save redirect_to backup_path, notice: "Backup config '#{@config.name}' created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
DELETE /backup_nexus/backup/:id
55 56 57 58 59 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 55 def destroy name = @config.name @config.destroy redirect_to backup_path, notice: "Backup config '#{name}' deleted." end |
#edit ⇒ Object
GET /backup_nexus/backup/:id/edit
37 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 37 def edit; end |
#history ⇒ Object
GET /backup_nexus/backup/:id/history
78 79 80 81 82 83 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 78 def history @config = BackupNexus::BackupConfig.find(params[:id]) @records = BackupNexus::Backup.where(config_name: @config.name) .order(started_at: :desc) .limit(50) end |
#index ⇒ Object
GET /backup_nexus/backup
9 10 11 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 9 def index @configs = BackupNexus::BackupConfig.order(:name) end |
#new ⇒ Object
GET /backup_nexus/backup/new
14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 14 def new @config = BackupNexus::BackupConfig.new( adapter: "mysql", host: "localhost", port: 3306, storage_path: "~/dumps", keep_count: 30, compress: true ) end |
#trigger ⇒ Object
POST /backup_nexus/backup/:id/trigger
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 62 def trigger begin BackupNexus::BackupJob.perform_later(@config.id) redirect_to backup_path, notice: "Backup '#{@config.name}' started in background." rescue # Fallback to synchronous if Active Job is not configured result = BackupNexus::BackupService.run(@config) if result[:success] redirect_to backup_path, notice: "Backup '#{@config.name}' completed successfully." else redirect_to backup_path, alert: "Backup failed: #{result[:error]}" end end end |
#update ⇒ Object
PATCH /backup_nexus/backup/:id
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/backup_nexus/backup_controller.rb', line 40 def update # Strip blank password fields so they don't overwrite stored values filtered = config_params %w[password encryption_password gpg_password].each do |attr| filtered = filtered.except(attr) if filtered[attr].blank? end if @config.update(filtered) redirect_to backup_path, notice: "Backup config '#{@config.name}' updated." else render :edit, status: :unprocessable_entity end end |