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 'fastimage'
gem 'fog', '1.18.0', require: false
gem 'fog', '1.22.1', require: false
gem 'unf', require: false
# see: https://twitter.com/samsaffron/status/412360162297393152

View File

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

View File

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