notch8-backupgem 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+
3
+ class StateRecorder
4
+ attr_accessor :sons_since_last_promotion
5
+ attr_accessor :fathers_since_last_promotion
6
+ attr_accessor :saved_state_folder
7
+
8
+ def initialize
9
+ @sons_since_last_promotion = 0
10
+ @fathers_since_last_promotion = 0
11
+ end
12
+
13
+ # cleanup all the snapshots created by madeline
14
+ def cleanup_snapshots
15
+ files = Dir[saved_state_folder + "/*.snapshot"]
16
+ files.pop
17
+ files.sort.each do |f|
18
+ FileUtils.rm(f, :verbose => false)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + "/tests_helper"
2
+
3
+ class ActorTest < Test::Unit::TestCase
4
+ def setup
5
+ @config = Backup::Configuration.new
6
+ @config.load "standard"
7
+ @actor = @config.actor
8
+ setup_tmp_backup_dir
9
+ end
10
+
11
+ def dont_test_exists
12
+ assert @actor
13
+ end
14
+
15
+ def dont_test_is_file
16
+ dir = create_tmp_files
17
+ config = <<-END
18
+ action :content, :is_file => "#{dir}/1"
19
+ END
20
+ @config.load :string => config
21
+ assert result = @actor.content
22
+ assert File.exists?(result)
23
+ puts "content result is: #{result}"
24
+ @actor.start_process!
25
+ end
26
+
27
+ def dont_test_is_folder
28
+ dir = create_tmp_files
29
+ config = <<-END
30
+ action :content, :is_folder => "#{dir}"
31
+ END
32
+ @config.load :string => config
33
+ assert result = @actor.content
34
+ assert File.exists?(result)
35
+ assert File.directory?(result)
36
+ puts "content result is: #{result}"
37
+ @actor.start_process!
38
+ end
39
+
40
+ def test_is_contents_of
41
+ dir = create_tmp_files
42
+ config = <<-END
43
+ action :content, :is_contents_of => "#{dir}", :copy => true
44
+ END
45
+ @config.load :string => config
46
+ #@actor.content
47
+ #@actor.cleanup
48
+ @actor.start_process!
49
+ end
50
+
51
+ private
52
+ def setup_tmp_backup_dir
53
+ newtmp = @config[:tmp_dir] + "/backup_#{rand}_" + Time.now.strftime("%Y%m%d%H%M%S")
54
+ sh "mkdir #{newtmp}"
55
+ config = <<-END
56
+ set :backup_path, "#{newtmp}"
57
+ END
58
+ @config.load :string => config
59
+ end
60
+
61
+ def create_tmp_files
62
+ newtmp = @config[:tmp_dir] + "/test_#{rand}_" + Time.now.strftime("%Y%m%d%H%M%S")
63
+ sh "mkdir #{newtmp}"
64
+ 0.upto(5) { |i| sh "touch #{newtmp}/#{i}" }
65
+ newtmp
66
+ end
67
+
68
+ end
69
+
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/bash
2
+ LOOK_IN="/var/local/backups/mediawiki/sons"; COUNT=`ls -1 $LOOK_IN | wc -l`; MAX=14; if (( $COUNT > $MAX )); then let "OFFSET=$COUNT-$MAX"; i=1; for f in `ls -1 $LOOK_IN | sort`; do if (( $i <= $OFFSET )); then CMD="rm $LOOK_IN/$f"; echo $CMD; $CMD; fi; echo "$i $f"; let "i=$i + 1"; done; else true; fi
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + "/tests_helper"
2
+
3
+ class S3Test < Test::Unit::TestCase
4
+
5
+ # These tests require actual S3 access keys set as environment variables
6
+
7
+ def setup
8
+ @config = Backup::Configuration.new
9
+ @config.load "standard"
10
+ @config.set :backup_path, 'test_backup'
11
+ @config.action :deliver, :method => :s3
12
+ @actor = Backup::S3Actor.new(@config)
13
+ end
14
+
15
+ def test_exists
16
+ assert @config
17
+ assert @actor
18
+ end
19
+
20
+ def test_on_s3
21
+ dir = create_tmp_files
22
+ config = <<-END
23
+ action :content, :is_folder => "#{dir}"
24
+ action :rotate, :method => :via_s3
25
+ END
26
+ @config.load :string => config
27
+ assert result = @config.actor.content
28
+ assert File.exists?(result)
29
+ @config.actor.start_process!
30
+ end
31
+
32
+ private
33
+
34
+ def create_tmp_files
35
+ newtmp = @config[:tmp_dir] + "/test_#{rand}_" + Time.now.strftime("%Y%m%d%H%M%S")
36
+ sh "mkdir #{newtmp}"
37
+ 0.upto(5) { |i| sh "touch #{newtmp}/#{i}" }
38
+ newtmp
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + "/tests_helper"
2
+ require 'runt'
3
+ require 'date'
4
+
5
+ class RotationTest < Test::Unit::TestCase
6
+ def setup
7
+ # setup our config to test the objects
8
+ @config = Backup::Configuration.new
9
+ @config.load "standard"
10
+ @rotator = Backup::Rotator.new(@config.actor)
11
+ end
12
+
13
+ def test_rotator
14
+ t = Date.today
15
+ r = @rotator
16
+ 0.upto(14) do |i|
17
+ $test_time = t
18
+ print t.to_s + t.strftime(" #{i} %a ").to_s
19
+ puts r.todays_generation
20
+ t += 1
21
+ end
22
+ end
23
+
24
+ def test_date_parsing
25
+ dp = Backup::DateParser.new
26
+ assert fri = dp.date_from(:fri)
27
+ assert daily = dp.date_from(:daily)
28
+ assert last = dp.date_from(:last_mon_of_the_month)
29
+ assert_raise(RuntimeError) { dp.date_from(:asdfasdf) }
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + "/tests_helper"
2
+
3
+ class S3Test < Test::Unit::TestCase
4
+
5
+ # These tests require actual S3 access keys set as environment variables
6
+
7
+ def setup
8
+ @config = Backup::Configuration.new
9
+ @config.load "standard"
10
+ @config.set :backup_path, 'test_backup'
11
+ @config.action :deliver, :method => :s3
12
+ @actor = Backup::S3Actor.new(@config)
13
+ end
14
+
15
+ def test_exists
16
+ assert @config
17
+ assert @actor
18
+ end
19
+
20
+ def test_on_s3
21
+ dir = create_tmp_files
22
+ config = <<-END
23
+ action :content, :is_folder => "#{dir}"
24
+ action :rotate, :method => :via_s3
25
+ END
26
+ @config.load :string => config
27
+ assert result = @config.actor.content
28
+ assert File.exists?(result)
29
+ @config.actor.start_process!
30
+ end
31
+
32
+ private
33
+
34
+ def create_tmp_files
35
+ newtmp = @config[:tmp_dir] + "/test_#{rand}_" + Time.now.strftime("%Y%m%d%H%M%S")
36
+ sh "mkdir #{newtmp}"
37
+ 0.upto(5) { |i| sh "touch #{newtmp}/#{i}" }
38
+ newtmp
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/tests_helper"
2
+
3
+ class SSHTest < Test::Unit::TestCase
4
+ def setup
5
+ @config = Backup::Configuration.new
6
+ @config.load "standard"
7
+ @config.action :deliver, :method => :ssh
8
+ @actor = Backup::SshActor.new(@config)
9
+ end
10
+
11
+ def test_exists
12
+ assert @config
13
+ assert @actor
14
+ end
15
+
16
+ def test_on_remote
17
+ @actor.on_remote do
18
+ run "echo \"hello $HOSTNAME\""
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift File.dirname(__FILE__) + "/../lib"
2
+
3
+ require 'test/unit'
4
+ require 'backup'
5
+ require 'backup/extensions'
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notch8-backupgem
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
10
+ platform: ruby
11
+ authors:
12
+ - Nate Murray
13
+ - Rob Kaufman(fork)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-06 00:00:00 -08:00
19
+ default_executable: backup
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 7
31
+ - 1
32
+ version: 0.7.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: runt
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 3
45
+ - 0
46
+ version: 0.3.0
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: net-ssh
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 2
58
+ - 0
59
+ - 0
60
+ version: 2.0.0
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: madeleine
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ - 7
73
+ - 3
74
+ version: 0.7.3
75
+ type: :runtime
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: right_aws
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 3
86
+ - 0
87
+ - 0
88
+ version: 3.0.0
89
+ type: :runtime
90
+ version_requirements: *id005
91
+ description:
92
+ email: nate@natemurray.com
93
+ executables:
94
+ - backup
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - CHANGELOG
99
+ - Rakefile
100
+ - TODO
101
+ files:
102
+ - bin/backup
103
+ - bin/commands.sh
104
+ - doc/LICENSE-GPL.txt
105
+ - doc/index.html
106
+ - doc/styles.css
107
+ - examples/global.rb
108
+ - examples/mediawiki.rb
109
+ - examples/mediawiki_numeric.rb
110
+ - examples/s3.rb
111
+ - lib/backup.rb
112
+ - lib/backup/actor.rb
113
+ - lib/backup/cli.rb
114
+ - lib/backup/configuration.rb
115
+ - lib/backup/date_parser.rb
116
+ - lib/backup/extensions.rb
117
+ - lib/backup/recipes/standard.rb
118
+ - lib/backup/rotator.rb
119
+ - lib/backup/s3_helpers.rb
120
+ - lib/backup/ssh_helpers.rb
121
+ - lib/backup/state_recorder.rb
122
+ - tests/actor_test.rb
123
+ - tests/cleanup.sh
124
+ - tests/optional/s3_test.rb
125
+ - tests/rotation_test.rb
126
+ - tests/s3_test.rb
127
+ - tests/ssh_test.rb
128
+ - tests/tests_helper.rb
129
+ - CHANGELOG
130
+ - Rakefile
131
+ - TODO
132
+ has_rdoc: true
133
+ homepage: http://tech.natemurray.com/backup
134
+ licenses: []
135
+
136
+ post_install_message:
137
+ rdoc_options:
138
+ - --charset=UTF-8
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project: backupgem
158
+ rubygems_version: 1.3.6
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Beginning-to-end solution for backups and rotation.
162
+ test_files:
163
+ - tests/actor_test.rb
164
+ - tests/optional/s3_test.rb
165
+ - tests/rotation_test.rb
166
+ - tests/s3_test.rb
167
+ - tests/ssh_test.rb