syc-backup 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README.rdoc +48 -0
  2. data/Rakefile +7 -0
  3. data/bin/sycbackup +6 -0
  4. data/doc/Backup.html +186 -0
  5. data/doc/Backup/CronEdit.html +381 -0
  6. data/doc/Backup/Environment.html +231 -0
  7. data/doc/Backup/FileBackup.html +363 -0
  8. data/doc/Backup/MySQLBackup.html +305 -0
  9. data/doc/Backup/Options.html +328 -0
  10. data/doc/Backup/Process.html +261 -0
  11. data/doc/Backup/Runner.html +244 -0
  12. data/doc/README_rdoc.html +202 -0
  13. data/doc/Rakefile.html +118 -0
  14. data/doc/TestCronEdit.html +211 -0
  15. data/doc/TestEnvironment.html +156 -0
  16. data/doc/TestFileBackup.html +237 -0
  17. data/doc/TestMySQLBackup.html +167 -0
  18. data/doc/TestOptions.html +156 -0
  19. data/doc/TestProcess.html +236 -0
  20. data/doc/created.rid +18 -0
  21. data/doc/images/add.png +0 -0
  22. data/doc/images/brick.png +0 -0
  23. data/doc/images/brick_link.png +0 -0
  24. data/doc/images/bug.png +0 -0
  25. data/doc/images/bullet_black.png +0 -0
  26. data/doc/images/bullet_toggle_minus.png +0 -0
  27. data/doc/images/bullet_toggle_plus.png +0 -0
  28. data/doc/images/date.png +0 -0
  29. data/doc/images/delete.png +0 -0
  30. data/doc/images/find.png +0 -0
  31. data/doc/images/loadingAnimation.gif +0 -0
  32. data/doc/images/macFFBgHack.png +0 -0
  33. data/doc/images/package.png +0 -0
  34. data/doc/images/page_green.png +0 -0
  35. data/doc/images/page_white_text.png +0 -0
  36. data/doc/images/page_white_width.png +0 -0
  37. data/doc/images/plugin.png +0 -0
  38. data/doc/images/ruby.png +0 -0
  39. data/doc/images/tag_blue.png +0 -0
  40. data/doc/images/tag_green.png +0 -0
  41. data/doc/images/transparent.png +0 -0
  42. data/doc/images/wrench.png +0 -0
  43. data/doc/images/wrench_orange.png +0 -0
  44. data/doc/images/zoom.png +0 -0
  45. data/doc/index.html +106 -0
  46. data/doc/js/darkfish.js +153 -0
  47. data/doc/js/jquery.js +18 -0
  48. data/doc/js/navigation.js +142 -0
  49. data/doc/js/search.js +94 -0
  50. data/doc/js/search_index.js +1 -0
  51. data/doc/js/searcher.js +228 -0
  52. data/doc/rdoc.css +543 -0
  53. data/doc/table_of_contents.html +148 -0
  54. data/lib/backup/cron_edit.rb +127 -0
  55. data/lib/backup/environment.rb +44 -0
  56. data/lib/backup/file_backup.rb +94 -0
  57. data/lib/backup/mysql_backup.rb +58 -0
  58. data/lib/backup/options.rb +199 -0
  59. data/lib/backup/process.rb +99 -0
  60. data/lib/backup/runner.rb +79 -0
  61. data/lib/backup_version.rb +9 -0
  62. data/syc-backup-0.0.1.gem +0 -0
  63. data/syc-backup-0.0.3.gem +0 -0
  64. data/sycbackup.gemspec +20 -0
  65. data/test/test_cron_edit.rb +49 -0
  66. data/test/test_environment.rb +22 -0
  67. data/test/test_file_backup.rb +70 -0
  68. data/test/test_mysql_backup.rb +71 -0
  69. data/test/test_options.rb +189 -0
  70. data/test/test_process.rb +40 -0
  71. metadata +123 -0
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require_relative '../lib/backup/environment'
4
+
5
+ # Tests Environment class to return the variables neccessary for running a
6
+ # Ruby application as a cron job
7
+ class TestEnvironment < Test::Unit::TestCase
8
+
9
+ context "Environment" do
10
+
11
+ should "return specified environment variables" do
12
+ vars = Backup::Environment::VARIABLES
13
+
14
+ extract = Backup::Environment.ruby
15
+ extract.each do |line|
16
+ assert_includes vars, line.match(/\A\w+(?=\=)/).to_s.upcase
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,70 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'fileutils'
4
+ require_relative '../lib/backup/file_backup.rb'
5
+
6
+ # Tests the FileBackup class.
7
+ class TestFileBackup < Test::Unit::TestCase
8
+
9
+ context "Providing erroneous user input" do
10
+
11
+ should "return error code 1 due to non existend file" do
12
+ fbu = Backup::FileBackup.new(["f1"])
13
+ begin
14
+ backup_files = fbu.backup "test/backup"
15
+ rescue SystemExit => e
16
+ assert_equal 1, e.status
17
+ end
18
+ end
19
+
20
+ should "return error code 1 due to non existend file within list" do
21
+ fbu = Backup::FileBackup.new(["f1","f2","f3"])
22
+ begin
23
+ backup_files = fbu.backup "test/backup"
24
+ rescue SystemExit => e
25
+ assert_equal 1, e.status
26
+ end
27
+ end
28
+
29
+ should "return error code 2 due to non existend file to compress" do
30
+ fbu = Backup::FileBackup.new
31
+ begin
32
+ backup_files = fbu.compress(["a","b","c"], "test/backup")
33
+ flunk "expected error code 2"
34
+ rescue SystemExit => e
35
+ assert_equal 2, e.status
36
+ end
37
+ end
38
+ end
39
+
40
+ context "Providing valid user input" do
41
+
42
+ # Create files to be backed up
43
+ def setup
44
+ ["file1", "file2", "file3"].each {|f| FileUtils.touch f}
45
+ end
46
+
47
+ # Remove files previously created with setup and all created files and
48
+ # directories during processing backups
49
+ def teardown
50
+ ["file1", "file2", "file3"].each {|f| FileUtils.rm f}
51
+ Dir["test/backup/file*"].each {|f| FileUtils.rm f}
52
+ Dir["test/backup/*.tar.gz"].each {|f| FileUtils.rm f}
53
+ Dir.rmdir "test/backup" if File.exists? "test/backup"
54
+ end
55
+
56
+ should "backup file in specified folder" do
57
+ fbu = Backup::FileBackup.new(["file1"])
58
+ backup_files = fbu.backup("test/backup")
59
+ assert_equal ["test/backup/file1"], backup_files
60
+ end
61
+
62
+ should "return compressed file in specified folder" do
63
+ fbu = Backup::FileBackup.new(["file1", "file2", "file3"])
64
+ backup_files = fbu.backup("test/backup/")
65
+ assert_equal 0, fbu.compress(backup_files, "test/backup")
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+
4
+ require_relative '../lib/backup/mysql_backup.rb'
5
+
6
+ # Tests for MySQLBackup class.
7
+ #
8
+ # Expects a running MySQL database server with following data
9
+ # table:: test
10
+ # user:: user
11
+ # password:: pass
12
+ #
13
+ class TestMySQLBackup < Test::Unit::TestCase
14
+
15
+ context "Providing erroneous user input" do
16
+
17
+ should "return error code 1 due to mysqldump error" do
18
+ myb = Backup::MySQLBackup.new("database", "user", "password")
19
+ begin
20
+ myb.backup
21
+ flunk(message="Expected a SystemExit!")
22
+ rescue SystemExit => e
23
+ assert_equal 1, e.status
24
+ end
25
+ end
26
+
27
+ should "return error code 2 due to compress error" do
28
+ myb = Backup::MySQLBackup.new("database", "user", "password")
29
+ begin
30
+ myb.compress("unexistent_file")
31
+ flunk(message="Expected a SystemExit!")
32
+ rescue SystemExit => e
33
+ assert_equal 2, e.status
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ context "Providing valid user input" do
40
+
41
+ setup do
42
+ @mbu = Backup::MySQLBackup.new("test", "pierre", "pass")
43
+ end
44
+
45
+ teardown do
46
+ Dir["test_*"].each { |file| File.delete file }
47
+ Dir["test/backup/test_*"].each { |file| File.delete file }
48
+ Dir.rmdir "test/backup" if File.exists? "test/backup"
49
+ end
50
+
51
+ should "create a database backup file in the default folder" do
52
+ backup_file = @mbu.backup
53
+ assert_match /\.\/test_\d{8}-\d{6}/, backup_file
54
+ end
55
+
56
+ should "create a database backup file in the provided backup folder" do
57
+ backup_file = @mbu.backup("test/backup/")
58
+ assert_match /test\/backup\/test_\d{8}-\d{6}/, backup_file
59
+ end
60
+
61
+ should "create a compressed file in the default folder" do
62
+ backup_file = @mbu.backup
63
+ assert 0 == @mbu.compress(backup_file)
64
+ end
65
+
66
+ should "create a compressed file in the provided backup folder" do
67
+ backup_file = @mbu.backup("test/backup/")
68
+ assert 0 == @mbu.compress(backup_file)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,189 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require_relative '../lib/backup/options'
4
+
5
+ # Test that user input is correctly interpreted and provided to other classes
6
+ # over methods.
7
+ class TestOptions < Test::Unit::TestCase
8
+
9
+ context "Erroneous user input" do
10
+ should "return error code 16 due to missing database and files" do
11
+ begin
12
+ opts = Backup::Options.new(["--no-compress", "--override",
13
+ "~/backup/old"])
14
+ rescue SystemExit => e
15
+ assert_equal 16, e.status
16
+ end
17
+ end
18
+
19
+ should "return error code 16 due to no database input" do
20
+ begin
21
+ opts = Backup::Options.new(["-u", "user", "-p", "pass"])
22
+ rescue SystemExit => e
23
+ assert_equal 16, e.status
24
+ end
25
+ end
26
+
27
+ should "return error code 2 due to missing user" do
28
+ begin
29
+ opts = Backup::Options.new(["-d", "database", "-p", "pass"])
30
+ rescue SystemExit => e
31
+ assert_equal 2, e.status
32
+ end
33
+ end
34
+
35
+ should "return error code 4 due to missing password" do
36
+ begin
37
+ opts = Backup::Options.new(["-d", "database", "-u", "user"])
38
+ rescue SystemExit => e
39
+ assert_equal 4, e.status
40
+ end
41
+ end
42
+
43
+ should "return error code 16 due to missing database and user" do
44
+ begin
45
+ opts = Backup::Options.new(["-p", "pass"])
46
+ rescue SystemExit => e
47
+ assert_equal 16, e.status
48
+ end
49
+ end
50
+
51
+ should "return error code 6 due to missing user and password" do
52
+ begin
53
+ opts = Backup::Options.new(["-d", "database"])
54
+ rescue SystemExit => e
55
+ assert_equal 6, e.status
56
+ end
57
+ end
58
+
59
+ should "return error code 1 due to missing database" do
60
+ begin
61
+ opts = Backup::Options.new(["-f", "a,b,c", "-u", "user", "-p", "pass"])
62
+ rescue SystemExit => e
63
+ assert_equal 1, e.status
64
+ end
65
+ end
66
+
67
+ should "return error code 3 due to missing database and user" do
68
+ begin
69
+ opts = Backup::Options.new(["-f", "a", "-p", "pass"])
70
+ rescue SystemExit => e
71
+ assert_equal 3, e.status
72
+ end
73
+ end
74
+
75
+ should "return error code -1 due to wrong switch and flag" do
76
+ begin
77
+ opts = Backup::Options.new(["-x"])
78
+ rescue SystemExit => e
79
+ assert_equal -1, e.status
80
+ end
81
+ end
82
+
83
+ should "return error code -1 due to missing argument for -f" do
84
+ begin
85
+ opts = Backup::Options.new(["-f"])
86
+ rescue SystemExit => e
87
+ assert_equal -1, e.status
88
+ end
89
+ end
90
+
91
+ should "return error code 8 due to wrong cron values" do
92
+ begin
93
+ opts = Backup::Options.new(["-d", "database", "-u", "user", "-p",
94
+ "pass", "--cron", "60,24,32,*,d,e"])
95
+ rescue SystemExit => e
96
+ assert_equal 8, e.status
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ context "Correct user input" do
103
+
104
+ should "return database, user, password and default backup_folder" do
105
+ default_backup_folder_exists =
106
+ File.exists? Backup::Options::DEFAULT_BACKUP_FOLDER
107
+ opts = Backup::Options.new(["-d", "database", "-u", "user", "-p", "pass"])
108
+ assert_equal "database", opts.database
109
+ assert_equal "user", opts.user
110
+ assert_equal "pass", opts.password
111
+ unless default_backup_folder_exists
112
+ assert_match Backup::Options::DEFAULT_BACKUP_FOLDER, opts.backup_folder
113
+ else
114
+ assert_match /#{Backup::Options::DEFAULT_BACKUP_FOLDER}_\d{8}-\d{6}\//,
115
+ opts.backup_folder
116
+ end
117
+ end
118
+
119
+ should "return database and specified backup folder" do
120
+ opts = Backup::Options.new(["-d", "database", "-u", "user", "-p", "pass",
121
+ "~/backups/2013/drupal"])
122
+ assert_equal "database", opts.database
123
+ assert_equal File.expand_path("~/backups/2013/drupal/"),
124
+ File.expand_path(opts.backup_folder)
125
+ end
126
+
127
+ should "return database and file" do
128
+ opts = Backup::Options.new(["-d", "database", "-u", "user", "-p", "pass",
129
+ "-f", "file_a"])
130
+ assert_equal "database", opts.database
131
+ assert_equal "file_a", opts.files[0]
132
+ end
133
+
134
+ should "return database, files and cron schedule" do
135
+ opts = Backup::Options.new(["-d", "database", "-u", "user", "-p", "pass",
136
+ "-f", "file_a,file_b",
137
+ "--cron", "15 3 * * *"])
138
+ assert_equal "database", opts.database
139
+ assert_equal 2, opts.files.size
140
+ assert_equal "15 3 * * *", opts.cron
141
+ end
142
+
143
+ should "return cron schedule even though too many arguments" do
144
+ opts = Backup::Options.new(["-d", "database", "-u", "user", "-p", "pass",
145
+ "--cron", "15 3 * 1 7 * * a"])
146
+ assert_equal "15 3 * 1 7", opts.cron
147
+ end
148
+
149
+ should "return without error (error code = 0) and print version" do
150
+ begin
151
+ opts = Backup::Options.new(["-v"])
152
+ rescue SystemExit => e
153
+ assert e.status == 0
154
+ end
155
+ end
156
+
157
+ should "return without error (error code = 0) and print help" do
158
+ begin
159
+ opts = Backup::Options.new(["-h"])
160
+ rescue SystemExit => e
161
+ assert e.status == 0
162
+ end
163
+ end
164
+
165
+ should "return files provided by user" do
166
+ opts = Backup::Options.new(["-f", "a,b,c"])
167
+ assert_equal ["a","b","c"], opts.files
168
+ end
169
+
170
+ should "return files stripped off trailing and leading blanks" do
171
+ opts = Backup::Options.new(["-f", "a, b, c "])
172
+ assert_equal ["a","b","c"], opts.files
173
+ end
174
+
175
+ should "return override" do
176
+ opts = Backup::Options.new(["-f", "a,b,c", "~/backup/new",
177
+ "--override"])
178
+ assert_equal ["a","b","c"], opts.files
179
+ assert_equal true, opts.override
180
+ end
181
+
182
+ should "return no-compress" do
183
+ opts = Backup::Options.new(["-f", "a,b,c", "--no-compress"])
184
+ assert_equal true, opts.no_compress
185
+ end
186
+
187
+ end
188
+
189
+ end
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'fileutils'
4
+ require_relative '../lib/backup/process.rb'
5
+
6
+ # Test for the Process class. Tests copy and compress commands
7
+ class TestProcess < Test::Unit::TestCase
8
+
9
+ context "Process" do
10
+
11
+ # Create files to backup
12
+ def setup
13
+ @files = ["file1", "file2", "file3"]
14
+ @files.each {|f| FileUtils.touch f}
15
+ end
16
+
17
+ # Remove files that have created with setup and all files and directories
18
+ # created during backup processing
19
+ def teardown
20
+ @files.each {|f| File.delete f}
21
+ Dir["test/backup_p/*"].each {|f| File.delete f if File.file? f}
22
+ end
23
+
24
+ should "backup files to provided folder without compressing" do
25
+ pro = Backup::Process.new("test/backup_p/", @files, false, true)
26
+ pro.backup
27
+ Dir["test/backup_p/*"].each do |f|
28
+ assert_equal 1, @files.count(File.basename(f))
29
+ end
30
+ end
31
+
32
+ should "compress files to provided folder" do
33
+ pro = Backup::Process.new("test/backup_p/", @files, false, false)
34
+ pro.backup
35
+ assert_equal 1, Dir["test/backup_p/*.tar.gz"].size
36
+ end
37
+
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syc-backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pierre Sugar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! "Back up a database and files or schedule cron job \n for
15
+ backup"
16
+ email: pierre@sugaryourcoffee.de
17
+ executables:
18
+ - sycbackup
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - README.rdoc
23
+ - syc-backup-0.0.3.gem
24
+ - test/test_process.rb
25
+ - test/test_mysql_backup.rb
26
+ - test/test_options.rb
27
+ - test/test_cron_edit.rb
28
+ - test/test_environment.rb
29
+ - test/test_file_backup.rb
30
+ - sycbackup.gemspec
31
+ - lib/backup_version.rb
32
+ - lib/backup/file_backup.rb
33
+ - lib/backup/process.rb
34
+ - lib/backup/mysql_backup.rb
35
+ - lib/backup/options.rb
36
+ - lib/backup/cron_edit.rb
37
+ - lib/backup/environment.rb
38
+ - lib/backup/runner.rb
39
+ - doc/TestProcess.html
40
+ - doc/README_rdoc.html
41
+ - doc/TestEnvironment.html
42
+ - doc/Rakefile.html
43
+ - doc/TestFileBackup.html
44
+ - doc/table_of_contents.html
45
+ - doc/Backup/FileBackup.html
46
+ - doc/Backup/Environment.html
47
+ - doc/Backup/Options.html
48
+ - doc/Backup/Runner.html
49
+ - doc/Backup/Process.html
50
+ - doc/Backup/CronEdit.html
51
+ - doc/Backup/MySQLBackup.html
52
+ - doc/created.rid
53
+ - doc/js/searcher.js
54
+ - doc/js/search.js
55
+ - doc/js/navigation.js
56
+ - doc/js/search_index.js
57
+ - doc/js/jquery.js
58
+ - doc/js/darkfish.js
59
+ - doc/Backup.html
60
+ - doc/index.html
61
+ - doc/TestCronEdit.html
62
+ - doc/images/bullet_black.png
63
+ - doc/images/bullet_toggle_plus.png
64
+ - doc/images/package.png
65
+ - doc/images/wrench.png
66
+ - doc/images/page_white_width.png
67
+ - doc/images/wrench_orange.png
68
+ - doc/images/delete.png
69
+ - doc/images/page_green.png
70
+ - doc/images/ruby.png
71
+ - doc/images/tag_green.png
72
+ - doc/images/bug.png
73
+ - doc/images/transparent.png
74
+ - doc/images/bullet_toggle_minus.png
75
+ - doc/images/zoom.png
76
+ - doc/images/brick.png
77
+ - doc/images/page_white_text.png
78
+ - doc/images/find.png
79
+ - doc/images/add.png
80
+ - doc/images/brick_link.png
81
+ - doc/images/date.png
82
+ - doc/images/loadingAnimation.gif
83
+ - doc/images/macFFBgHack.png
84
+ - doc/images/plugin.png
85
+ - doc/images/tag_blue.png
86
+ - doc/rdoc.css
87
+ - doc/TestMySQLBackup.html
88
+ - doc/TestOptions.html
89
+ - bin/sycbackup
90
+ - Rakefile
91
+ - syc-backup-0.0.1.gem
92
+ homepage: http://syc.dyndns.org/drupal
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '1.9'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements:
111
+ - No requirements
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.25
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Back up a database and files
117
+ test_files:
118
+ - test/test_process.rb
119
+ - test/test_mysql_backup.rb
120
+ - test/test_options.rb
121
+ - test/test_cron_edit.rb
122
+ - test/test_environment.rb
123
+ - test/test_file_backup.rb