backup 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backup}
8
- s.version = "1.2.1"
8
+ s.version = "1.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["meskyanichi"]
@@ -12,11 +12,13 @@ end
12
12
  namespace :backup do
13
13
 
14
14
  task :s3_config => :environment do
15
- @config = generate_yaml('s3.yml')
15
+ @config = generate_yaml('s3.yml')
16
+ @adapters = ['mysql', 'sqlite3', 'assets', 'custom']
16
17
  end
17
18
 
18
19
  task :ssh_config => :environment do
19
20
  @config = generate_yaml('ssh.yml')
21
+ @adapters = ['mysql', 'sqlite3', 'assets', 'custom']
20
22
  end
21
23
 
22
24
  end
@@ -22,15 +22,15 @@ namespace :backup do
22
22
  desc 'Destroys S3 Backup database records; Physical files WILL be deleted as well.'
23
23
  task :s3 => :s3_config do
24
24
  puts "Removing all backups from S3.."
25
- ['mysql', 'sqlite3', 'assets', 'custom'].each do |adapter|
25
+ @adapters.each do |adapter|
26
26
  if @config[adapter]
27
27
  unless @config[adapter].is_a?(Array)
28
28
  puts "\n\n-- Processing #{adapter} backups.. --"
29
- Backup::BackupRecord::S3.destroy_all_backups(adapter, @config[adapter])
29
+ Backup::BackupRecord::S3.destroy_all_backups(adapter, @config[adapter], 0)
30
30
  else
31
31
  puts "\n\n-- Processing #{adapter} backups.. --"
32
- @config[adapter].each do |config|
33
- Backup::BackupRecord::S3.destroy_all_backups(adapter, config)
32
+ @config[adapter].each_with_index do |config, index|
33
+ Backup::BackupRecord::S3.destroy_all_backups(adapter, config, index)
34
34
  end
35
35
  end
36
36
  end
@@ -41,15 +41,15 @@ namespace :backup do
41
41
  desc 'Destroys SSH Backup database records; Physical files WILL be deleted as well.'
42
42
  task :ssh => :ssh_config do
43
43
  puts "Removing all backups from remote server through SSH.."
44
- ['mysql', 'sqlite3', 'assets', 'custom'].each do |adapter|
44
+ @adapters.each do |adapter|
45
45
  if @config[adapter]
46
46
  unless @config[adapter].is_a?(Array)
47
47
  puts "\n\n-- Processing #{adapter} backups.. --"
48
- Backup::BackupRecord::SSH.destroy_all_backups(adapter, @config[adapter])
48
+ Backup::BackupRecord::SSH.destroy_all_backups(adapter, @config[adapter], 0)
49
49
  else
50
50
  puts "\n\n-- Processing #{adapter} backups.. --"
51
- @config[adapter].each do |config|
52
- Backup::BackupRecord::SSH.destroy_all_backups(adapter, config)
51
+ @config[adapter].each_with_index do |config, index|
52
+ Backup::BackupRecord::SSH.destroy_all_backups(adapter, config, index)
53
53
  end
54
54
  end
55
55
  end
@@ -14,6 +14,7 @@ namespace :backup do
14
14
  unless @config.is_a?(Array)
15
15
  Backup::Adapter::Mysql.new({
16
16
  :adapter => 'mysql',
17
+ :index => 0,
17
18
  :mysql => {
18
19
  :user => @config['mysql_config']['user'],
19
20
  :password => @config['mysql_config']['password'],
@@ -31,9 +32,10 @@ namespace :backup do
31
32
  }
32
33
  }).run
33
34
  else
34
- @config.each do |config|
35
+ @config.each_with_index do |config, index|
35
36
  Backup::Adapter::Mysql.new({
36
37
  :adapter => 'mysql',
38
+ :index => index,
37
39
  :mysql => {
38
40
  :user => config['mysql_config']['user'],
39
41
  :password => config['mysql_config']['password'],
@@ -68,6 +70,7 @@ namespace :backup do
68
70
  unless @config.is_a?(Array)
69
71
  Backup::Adapter::Sqlite3.new({
70
72
  :adapter => 'sqlite3',
73
+ :index => 0,
71
74
  :file => @config['file'],
72
75
  :path => @config['path'],
73
76
  :encrypt => @config['encrypt'],
@@ -81,9 +84,10 @@ namespace :backup do
81
84
  }
82
85
  }).run
83
86
  else
84
- @config.each do |config|
87
+ @config.each_with_index do |config, index|
85
88
  Backup::Adapter::Sqlite3.new({
86
89
  :adapter => 'sqlite3',
90
+ :index => index,
87
91
  :file => config['file'],
88
92
  :path => config['path'],
89
93
  :encrypt => config['encrypt'],
@@ -114,6 +118,7 @@ namespace :backup do
114
118
  unless @config.is_a?(Array)
115
119
  Backup::Adapter::Assets.new({
116
120
  :adapter => 'assets',
121
+ :index => 0,
117
122
  :path => @config['path'],
118
123
  :encrypt => @config['encrypt'],
119
124
  :keep_backups => @config['keep_backups'],
@@ -126,9 +131,10 @@ namespace :backup do
126
131
  }
127
132
  }).run
128
133
  else
129
- @config.each do |config|
134
+ @config.each_with_index do |config, index|
130
135
  Backup::Adapter::Assets.new({
131
136
  :adapter => 'assets',
137
+ :index => index,
132
138
  :path => config['path'],
133
139
  :encrypt => config['encrypt'],
134
140
  :keep_backups => config['keep_backups'],
@@ -185,6 +191,7 @@ namespace :backup do
185
191
  unless @config.is_a?(Array)
186
192
  Backup::Adapter::Custom.new({
187
193
  :adapter => 'custom',
194
+ :index => 0,
188
195
  :file => @config['file'],
189
196
  :path => @config['path'],
190
197
  :command => @config['command'],
@@ -199,9 +206,10 @@ namespace :backup do
199
206
  }
200
207
  }).run
201
208
  else
202
- @config.each do |config|
209
+ @config.each_with_index do |config, index|
203
210
  Backup::Adapter::Custom.new({
204
211
  :adapter => 'custom',
212
+ :index => index,
205
213
  :file => config['file'],
206
214
  :path => config['path'],
207
215
  :command => config['command'],
@@ -11,7 +11,8 @@ namespace :backup do
11
11
  @config = @config['mysql']
12
12
  unless @config.is_a?(Array)
13
13
  Backup::Adapter::Mysql.new({
14
- :adapter => 'mysql',
14
+ :adapter => 'mysql',
15
+ :index => 0,
15
16
  :mysql => {
16
17
  :user => @config['mysql_config']['user'],
17
18
  :password => @config['mysql_config']['password'],
@@ -29,9 +30,10 @@ namespace :backup do
29
30
  }
30
31
  }).run
31
32
  else
32
- @config.each do |config|
33
+ @config.each_with_index do |config, index|
33
34
  Backup::Adapter::Mysql.new({
34
35
  :adapter => 'mysql',
36
+ :index => index,
35
37
  :mysql => {
36
38
  :user => config['mysql_config']['user'],
37
39
  :password => config['mysql_config']['password'],
@@ -65,6 +67,7 @@ namespace :backup do
65
67
  unless @config.is_a?(Array)
66
68
  Backup::Adapter::Sqlite3.new({
67
69
  :adapter => 'sqlite3',
70
+ :index => 0,
68
71
  :file => @config['file'],
69
72
  :path => @config['path'],
70
73
  :encrypt => @config['encrypt'],
@@ -78,9 +81,10 @@ namespace :backup do
78
81
  }
79
82
  }).run
80
83
  else
81
- @config.each do |config|
84
+ @config.each_with_index do |config, index|
82
85
  Backup::Adapter::Sqlite3.new({
83
86
  :adapter => 'sqlite3',
87
+ :index => index,
84
88
  :file => config['file'],
85
89
  :path => config['path'],
86
90
  :encrypt => config['encrypt'],
@@ -109,6 +113,7 @@ namespace :backup do
109
113
  unless @config.is_a?(Array)
110
114
  Backup::Adapter::Assets.new({
111
115
  :adapter => 'assets',
116
+ :index => 0,
112
117
  :path => @config['path'],
113
118
  :encrypt => @config['encrypt'],
114
119
  :keep_backups => @config['keep_backups'],
@@ -121,9 +126,10 @@ namespace :backup do
121
126
  }
122
127
  }).run
123
128
  else
124
- @config.each do |config|
129
+ @config.each_with_index do |config, index|
125
130
  Backup::Adapter::Assets.new({
126
131
  :adapter => 'assets',
132
+ :index => index,
127
133
  :path => config['path'],
128
134
  :encrypt => config['encrypt'],
129
135
  :keep_backups => config['keep_backups'],
@@ -180,6 +186,7 @@ namespace :backup do
180
186
  unless @config.is_a?(Array)
181
187
  Backup::Adapter::Custom.new({
182
188
  :adapter => 'custom',
189
+ :index => 0,
183
190
  :file => @config['file'],
184
191
  :path => @config['path'],
185
192
  :command => @config['command'],
@@ -194,9 +201,10 @@ namespace :backup do
194
201
  }
195
202
  }).run
196
203
  else
197
- @config.each do |config|
204
+ @config.each_with_index do |config, index|
198
205
  Backup::Adapter::Custom.new({
199
206
  :adapter => 'custom',
207
+ :index => index,
200
208
  :file => config['file'],
201
209
  :path => config['path'],
202
210
  :command => config['command'],
@@ -30,12 +30,13 @@ module Backup
30
30
  self.bucket = options[:s3][:bucket]
31
31
  self.keep_backups = options[:keep_backups]
32
32
  self.adapter = options[:adapter]
33
+ self.index = options[:index]
33
34
  end
34
35
 
35
- def self.destroy_all_backups(adapter, options)
36
+ def self.destroy_all_backups(adapter, options, index)
36
37
  s3 = Backup::Connection::S3.new(options)
37
38
  s3.connect
38
- backups = Backup::BackupRecord::S3.all(:conditions => {:adapter => adapter})
39
+ backups = Backup::BackupRecord::S3.all(:conditions => {:adapter => adapter, :index => index})
39
40
  backups.each do |backup|
40
41
  puts "Destroying backup: #{backup.backup_file}.."
41
42
  s3.destroy(backup.backup_file, backup.bucket)
@@ -50,7 +51,7 @@ module Backup
50
51
  # First all backups will be fetched.
51
52
  def destroy_old_backups
52
53
  if keep_backups.is_a?(Integer)
53
- backups = Backup::BackupRecord::S3.all(:conditions => {:adapter => adapter})
54
+ backups = Backup::BackupRecord::S3.all(:conditions => {:adapter => adapter, :index => index})
54
55
  backups_to_destroy = Array.new
55
56
  backups.each_with_index do |backup, index|
56
57
  if index >= keep_backups then
@@ -30,12 +30,13 @@ module Backup
30
30
  self.backup_path = options[:ssh][:path]
31
31
  self.keep_backups = options[:keep_backups]
32
32
  self.adapter = options[:adapter]
33
+ self.index = options[:index]
33
34
  self.ip = options[:ssh][:ip]
34
35
  self.user = options[:ssh][:user]
35
36
  end
36
37
 
37
- def self.destroy_all_backups(adapter, options)
38
- backups = Backup::BackupRecord::SSH.all(:conditions => {:adapter => adapter})
38
+ def self.destroy_all_backups(adapter, options, index)
39
+ backups = Backup::BackupRecord::SSH.all(:conditions => {:adapter => adapter, :index => index})
39
40
  Net::SSH.start(options['ssh']['ip'], options['ssh']['user']) do |ssh|
40
41
  # Loop through all backups that should be destroyed and remove them from remote server.
41
42
  backups.each do |backup|
@@ -53,7 +54,7 @@ module Backup
53
54
  # First all backups will be fetched.
54
55
  def destroy_old_backups
55
56
  if keep_backups.is_a?(Integer)
56
- backups = Backup::BackupRecord::SSH.all(:conditions => {:adapter => adapter})
57
+ backups = Backup::BackupRecord::SSH.all(:conditions => {:adapter => adapter, :index => index})
57
58
  backups_to_destroy = Array.new
58
59
  backups.each_with_index do |backup, index|
59
60
  if index >= keep_backups then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meskyanichi