|
| 1 | +require 'aws-sdk-s3' |
| 2 | + |
1 | 3 | desc "Update the development db to what is being used in prod" |
2 | | -BACKUP_CONTAINER_NAME = 'backups' |
| 4 | +BUCKET_NAME = "human-essentials-backups" |
3 | 5 | PASSWORD_REPLACEMENT = 'password' |
4 | 6 |
|
5 | 7 | task :fetch_latest_db do |
|
51 | 53 | private |
52 | 54 |
|
53 | 55 | def fetch_latest_backups |
54 | | - backups = blob_client.list_blobs(BACKUP_CONTAINER_NAME) |
| 56 | + backups = blob_client.list_objects_v2(bucket: BUCKET_NAME) |
55 | 57 |
|
56 | 58 | # |
57 | 59 | # Retrieve the most up to date version of the DB dump |
58 | 60 | # |
59 | 61 | backup = backups.select { |b| b.name.match?(".rds.dump") }.sort do |a,b| |
60 | | - Time.parse(a.properties[:last_modified]) <=> Time.parse(b.properties[:last_modified]) |
| 62 | + Time.parse(a.last_modified) <=> Time.parse(b.last_modified) |
61 | 63 | end.reverse.first |
62 | 64 |
|
63 | 65 | # |
64 | 66 | # Download each of the backups onto the local disk in tmp |
65 | 67 | # |
66 | 68 | filepath = fetch_file_path(backup) |
67 | 69 | puts "\nDownloading blob #{backup.name} to #{filepath}" |
68 | | - blob, content = blob_client.get_blob(BACKUP_CONTAINER_NAME, backup.name) |
69 | | - File.open(filepath, "wb") { |f| f.write(content) } |
| 70 | + blob_client.get_object(bucket: BUCKET_NAME, key: backup.name, response_target: filepath) |
70 | 71 |
|
71 | 72 | # |
72 | 73 | # At this point, the dumps should be stored on the local |
73 | 74 | # machine of the user under tmp. |
74 | 75 | # |
75 | | - return backup |
| 76 | + backup |
76 | 77 | end |
77 | 78 |
|
78 | 79 | def blob_client |
79 | | - return @blob_client if @blob_client |
80 | | - |
81 | | - account_name = ENV["AZURE_STORAGE_ACCOUNT_NAME"] |
82 | | - account_key = ENV["AZURE_STORAGE_ACCESS_KEY"] |
83 | | - |
84 | | - if account_name.blank? || account_key.blank? |
85 | | - raise "You must have the correct azure credentials in your ENV" |
86 | | - end |
87 | | - |
88 | | - @blob_client = Azure::Storage::Blob::BlobService.create( |
89 | | - storage_account_name: account_name, |
90 | | - storage_access_key: account_key |
91 | | - ) |
| 80 | + Aws::S3::Client.new |
92 | 81 | end |
93 | 82 |
|
94 | 83 | def fetch_file_path(backup) |
|
0 commit comments