BUGFIX: S3 backups failed when using a region

TRIVIAL: updated fog gem to latest version (1.22.1)
BUGFIX: fixed algorithm used to remove old backups
This commit is contained in:
Régis Hanol
2014-07-08 20:46:08 +02:00
parent ba06a6b0d2
commit 7658b72556
3 changed files with 38 additions and 19 deletions

View File

@ -102,7 +102,7 @@ gem 'fast_xs'
gem 'fast_xor' gem 'fast_xor'
gem 'fastimage' gem 'fastimage'
gem 'fog', '1.18.0', require: false gem 'fog', '1.22.1', require: false
gem 'unf', require: false gem 'unf', require: false
# see: https://twitter.com/samsaffron/status/412360162297393152 # see: https://twitter.com/samsaffron/status/412360162297393152

View File

@ -85,7 +85,7 @@ GEM
handlebars-source (~> 1.0) handlebars-source (~> 1.0)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.0.3) eventmachine (1.0.3)
excon (0.28.0) excon (0.37.0)
execjs (2.1.0) execjs (2.1.0)
exifr (1.1.3) exifr (1.1.3)
fabrication (2.9.8) fabrication (2.9.8)
@ -105,20 +105,29 @@ GEM
ffi (1.9.3) ffi (1.9.3)
flamegraph (0.0.5) flamegraph (0.0.5)
fast_stack fast_stack
fog (1.18.0) fog (1.22.1)
fog-brightbox
fog-core (~> 1.22)
fog-json
ipaddress (~> 0.5)
nokogiri (~> 1.5, >= 1.5.11)
fog-brightbox (0.1.1)
fog-core (~> 1.22)
fog-json
inflecto
fog-core (1.22.0)
builder builder
excon (~> 0.28.0) excon (~> 0.33)
formatador (~> 0.2.0) formatador (~> 0.2)
mime-types mime-types
multi_json (~> 1.0)
net-scp (~> 1.1) net-scp (~> 1.1)
net-ssh (>= 2.1.3) net-ssh (>= 2.1.3)
nokogiri (~> 1.5) fog-json (1.0.0)
ruby-hmac multi_json (~> 1.0)
foreman (0.63.0) foreman (0.63.0)
dotenv (>= 0.7) dotenv (>= 0.7)
thor (>= 0.13.6) thor (>= 0.13.6)
formatador (0.2.4) formatador (0.2.5)
fspath (2.0.6) fspath (2.0.6)
gctools (0.2.3) gctools (0.2.3)
given_core (3.5.4) given_core (3.5.4)
@ -139,6 +148,8 @@ GEM
progress (~> 3.0.0) progress (~> 3.0.0)
image_size (1.1.5) image_size (1.1.5)
in_threads (1.2.0) in_threads (1.2.0)
inflecto (0.0.2)
ipaddress (0.8.0)
jquery-rails (3.1.0) jquery-rails (3.1.0)
railties (>= 3.0, < 5.0) railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
@ -175,9 +186,9 @@ GEM
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
mustache (0.99.5) mustache (0.99.5)
net-scp (1.1.2) net-scp (1.2.1)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (2.8.0) net-ssh (2.9.1)
nokogiri (1.6.2.1) nokogiri (1.6.2.1)
mini_portile (= 0.6.0) mini_portile (= 0.6.0)
oauth (0.4.7) oauth (0.4.7)
@ -303,7 +314,6 @@ GEM
rspec-core (~> 2.14.0) rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.14.0)
ruby-hmac (0.4.0)
ruby-openid (2.5.0) ruby-openid (2.5.0)
ruby-readability (0.6.1) ruby-readability (0.6.1)
guess_html_encoding (>= 0.0.4) guess_html_encoding (>= 0.0.4)
@ -410,7 +420,7 @@ DEPENDENCIES
fast_xs fast_xs
fastimage fastimage
flamegraph flamegraph
fog (= 1.18.0) fog (= 1.22.1)
foreman foreman
gctools gctools
handlebars-source (= 1.3.0) handlebars-source (= 1.3.0)

View File

@ -10,8 +10,10 @@ class Backup
end end
def self.all def self.all
backups = Dir.glob(File.join(Backup.base_directory, "*.tar.gz")) Dir.glob(File.join(Backup.base_directory, "*.tar.gz"))
backups.sort.reverse.map { |backup| Backup.create_from_filename(File.basename(backup)) } .sort_by { |file| File.mtime(file) }
.reverse
.map { |backup| Backup.create_from_filename(File.basename(backup)) }
end end
def self.[](filename) def self.[](filename)
@ -65,20 +67,27 @@ class Backup
def self.remove_old def self.remove_old
all_backups = Backup.all all_backups = Backup.all
return unless all_backups.size > SiteSetting.maximum_backups return unless all_backups.size > SiteSetting.maximum_backups
all_backups[SiteSetting.maximum_backups..-1].each {|b| b.remove} all_backups[SiteSetting.maximum_backups..-1].each(&:remove)
end end
private private
def s3_options
{
provider: 'AWS',
aws_access_key_id: SiteSetting.s3_access_key_id,
aws_secret_access_key: SiteSetting.s3_secret_access_key,
region: SiteSetting.s3_region.blank? ? "us-east-1" : SiteSetting.s3_region,
}
end
def fog def fog
return @fog if @fog return @fog if @fog
return unless SiteSetting.s3_access_key_id.present? && return unless SiteSetting.s3_access_key_id.present? &&
SiteSetting.s3_secret_access_key.present? && SiteSetting.s3_secret_access_key.present? &&
SiteSetting.s3_backup_bucket.present? SiteSetting.s3_backup_bucket.present?
require 'fog' require 'fog'
@fog = Fog::Storage.new(provider: 'AWS', @fog = Fog::Storage.new(s3_options)
aws_access_key_id: SiteSetting.s3_access_key_id,
aws_secret_access_key: SiteSetting.s3_secret_access_key)
end end
def fog_directory def fog_directory