backup 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -85,6 +85,11 @@ http://wiki.github.com/meskyanichi/backup/requirements
85
85
  http://wiki.github.com/meskyanichi/backup/automatic-backups
86
86
 
87
87
 
88
+ === Capistrano Recipes
89
+
90
+ http://wiki.github.com/meskyanichi/backup/capistrano-recipes
91
+
92
+
88
93
  === Resources
89
94
 
90
95
  http://wiki.github.com/meskyanichi/backup/resources
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
data/backup.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backup}
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
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
- s.date = %q{2009-10-08}
12
+ s.date = %q{2009-10-09}
13
13
  s.description = %q{
14
14
  “Backup” is a RubyGem, written for Ruby on Rails. It's main purpose is to Backup any
15
15
  files to Amazon S3 or any remotely accessible server through SSH (SCP). It supports database
@@ -1,13 +1,6 @@
1
1
  namespace :backup do
2
2
  namespace :db do
3
3
  namespace :truncate do
4
-
5
- desc 'Truncates all the Backup database records; Physical files WILL NOT be deleted.'
6
- task :all => :environment do
7
- puts "Truncating All!"
8
- Backup::BackupRecord::S3.destroy_all
9
- Backup::BackupRecord::SSH.destroy_all
10
- end
11
4
 
12
5
  desc 'Truncates the S3 Backup database records; Physical files WILL NOT be deleted from S3.'
13
6
  task :s3 => :environment do
@@ -23,27 +16,47 @@ namespace :backup do
23
16
 
24
17
  end
25
18
 
26
- =begin
19
+
27
20
  namespace :destroy do
28
21
 
29
- desc 'Destroys all Backup database records; Physical files WILL be deleted as well.'
30
- task :all => :environment do
31
- Backup::BackupRecord::S3.destroy_all_backups
32
- Backup::BackupRecord::SSH.destroy_all_backups
33
- end
34
-
35
22
  desc 'Destroys S3 Backup database records; Physical files WILL be deleted as well.'
36
23
  task :s3 => :s3_config do
37
- Backup::BackupRecord::S3.destroy_all_backups
24
+ puts "Removing all backups from S3.."
25
+ ['mysql', 'sqlite3', 'assets', 'custom'].each do |adapter|
26
+ if @config[adapter]
27
+ unless @config[adapter].is_a?(Array)
28
+ puts "\n\n-- Processing #{adapter} backups.. --"
29
+ Backup::BackupRecord::S3.destroy_all_backups(adapter, @config[adapter])
30
+ else
31
+ puts "\n\n-- Processing #{adapter} backups.. --"
32
+ @config[adapter].each do |config|
33
+ Backup::BackupRecord::S3.destroy_all_backups(adapter, config)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ puts "\n\nAll S3 backups destroyed!"
38
39
  end
39
40
 
40
41
  desc 'Destroys SSH Backup database records; Physical files WILL be deleted as well.'
41
42
  task :ssh => :ssh_config do
42
- Backup::BackupRecord::SSH.destroy_all_backups
43
+ puts "Removing all backups from remote server through SSH.."
44
+ ['mysql', 'sqlite3', 'assets', 'custom'].each do |adapter|
45
+ if @config[adapter]
46
+ unless @config[adapter].is_a?(Array)
47
+ puts "\n\n-- Processing #{adapter} backups.. --"
48
+ Backup::BackupRecord::SSH.destroy_all_backups(adapter, @config[adapter])
49
+ else
50
+ puts "\n\n-- Processing #{adapter} backups.. --"
51
+ @config[adapter].each do |config|
52
+ Backup::BackupRecord::SSH.destroy_all_backups(adapter, config)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ puts "All backups from remote server destroyed!"
43
58
  end
44
59
 
45
60
  end
46
- =end
47
-
48
61
  end
49
62
  end
@@ -32,16 +32,15 @@ module Backup
32
32
  self.adapter = options[:adapter]
33
33
  end
34
34
 
35
- def self.destroy_all_backups(options)
35
+ def self.destroy_all_backups(adapter, options)
36
36
  s3 = Backup::Connection::S3.new(options)
37
37
  s3.connect
38
- backups = Backup::BackupRecord::S3.all
38
+ backups = Backup::BackupRecord::S3.all(:conditions => {:adapter => adapter})
39
39
  backups.each do |backup|
40
40
  puts "Destroying backup: #{backup.backup_file}.."
41
41
  s3.destroy(backup.backup_file, backup.bucket)
42
42
  backup.destroy
43
43
  end
44
- puts "All S3 Backups Destroyed!"
45
44
  end
46
45
 
47
46
  private
@@ -34,6 +34,18 @@ module Backup
34
34
  self.user = options[:ssh][:user]
35
35
  end
36
36
 
37
+ def self.destroy_all_backups(adapter, options)
38
+ backups = Backup::BackupRecord::SSH.all(:conditions => {:adapter => adapter})
39
+ Net::SSH.start(options['ssh']['ip'], options['ssh']['user']) do |ssh|
40
+ # Loop through all backups that should be destroyed and remove them from remote server.
41
+ backups.each do |backup|
42
+ puts "Destroying old backup: #{backup.backup_file}.."
43
+ ssh.exec("rm #{File.join(backup.backup_path, backup.backup_file)}")
44
+ backup.destroy
45
+ end
46
+ end
47
+ end
48
+
37
49
  private
38
50
 
39
51
  # Destroys backups when the backup limit has been reached
@@ -52,7 +64,7 @@ module Backup
52
64
  if backups_to_destroy
53
65
  # Establish a connection with the remote server through SSH
54
66
  Net::SSH.start(ip, user) do |ssh|
55
- # Loop through all backups that should be destroyed and remove them from S3.
67
+ # Loop through all backups that should be destroyed and remove them from remote server.
56
68
  backups_to_destroy.each do |backup|
57
69
  puts "Destroying old backup: #{backup.backup_file}.."
58
70
  ssh.exec("rm #{File.join(backup.backup_path, backup.backup_file)}")
@@ -3,6 +3,8 @@ module Backup
3
3
  class S3 < Backup::Connection::Base
4
4
 
5
5
  def initialize(options = {})
6
+ options.symbolize_keys!
7
+ options[:s3].symbolize_keys!
6
8
  super(options)
7
9
  end
8
10
 
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.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - meskyanichi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-08 00:00:00 +02:00
12
+ date: 2009-10-09 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency