Class: BackupRestore::LocalBackupStore

Inherits:
BackupStore show all
Defined in:
lib/backup_restore/local_backup_store.rb

Constant Summary

Constants inherited from BackupStore

BackupStore::BackupFileExists, BackupStore::StorageError

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BackupStore

create, #delete_old, #files, #generate_upload_url, #latest_file, #reset_cache, #stats, #upload_file

Constructor Details

#initialize(opts = {}) ⇒ LocalBackupStore

Returns a new instance of LocalBackupStore.



23
24
25
# File 'lib/backup_restore/local_backup_store.rb', line 23

def initialize(opts = {})
  @base_directory = LocalBackupStore.base_directory(root_directory: opts[:root_directory])
end

Class Method Details

.base_directory(db: nil, root_directory: nil) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/backup_restore/local_backup_store.rb', line 5

def self.base_directory(db: nil, root_directory: nil)
  current_db = db || RailsMultisite::ConnectionManagement.current_db
  root_directory ||= File.join(Rails.root, "public", "backups")

  base_directory = File.join(root_directory, current_db)
  FileUtils.mkdir_p(base_directory) unless Dir.exist?(base_directory)
  base_directory
end

.chunk_path(identifier, filename, chunk_number) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/backup_restore/local_backup_store.rb', line 14

def self.chunk_path(identifier, filename, chunk_number)
  File.join(
    LocalBackupStore.base_directory,
    "tmp",
    identifier,
    "#{filename}.part#{chunk_number}",
  )
end

Instance Method Details

#delete_file(filename) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/backup_restore/local_backup_store.rb', line 36

def delete_file(filename)
  path = path_from_filename(filename)

  if File.exist?(path)
    File.delete(path)
    reset_cache
  end
end

#download_file(filename, destination, failure_message = "") ⇒ Object



45
46
47
48
# File 'lib/backup_restore/local_backup_store.rb', line 45

def download_file(filename, destination, failure_message = "")
  path = path_from_filename(filename)
  Discourse::Utils.execute_command("cp", path, destination, failure_message: failure_message)
end

#file(filename, include_download_source: false) ⇒ Object



31
32
33
34
# File 'lib/backup_restore/local_backup_store.rb', line 31

def file(filename, include_download_source: false)
  path = path_from_filename(filename)
  create_file_from_path(path, include_download_source) if File.exist?(path)
end

#remote?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/backup_restore/local_backup_store.rb', line 27

def remote?
  false
end