backup 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b3395ec5399914784eeb39f638352a1ce486589
4
- data.tar.gz: 7e8dfbc5aea5da8abed31b2dbf14d920cfcebb41
3
+ metadata.gz: d08d993d32d7569046700f059019d19276be8d4f
4
+ data.tar.gz: a0f8b82c36a16137008774c5107c03f2cb560488
5
5
  SHA512:
6
- metadata.gz: 4e9ac7c7b0ad9ef5d7b4d5ac4147206c4407cceba3704aa15f53b0c99fadfe4c8703e07daa16dd874f0c3c80e836f89d1db56204de60e5c607080c4f96c498cc
7
- data.tar.gz: e64842958d8d39f15f739e76b554012389fbd7720710a0602cded468ae2c0829ed43039b0757bbec5d6f48a1e1b58db6aec625ad8954d956c44b8eec125f69ca
6
+ metadata.gz: 3bd3300ce800e95d11097dcf02c79965917d9aac7bb58a89e482248a6f3a37084efce66885cfd6b2f8892611b17dd2381df3fdb78c3e052da34e9eb8882b215e
7
+ data.tar.gz: dec002458b652dde7ea835c4366581252d1bd1961fca6e125c3677abedf72c03ca90313fa78ca0d8dfc2449575f3542cf399eb98bbdcd8873971f71d57a8fb6c
@@ -9,6 +9,11 @@ module Backup
9
9
  # The Hipchat API token
10
10
  attr_accessor :token
11
11
 
12
+ ##
13
+ # The Hipchat API version
14
+ # Either 'v1' or 'v2' (default is 'v1')
15
+ attr_accessor :api_version
16
+
12
17
  ##
13
18
  # Who the notification should appear from
14
19
  attr_accessor :from
@@ -45,6 +50,7 @@ module Backup
45
50
  @success_color ||= 'yellow'
46
51
  @warning_color ||= 'yellow'
47
52
  @failure_color ||= 'yellow'
53
+ @api_version ||= 'v1'
48
54
  end
49
55
 
50
56
  private
@@ -72,9 +78,13 @@ module Backup
72
78
  send_message(msg, status_data[:color])
73
79
  end
74
80
 
81
+ def client_options
82
+ { api_version: @api_version }
83
+ end
84
+
75
85
  # Hipchat::Client will raise an error if unsuccessful.
76
86
  def send_message(msg, color)
77
- client = HipChat::Client.new(token)
87
+ client = HipChat::Client.new(token, client_options)
78
88
  rooms_to_notify.each do |room|
79
89
  client[room].send(from, msg, :color => color, :notify => notify_users)
80
90
  end
@@ -37,6 +37,18 @@ module Backup
37
37
  # Receiver Email Address
38
38
  attr_accessor :to
39
39
 
40
+ ##
41
+ # CC receiver Email Address
42
+ attr_accessor :cc
43
+
44
+ ##
45
+ # BCC receiver Email Address
46
+ attr_accessor :bcc
47
+
48
+ ##
49
+ # Set reply to email address
50
+ attr_accessor :reply_to
51
+
40
52
  ##
41
53
  # SMTP Server Address
42
54
  attr_accessor :address
@@ -208,8 +220,11 @@ module Backup
208
220
  end
209
221
 
210
222
  email = ::Mail.new
211
- email.to = @to
212
- email.from = @from
223
+ email.to = to
224
+ email.from = from
225
+ email.cc = cc
226
+ email.bcc = bcc
227
+ email.reply_to = reply_to
213
228
  email
214
229
  end
215
230
 
@@ -47,5 +47,9 @@ module Backup
47
47
  "#{ trigger }.#{ extension }"
48
48
  end
49
49
 
50
+ def time_as_object
51
+ Time.strptime(time, '%Y.%m.%d.%H.%M.%S')
52
+ end
53
+
50
54
  end
51
55
  end
@@ -10,8 +10,18 @@ module Backup
10
10
  attr_accessor :path
11
11
 
12
12
  ##
13
- # Sets the limit to how many backups to keep in the remote location.
14
- # If exceeded, the oldest will be removed to make room for the newest
13
+ # Number of backups to keep or time until which to keep.
14
+ #
15
+ # If an Integer is given it sets the limit to how many backups to keep in
16
+ # the remote location. If exceeded, the oldest will be removed to make
17
+ # room for the newest.
18
+ #
19
+ # If a Time object is given it will remove backups _older_ than the given
20
+ # date.
21
+ #
22
+ # @!attribute [rw] keep
23
+ # @param [Integer|Time]
24
+ # @return [Integer|Time]
15
25
  attr_accessor :keep
16
26
 
17
27
  attr_reader :model, :package, :storage_id
@@ -33,7 +43,9 @@ module Backup
33
43
  def perform!
34
44
  Logger.info "#{ storage_name } Started..."
35
45
  transfer!
36
- cycle! if respond_to?(:cycle!, true) && keep.to_i > 0
46
+ if respond_to?(:cycle!, true) && (keep.to_i > 0 || keep.is_a?(Time))
47
+ cycle!
48
+ end
37
49
  Logger.info "#{ storage_name } Finished!"
38
50
  end
39
51
 
@@ -14,24 +14,34 @@ module Backup
14
14
  Logger.info 'Cycling Started...'
15
15
 
16
16
  packages = yaml_load.unshift(package)
17
- excess = packages.count - keep.to_i
17
+ cycled_packages = []
18
18
 
19
- if excess > 0
20
- packages.pop(excess).each do |pkg|
21
- begin
22
- remove!(pkg) unless pkg.no_cycle
23
- rescue => err
24
- Logger.warn Error.wrap(err, <<-EOS)
25
- There was a problem removing the following package:
26
- Trigger: #{pkg.trigger} :: Dated: #{pkg.time}
27
- Package included the following #{ pkg.filenames.count } file(s):
28
- #{ pkg.filenames.join("\n") }
29
- EOS
30
- end
19
+ if keep.is_a?(Date) || keep.is_a?(Time)
20
+ cycled_packages = packages.select do |p|
21
+ p.time_as_object < keep.to_time
31
22
  end
23
+ else
24
+ excess = packages.count - keep.to_i
25
+ cycled_packages = packages.last(excess) if excess > 0
32
26
  end
33
27
 
34
- yaml_save(packages)
28
+ saved_packages = packages - cycled_packages
29
+ cycled_packages.each { |package| delete_package package }
30
+
31
+ yaml_save(saved_packages)
32
+ end
33
+
34
+ def delete_package(package)
35
+ begin
36
+ remove!(package) unless package.no_cycle
37
+ rescue => err
38
+ Logger.warn Error.wrap(err, <<-EOS)
39
+ There was a problem removing the following package:
40
+ Trigger: #{package.trigger} :: Dated: #{package.time}
41
+ Package included the following #{ package.filenames.count } file(s):
42
+ #{ package.filenames.join("\n") }
43
+ EOS
44
+ end
35
45
  end
36
46
 
37
47
  # Returns path to the YAML data file.
@@ -15,15 +15,25 @@ module Backup
15
15
  attr_accessor :ip, :port
16
16
 
17
17
  ##
18
- # use passive mode?
18
+ # Use passive mode?
19
19
  attr_accessor :passive_mode
20
20
 
21
+ ##
22
+ # Configure connection open and read timeouts.
23
+ # Net::FTP's open_timeout and read_timeout will both be configured using
24
+ # this setting.
25
+ # @!attribute [rw] timeout
26
+ # @param [Integer|Float]
27
+ # @return [Integer|Float]
28
+ attr_accessor :timeout
29
+
21
30
  def initialize(model, storage_id = nil)
22
31
  super
23
32
 
24
33
  @port ||= 21
25
34
  @path ||= 'backups'
26
35
  @passive_mode ||= false
36
+ @timeout ||= nil
27
37
  path.sub!(/^~\//, '')
28
38
  end
29
39
 
@@ -42,6 +52,10 @@ module Backup
42
52
  end; Net::FTP.send(:const_set, :FTP_PORT, port)
43
53
 
44
54
  Net::FTP.open(ip, username, password) do |ftp|
55
+ if timeout
56
+ ftp.open_timeout = timeout
57
+ ftp.read_timeout = timeout
58
+ end
45
59
  ftp.passive = true if passive_mode
46
60
  yield ftp
47
61
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backup
4
- VERSION = '4.2.0'
4
+ VERSION = '4.2.2'
5
5
  end
@@ -12,4 +12,5 @@
12
12
  hipchat.success_color = "green"
13
13
  hipchat.warning_color = "yellow"
14
14
  hipchat.failure_color = "red"
15
+ hipchat.api_version = "v1"
15
16
  end
@@ -11,6 +11,9 @@
11
11
 
12
12
  mail.from = "sender@email.com"
13
13
  mail.to = "receiver@email.com"
14
+ mail.cc = "cc@email.com"
15
+ mail.bcc = "bcc@email.com"
16
+ mail.reply_to = "reply_to@email.com"
14
17
  mail.address = "smtp.gmail.com"
15
18
  mail.port = 587
16
19
  mail.domain = "your.host.name"
@@ -16,4 +16,5 @@
16
16
  db.access_type = :app_folder
17
17
  db.path = "/path/to/my/backups"
18
18
  db.keep = 25
19
+ # db.keep = Time.now - 2592000 # Remove all backups older than 1 month.
19
20
  end
@@ -8,5 +8,6 @@
8
8
  server.port = 21
9
9
  server.path = "~/backups/"
10
10
  server.keep = 5
11
+ # server.keep = Time.now - 2592000 # Remove all backups older than 1 month.
11
12
  server.passive_mode = false
12
13
  end
@@ -4,4 +4,5 @@
4
4
  store_with Local do |local|
5
5
  local.path = "~/backups/"
6
6
  local.keep = 5
7
+ # local.keep = Time.now - 2592000 # Remove all backups older than 1 month.
7
8
  end
@@ -6,4 +6,5 @@
6
6
  nf.storage_secret = "my_storage_secret"
7
7
  nf.path = "/path/to/my/backups"
8
8
  nf.keep = 10
9
+ # nf.keep = Time.now - 2592000 # Remove all backups older than 1 month.
9
10
  end
@@ -11,4 +11,6 @@
11
11
  s3.region = "us-east-1"
12
12
  s3.bucket = "bucket-name"
13
13
  s3.path = "path/to/backups"
14
+ s3.keep = 5
15
+ # s3.keep = Time.now - 2592000 # Remove all backups older than 1 month.
14
16
  end
@@ -8,6 +8,7 @@
8
8
  server.port = 22
9
9
  server.path = "~/backups/"
10
10
  server.keep = 5
11
+ # server.keep = Time.now - 2592000 # Remove all backups older than 1 month.
11
12
 
12
13
  # Additional options for the SSH connection.
13
14
  # server.ssh_options = {}
@@ -8,6 +8,7 @@
8
8
  server.port = 22
9
9
  server.path = "~/backups/"
10
10
  server.keep = 5
11
+ # server.keep = Time.now - 2592000 # Remove all backups older than 1 month.
11
12
 
12
13
  # Additional options for the SSH connection.
13
14
  # server.ssh_options = {}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: CFPropertyList