backupgemsteven 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +48 -0
- data/Rakefile +26 -0
- data/TODO +7 -0
- data/bin/backup +12 -0
- data/bin/commands.sh +2 -0
- data/doc/LICENSE-GPL.txt +280 -0
- data/doc/index.html +716 -0
- data/doc/styles.css +157 -0
- data/examples/global.rb +28 -0
- data/examples/mediawiki.rb +24 -0
- data/examples/mediawiki_numeric.rb +19 -0
- data/examples/s3.rb +35 -0
- data/lib/backup.rb +23 -0
- data/lib/backup/actor.rb +208 -0
- data/lib/backup/cli.rb +144 -0
- data/lib/backup/configuration.rb +137 -0
- data/lib/backup/date_parser.rb +37 -0
- data/lib/backup/extensions.rb +17 -0
- data/lib/backup/recipes/standard.rb +113 -0
- data/lib/backup/rotator.rb +219 -0
- data/lib/backup/s3_helpers.rb +140 -0
- data/lib/backup/ssh_helpers.rb +135 -0
- data/lib/backup/state_recorder.rb +21 -0
- data/tests/actor_test.rb +69 -0
- data/tests/cleanup.sh +2 -0
- data/tests/optional/s3_test.rb +40 -0
- data/tests/rotation_test.rb +31 -0
- data/tests/s3_test.rb +40 -0
- data/tests/ssh_test.rb +21 -0
- data/tests/tests_helper.rb +5 -0
- metadata +165 -0
@@ -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
|
data/tests/actor_test.rb
ADDED
@@ -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
|
+
|
data/tests/cleanup.sh
ADDED
@@ -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
|
data/tests/s3_test.rb
ADDED
@@ -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
|
data/tests/ssh_test.rb
ADDED
@@ -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
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backupgemsteven
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nate Murray
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-01-27 00:00:00 +01: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
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 7
|
33
|
+
- 1
|
34
|
+
version: 0.7.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: runt
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 19
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 3
|
49
|
+
- 0
|
50
|
+
version: 0.3.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: net-ssh
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 15
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 0
|
65
|
+
- 0
|
66
|
+
version: 2.0.0
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: madeleine
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 5
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 7
|
81
|
+
- 3
|
82
|
+
version: 0.7.3
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
description:
|
86
|
+
email: nate@natemurray.com
|
87
|
+
executables:
|
88
|
+
- backup
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files:
|
92
|
+
- CHANGELOG
|
93
|
+
- Rakefile
|
94
|
+
- TODO
|
95
|
+
files:
|
96
|
+
- bin/backup
|
97
|
+
- bin/commands.sh
|
98
|
+
- doc/LICENSE-GPL.txt
|
99
|
+
- doc/index.html
|
100
|
+
- doc/styles.css
|
101
|
+
- examples/global.rb
|
102
|
+
- examples/mediawiki.rb
|
103
|
+
- examples/mediawiki_numeric.rb
|
104
|
+
- examples/s3.rb
|
105
|
+
- lib/backup.rb
|
106
|
+
- lib/backup/actor.rb
|
107
|
+
- lib/backup/cli.rb
|
108
|
+
- lib/backup/configuration.rb
|
109
|
+
- lib/backup/date_parser.rb
|
110
|
+
- lib/backup/extensions.rb
|
111
|
+
- lib/backup/recipes/standard.rb
|
112
|
+
- lib/backup/rotator.rb
|
113
|
+
- lib/backup/s3_helpers.rb
|
114
|
+
- lib/backup/ssh_helpers.rb
|
115
|
+
- lib/backup/state_recorder.rb
|
116
|
+
- tests/actor_test.rb
|
117
|
+
- tests/cleanup.sh
|
118
|
+
- tests/optional/s3_test.rb
|
119
|
+
- tests/rotation_test.rb
|
120
|
+
- tests/s3_test.rb
|
121
|
+
- tests/ssh_test.rb
|
122
|
+
- tests/tests_helper.rb
|
123
|
+
- CHANGELOG
|
124
|
+
- Rakefile
|
125
|
+
- TODO
|
126
|
+
has_rdoc: true
|
127
|
+
homepage: http://tech.natemurray.com/backup
|
128
|
+
licenses: []
|
129
|
+
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options:
|
132
|
+
- --charset=UTF-8
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
requirements: []
|
154
|
+
|
155
|
+
rubyforge_project: backupgem
|
156
|
+
rubygems_version: 1.3.7
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Beginning-to-end solution for backups and rotation.
|
160
|
+
test_files:
|
161
|
+
- tests/actor_test.rb
|
162
|
+
- tests/optional/s3_test.rb
|
163
|
+
- tests/rotation_test.rb
|
164
|
+
- tests/s3_test.rb
|
165
|
+
- tests/ssh_test.rb
|