Skip to content

Commit 70363fa

Browse files
committed
Fix rake tasks
1 parent 95a9c21 commit 70363fa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/tasks/backup_db_rds.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ task :backup_db_rds => :environment do
1111
backup_filename = "#{Rails.env}-#{current_time}.rds.dump"
1212
system("PGPASSWORD='#{ENV["DIAPER_DB_PASSWORD"]}' pg_dump -Fc -v --host=#{ENV["DIAPER_DB_HOST"]} --username=#{ENV["DIAPER_DB_USERNAME"]} --dbname=#{ENV["DIAPER_DB_DATABASE"]} -f #{backup_filename}")
1313

14-
client = Aws::S3::Client.new
14+
client = Aws::S3::Client.new(region: 'us-east-2')
1515

1616
logger.info("Uploading #{backup_filename}")
1717
client.put_object(bucket: "human-essentials-backups", key: "backups/#{backup_filename}", body: File.read(backup_filename))

lib/tasks/fetch_latest_db.rake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ task :fetch_latest_db do
1515
system("bin/rails db:environment:set RAILS_ENV=development")
1616
system("bin/rails db:drop db:create")
1717

18-
puts "Restoring the database with #{backup.name}"
18+
puts "Restoring the database with #{backup.key}"
1919
backup_filepath = fetch_file_path(backup)
2020
db_username = ENV["PG_USERNAME"].presence || ENV["USER"].presence || "postgres"
2121
db_host = ENV["PG_HOST"].presence || "localhost"
@@ -58,16 +58,16 @@ def fetch_latest_backups
5858
#
5959
# Retrieve the most up to date version of the DB dump
6060
#
61-
backup = backups.select { |b| b.name.match?(".rds.dump") }.sort do |a,b|
61+
backup = backups.contents.select { |b| b.key.match?(".rds.dump") }.sort do |a,b|
6262
Time.parse(a.last_modified) <=> Time.parse(b.last_modified)
6363
end.reverse.first
6464

6565
#
6666
# Download each of the backups onto the local disk in tmp
6767
#
6868
filepath = fetch_file_path(backup)
69-
puts "\nDownloading blob #{backup.name} to #{filepath}"
70-
blob_client.get_object(bucket: BUCKET_NAME, key: backup.name, response_target: filepath)
69+
puts "\nDownloading blob #{backup.key} to #{filepath}"
70+
blob_client.get_object(bucket: BUCKET_NAME, key: backup.key, response_target: filepath)
7171

7272
#
7373
# At this point, the dumps should be stored on the local
@@ -77,11 +77,11 @@ def fetch_latest_backups
7777
end
7878

7979
def blob_client
80-
Aws::S3::Client.new
80+
Aws::S3::Client.new(region: 'us-east-2')
8181
end
8282

8383
def fetch_file_path(backup)
84-
File.join(Rails.root, 'tmp', backup.name)
84+
File.join(Rails.root, 'tmp', File.basename(backup.key))
8585
end
8686

8787
def replace_user_passwords

0 commit comments

Comments
 (0)