Class: Appydave::Tools::Dam::S3Archiver

Inherits:
S3Base
  • Object
show all
Defined in:
lib/appydave/tools/dam/s3_archiver.rb

Overview

Handles S3 cleanup and SSD archive operations. Inherits shared infrastructure and helpers from S3Base.

Constant Summary

Constants inherited from S3Base

Appydave::Tools::Dam::S3Base::EXCLUDE_PATTERNS

Instance Attribute Summary

Attributes inherited from S3Base

#brand, #brand_info, #brand_path, #project_id

Instance Method Summary collapse

Methods inherited from S3Base

#build_s3_key, #extract_relative_path, #initialize, #s3_client

Constructor Details

This class inherits a constructor from Appydave::Tools::Dam::S3Base

Instance Method Details

#archive(force: false, dry_run: false) ⇒ Object

Archive project to SSD



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/appydave/tools/dam/s3_archiver.rb', line 101

def archive(force: false, dry_run: false)
  ssd_backup = brand_info.locations.ssd_backup

  unless ssd_backup && !ssd_backup.empty?
    puts "❌ SSD backup location not configured for brand '#{brand}'"
    return
  end

  unless Dir.exist?(ssd_backup)
    puts "❌ SSD not mounted at #{ssd_backup}"
    puts '   Please connect the SSD before archiving.'
    return
  end

  project_dir = project_directory_path

  unless Dir.exist?(project_dir)
    puts "❌ Project not found: #{project_dir}"
    puts ''
    puts "   Try: dam list #{brand}  # See available projects"
    return
  end

  ssd_project_dir = File.join(ssd_backup, project_id)

  puts "📦 Archive: #{brand}/#{project_id}"
  puts ''

  if copy_to_ssd(project_dir, ssd_project_dir, dry_run: dry_run)
    if force
      delete_local_project(project_dir, dry_run: dry_run)
    else
      puts ''
      puts '⚠️  Project copied to SSD but NOT deleted locally.'
      puts '   Use --force to delete local copy after archiving.'
    end
  end

  puts ''
  puts dry_run ? '✅ Archive dry-run complete!' : '✅ Archive complete!'
end

#cleanup(force: false, dry_run: false) ⇒ Object

Cleanup S3 files



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/appydave/tools/dam/s3_archiver.rb', line 10

def cleanup(force: false, dry_run: false)
  s3_files = list_s3_files

  if s3_files.empty?
    puts "❌ No files found in S3 for #{brand}/#{project_id}"
    return
  end

  puts "🗑️  Found #{s3_files.size} file(s) in S3 for #{brand}/#{project_id}"
  puts ''

  unless force
    puts '⚠️  This will DELETE all files from S3 for this project.'
    puts 'Use --force to confirm deletion.'
    return
  end

  deleted = 0
  failed = 0

  s3_files.each do |s3_file|
    key = s3_file['Key']
    relative_path = extract_relative_path(key)

    if delete_s3_file(key, dry_run: dry_run)
      puts "  ✓ Deleted: #{relative_path}"
      deleted += 1
    else
      puts "  ✗ Failed: #{relative_path}"
      failed += 1
    end
  end

  puts ''
  puts '✅ Cleanup complete!'
  puts "   Deleted: #{deleted}, Failed: #{failed}"
end

#cleanup_local(force: false, dry_run: false) ⇒ Object

Cleanup local s3-staging files



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/appydave/tools/dam/s3_archiver.rb', line 49

def cleanup_local(force: false, dry_run: false)
  project_dir = project_directory_path
  staging_dir = File.join(project_dir, 's3-staging')

  unless Dir.exist?(staging_dir)
    puts "❌ No s3-staging directory found: #{staging_dir}"
    return
  end

  files = Dir.glob("#{staging_dir}/**/*").select { |f| File.file?(f) }

  if files.empty?
    puts '❌ No files found in s3-staging/'
    return
  end

  puts "🗑️  Found #{files.size} file(s) in local s3-staging/"
  puts ''

  unless force
    puts '⚠️  This will DELETE all files from s3-staging/ for this project.'
    puts 'Use --force to confirm deletion.'
    return
  end

  deleted = 0
  failed = 0

  files.each do |file|
    relative_path = file.sub("#{staging_dir}/", '')

    if delete_local_file(file, dry_run: dry_run)
      puts "  ✓ Deleted: #{relative_path}"
      deleted += 1
    else
      puts "  ✗ Failed: #{relative_path}"
      failed += 1
    end
  end

  Dir.glob("#{staging_dir}/**/*").select { |d| File.directory?(d) }.sort.reverse.each do |dir|
    Dir.rmdir(dir) if Dir.empty?(dir)
  rescue StandardError
    nil
  end

  puts ''
  puts '✅ Local cleanup complete!'
  puts "   Deleted: #{deleted}, Failed: #{failed}"
end