Class: BackupNexus::BackupConfig

Inherits:
BaseRecord
  • Object
show all
Defined in:
app/models/backup_nexus/backup_config.rb

Constant Summary collapse

ADAPTERS =
%w[mysql postgresql sqlite mongodb redis].freeze

Instance Method Summary collapse

Instance Method Details

#archive_excludes_listObject



88
89
90
91
# File 'app/models/backup_nexus/backup_config.rb', line 88

def archive_excludes_list
  return [] if archive_excludes.blank?
  archive_excludes.is_a?(Array) ? archive_excludes : JSON.parse(archive_excludes.to_s) rescue []
end

#archive_excludes_list=(value) ⇒ Object



93
94
95
96
97
98
99
100
# File 'app/models/backup_nexus/backup_config.rb', line 93

def archive_excludes_list=(value)
  return if value.blank?
  self.archive_excludes = if value.is_a?(String)
    value.split(",").map(&:strip).reject(&:blank?)
  else
    value
  end
end

#archive_paths_listObject

─── Archive Paths ─────────────────────────────────────────────



74
75
76
77
# File 'app/models/backup_nexus/backup_config.rb', line 74

def archive_paths_list
  return [] if archive_paths.blank?
  archive_paths.is_a?(Array) ? archive_paths : JSON.parse(archive_paths.to_s) rescue []
end

#archive_paths_list=(value) ⇒ Object



79
80
81
82
83
84
85
86
# File 'app/models/backup_nexus/backup_config.rb', line 79

def archive_paths_list=(value)
  return if value.blank?
  self.archive_paths = if value.is_a?(String)
    value.split(",").map(&:strip).reject(&:blank?)
  else
    value
  end
end

#dump_filenameObject



114
115
116
117
118
# File 'app/models/backup_nexus/backup_config.rb', line 114

def dump_filename
  timestamp = Time.current.strftime("%Y%m%d_%H%M%S")
  ext = dump_extension
  "#{name}_#{timestamp}.#{ext}"
end

#dump_filepathObject



120
121
122
# File 'app/models/backup_nexus/backup_config.rb', line 120

def dump_filepath
  File.join(storage_path_expanded, dump_filename)
end

#last_failureObject



129
130
131
# File 'app/models/backup_nexus/backup_config.rb', line 129

def last_failure
  BackupNexus::Backup.where(config_name: name, status: "failed").order(started_at: :desc).first
end

#mongodb?Boolean

Returns:

  • (Boolean)


106
# File 'app/models/backup_nexus/backup_config.rb', line 106

def mongodb?;       adapter == "mongodb";       end

#mysql?Boolean

─── Adapter checks ────────────────────────────────────────────

Returns:

  • (Boolean)


103
# File 'app/models/backup_nexus/backup_config.rb', line 103

def mysql?;         adapter == "mysql";        end

#postgresql?Boolean

Returns:

  • (Boolean)


104
# File 'app/models/backup_nexus/backup_config.rb', line 104

def postgresql?;    adapter == "postgresql";    end

#recent_backups(limit: 10) ⇒ Object

─── Stats ─────────────────────────────────────────────────────



125
126
127
# File 'app/models/backup_nexus/backup_config.rb', line 125

def recent_backups(limit: 10)
  BackupNexus::Backup.where(config_name: name).order(started_at: :desc).limit(limit)
end

#redis?Boolean

Returns:

  • (Boolean)


107
# File 'app/models/backup_nexus/backup_config.rb', line 107

def redis?;         adapter == "redis";         end

#skip_tables_listObject

─── Skip Tables ───────────────────────────────────────────────



59
60
61
62
# File 'app/models/backup_nexus/backup_config.rb', line 59

def skip_tables_list
  return [] if skip_tables.blank?
  skip_tables.is_a?(Array) ? skip_tables : JSON.parse(skip_tables.to_s) rescue []
end

#skip_tables_list=(value) ⇒ Object



64
65
66
67
68
69
70
71
# File 'app/models/backup_nexus/backup_config.rb', line 64

def skip_tables_list=(value)
  return if value.blank?
  self.skip_tables = if value.is_a?(String)
    value.split(",").map(&:strip).reject(&:blank?)
  else
    value
  end
end

#sqlite?Boolean

Returns:

  • (Boolean)


105
# File 'app/models/backup_nexus/backup_config.rb', line 105

def sqlite?;        adapter == "sqlite";        end

#statsObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/models/backup_nexus/backup_config.rb', line 133

def stats
  backups = BackupNexus::Backup.where(config_name: name)
  recent = backups.where("started_at >= ?", 7.days.ago)
  {
    total: backups.count,
    successful: backups.successful.count,
    failed: backups.failed.count,
    recent_count: recent.count,
    recent_success: recent.successful.count,
    recent_failed: recent.failed.count,
    last_backup: backups.successful.latest_first.first,
    total_size: backups.sum(:file_size).to_i,
    total_size_human: human_size(backups.sum(:file_size).to_i)
  }
end

#storage_path_expandedObject

─── Path helpers ──────────────────────────────────────────────



110
111
112
# File 'app/models/backup_nexus/backup_config.rb', line 110

def storage_path_expanded
  storage_path.gsub("~", Dir.home)
end