Class: Ruborg::Backup
- Inherits:
-
Object
- Object
- Ruborg::Backup
- Defined in:
- lib/ruborg/backup.rb
Overview
Backup operations using Borg
Instance Method Summary collapse
- #create(name: nil, remove_source: false) ⇒ Object
- #delete(archive_name) ⇒ Object
- #extract(archive_name, destination: ".", path: nil) ⇒ Object
-
#initialize(repository, config:, retention_mode: "standard", repo_name: nil, logger: nil, skip_hash_check: false, progress: nil) ⇒ Backup
constructor
A new instance of Backup.
- #list_archives ⇒ Object
Constructor Details
#initialize(repository, config:, retention_mode: "standard", repo_name: nil, logger: nil, skip_hash_check: false, progress: nil) ⇒ Backup
Returns a new instance of Backup.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruborg/backup.rb', line 6 def initialize(repository, config:, retention_mode: "standard", repo_name: nil, logger: nil, skip_hash_check: false, progress: nil) @repository = repository @config = config @retention_mode = retention_mode @repo_name = repo_name @logger = logger @skip_hash_check = skip_hash_check @progress = progress end |
Instance Method Details
#create(name: nil, remove_source: false) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/ruborg/backup.rb', line 17 def create(name: nil, remove_source: false) raise BorgError, "Repository does not exist" unless @repository.exists? if @retention_mode == "per_file" create_per_file_archives(name, remove_source) else create_standard_archive(name, remove_source) end end |
#delete(archive_name) ⇒ Object
324 325 326 327 328 329 |
# File 'lib/ruborg/backup.rb', line 324 def delete(archive_name) @logger&.info("Deleting archive: #{archive_name}") cmd = [@repository.borg_path, "delete", "#{@repository.path}::#{archive_name}"] execute_borg_command(cmd) @logger&.info("Archive deleted successfully: #{archive_name}") end |
#extract(archive_name, destination: ".", path: nil) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/ruborg/backup.rb', line 293 def extract(archive_name, destination: ".", path: nil) raise BorgError, "Repository does not exist" unless @repository.exists? extract_target = path ? "#{path} from #{archive_name}" : archive_name @logger&.info("Extracting #{extract_target} to #{destination}") cmd = [@repository.borg_path, "extract", "#{@repository.path}::#{archive_name}"] cmd << path if path # Change to destination directory if specified if destination == "." execute_borg_command(cmd) else require "fileutils" # Validate and normalize destination path validated_dest = validate_destination_path(destination) FileUtils.mkdir_p(validated_dest) unless File.directory?(validated_dest) Dir.chdir(validated_dest) do execute_borg_command(cmd) end end @logger&.info("Extraction completed successfully") end |
#list_archives ⇒ Object
320 321 322 |
# File 'lib/ruborg/backup.rb', line 320 def list_archives @repository.list end |