Module: OllamaChat::Utils::Backup

Included in:
Tools::Concern
Defined in:
lib/ollama_chat/utils/backup.rb

Overview

Utility module for handling file backups. This module provides methods to create timestamped copies of files in a designated backup directory within the XDG state home.

Instance Method Summary collapse

Instance Method Details

#perform_backup(path) ⇒ Pathname

Creates a timestamped backup of the specified file.

The backup is stored in OC::XDG_STATE_HOME/backups, preserving the original directory structure.

Parameters:

  • path (Pathname, String)

    the path to the file that should be backed up.

Returns:

  • (Pathname)

    backup path to the file that was created for backup



12
13
14
15
16
17
18
19
20
# File 'lib/ollama_chat/utils/backup.rb', line 12

def perform_backup(path)
  path.exist? or return
  backups_dir = OC::XDG_STATE_HOME + 'backups'
  timestamp   = Time.now.strftime('%Y%m%d%H%M%S')
  backup_path = Pathname.new(backups_dir.to_s + path.to_s + ?- + timestamp)
  backup_path.dirname.mkpath
  FileUtils.cp path, backup_path
  backup_path
end