ambethia-backup 0.0.11
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.
- 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 +24 -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 +97 -0
- data/lib/backup/ssh_helpers.rb +139 -0
- data/lib/backup/state_recorder.rb +21 -0
- data/tests/actor_test.rb +70 -0
- data/tests/cleanup.sh +2 -0
- data/tests/optional/s3_test.rb +40 -0
- data/tests/rotation_test.rb +32 -0
- data/tests/s3_test.rb +40 -0
- data/tests/ssh_test.rb +21 -0
- data/tests/tests_helper.rb +5 -0
- metadata +128 -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,70 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require File.dirname(__FILE__) + "/tests_helper"
|
3
|
+
|
4
|
+
class ActorTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@config = Backup::Configuration.new
|
7
|
+
@config.load "standard"
|
8
|
+
@actor = @config.actor
|
9
|
+
setup_tmp_backup_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
def dont_test_exists
|
13
|
+
assert @actor
|
14
|
+
end
|
15
|
+
|
16
|
+
def dont_test_is_file
|
17
|
+
dir = create_tmp_files
|
18
|
+
config = <<-END
|
19
|
+
action :content, :is_file => "#{dir}/1"
|
20
|
+
END
|
21
|
+
@config.load :string => config
|
22
|
+
assert result = @actor.content
|
23
|
+
assert File.exists?(result)
|
24
|
+
puts "content result is: #{result}"
|
25
|
+
@actor.start_process!
|
26
|
+
end
|
27
|
+
|
28
|
+
def dont_test_is_folder
|
29
|
+
dir = create_tmp_files
|
30
|
+
config = <<-END
|
31
|
+
action :content, :is_folder => "#{dir}"
|
32
|
+
END
|
33
|
+
@config.load :string => config
|
34
|
+
assert result = @actor.content
|
35
|
+
assert File.exists?(result)
|
36
|
+
assert File.directory?(result)
|
37
|
+
puts "content result is: #{result}"
|
38
|
+
@actor.start_process!
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_is_contents_of
|
42
|
+
dir = create_tmp_files
|
43
|
+
config = <<-END
|
44
|
+
action :content, :is_contents_of => "#{dir}", :copy => true
|
45
|
+
END
|
46
|
+
@config.load :string => config
|
47
|
+
#@actor.content
|
48
|
+
#@actor.cleanup
|
49
|
+
@actor.start_process!
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def setup_tmp_backup_dir
|
54
|
+
newtmp = @config[:tmp_dir] + "/backup_#{rand}_" + Time.now.strftime("%Y%m%d%H%M%S")
|
55
|
+
sh "mkdir #{newtmp}"
|
56
|
+
config = <<-END
|
57
|
+
set :backup_path, "#{newtmp}"
|
58
|
+
END
|
59
|
+
@config.load :string => config
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_tmp_files
|
63
|
+
newtmp = @config[:tmp_dir] + "/test_#{rand}_" + Time.now.strftime("%Y%m%d%H%M%S")
|
64
|
+
sh "mkdir #{newtmp}"
|
65
|
+
0.upto(5) { |i| sh "touch #{newtmp}/#{i}" }
|
66
|
+
newtmp
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
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,32 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require File.dirname(__FILE__) + "/tests_helper"
|
3
|
+
require 'runt'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
class RotationTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
# setup our config to test the objects
|
9
|
+
@config = Backup::Configuration.new
|
10
|
+
@config.load "standard"
|
11
|
+
@rotator = Backup::Rotator.new(@config.actor)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_rotator
|
15
|
+
t = Date.today
|
16
|
+
r = @rotator
|
17
|
+
0.upto(14) do |i|
|
18
|
+
$test_time = t
|
19
|
+
print t.to_s + t.strftime(" #{i} %a ").to_s
|
20
|
+
puts r.todays_generation
|
21
|
+
t += 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_date_parsing
|
26
|
+
dp = Backup::DateParser.new
|
27
|
+
assert fri = dp.date_from(:fri)
|
28
|
+
assert daily = dp.date_from(:daily)
|
29
|
+
assert last = dp.date_from(:last_mon_of_the_month)
|
30
|
+
assert_raise(RuntimeError) { dp.date_from(:asdfasdf) }
|
31
|
+
end
|
32
|
+
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,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ambethia-backup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nate Murray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-28 00:00:00 -07:00
|
13
|
+
default_executable: backup
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.7.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: runt
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: net-ssh
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: madeleine
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.7.3
|
54
|
+
version:
|
55
|
+
description:
|
56
|
+
email: nate@natemurray.com
|
57
|
+
executables:
|
58
|
+
- backup
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- CHANGELOG
|
63
|
+
- Rakefile
|
64
|
+
- TODO
|
65
|
+
files:
|
66
|
+
- bin/backup
|
67
|
+
- bin/commands.sh
|
68
|
+
- doc/LICENSE-GPL.txt
|
69
|
+
- doc/index.html
|
70
|
+
- doc/styles.css
|
71
|
+
- examples/global.rb
|
72
|
+
- examples/mediawiki.rb
|
73
|
+
- examples/mediawiki_numeric.rb
|
74
|
+
- examples/s3.rb
|
75
|
+
- lib/backup.rb
|
76
|
+
- lib/backup/actor.rb
|
77
|
+
- lib/backup/cli.rb
|
78
|
+
- lib/backup/configuration.rb
|
79
|
+
- lib/backup/date_parser.rb
|
80
|
+
- lib/backup/extensions.rb
|
81
|
+
- lib/backup/recipes/standard.rb
|
82
|
+
- lib/backup/rotator.rb
|
83
|
+
- lib/backup/s3_helpers.rb
|
84
|
+
- lib/backup/ssh_helpers.rb
|
85
|
+
- lib/backup/state_recorder.rb
|
86
|
+
- tests/actor_test.rb
|
87
|
+
- tests/cleanup.sh
|
88
|
+
- tests/optional/s3_test.rb
|
89
|
+
- tests/rotation_test.rb
|
90
|
+
- tests/s3_test.rb
|
91
|
+
- tests/ssh_test.rb
|
92
|
+
- tests/tests_helper.rb
|
93
|
+
- CHANGELOG
|
94
|
+
- Rakefile
|
95
|
+
- TODO
|
96
|
+
has_rdoc: false
|
97
|
+
homepage: http://tech.natemurray.com/backup
|
98
|
+
licenses:
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options:
|
101
|
+
- --charset=UTF-8
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
version:
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
version:
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project: backupgem
|
119
|
+
rubygems_version: 1.3.5
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Beginning-to-end solution for backups and rotation.
|
123
|
+
test_files:
|
124
|
+
- tests/actor_test.rb
|
125
|
+
- tests/optional/s3_test.rb
|
126
|
+
- tests/rotation_test.rb
|
127
|
+
- tests/s3_test.rb
|
128
|
+
- tests/ssh_test.rb
|