syc-backup 0.0.4

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.
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,48 @@
1
+ = Backup utility for database, folders and files
2
+ Backs up a MySQL database, folders and files to a default folder (~/backup) or to a specified folder. If the --cron switch is provided the specified database and files are not backed up rather a cron job of the provided command is added to crontab.
3
+
4
+ == Install
5
+ The application can be installed with
6
+ $ gem install syc-backup
7
+
8
+ == Usage
9
+ Backup a database to the default folder _~/backup_
10
+ $ sycup -d database -uuser -ppass
11
+
12
+ Backup a MySQL database, a directory and files to the default folder
13
+ $ sycup -d database -uuser -ppass -f directory,file1,file2
14
+
15
+ Specify a backup folder
16
+ $ sycup backup/folder -d database -uuser -ppass -f directory,file1,file2
17
+
18
+ Override files in the backup folder if they exist
19
+ $ sycup backup/folder --override -f directory,file1,file2
20
+
21
+ Don't compress the backup
22
+ $ sycup --no-compress -f directory,file1,file2
23
+
24
+ Create a cron job that is scheduled every day at 2:30
25
+ $ sycup -d database -uuser -ppass -f directory,file1 --cron 30,2,*,*,*
26
+
27
+ == Supported Platform
28
+ syc-backup has been tested with 1.9.3
29
+
30
+ == Notes
31
+ The application backs up the MySQL database with _mysqldump_. The dumpfile has the form yyyymmdd-HHMMSS_databasename.sql. After the files are backed up the dumpfile will be deleted.
32
+
33
+ If the --no-compress is provided the files are copied to the backup folder. Otherwise they are compressed with _tar cfz YYYYmmdd-HHMMSS_syc-backup.tar.gz_.
34
+
35
+ If the --override switch is not provided the backup directory will be added a timestamp. So if you create a cron job you should every now and then delete obsolete backup folders.
36
+
37
+ The source contains lib/backup/file_backup.rb which is not used in the application.
38
+
39
+ == Tests
40
+ The tests create folders and files and will be deleted after the tests finish. _MySQLBackup_ needs to run a MySQL database with a database _test_ and a user _user_ with the password _pass_.
41
+
42
+ The test files live in the test folder and begin with test_.
43
+
44
+ == Links
45
+ * [http://sugaryourcoffee.github.com/syc-backup] - RubyDoc
46
+ * [http://www.github.com/sugaryourcoffee/syc-backup] - Source code on GitHub
47
+ * [http://syc.dyndns.org/drupal/content/backup-drupal-database] - Development notebook
48
+ * [https://rubygems.org/gems/syc-backup] - RubyGems
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.test_files = FileList['test/test_*.rb']
6
+ end
7
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'backup/runner'
4
+
5
+ runner = Backup::Runner.new(ARGV)
6
+ runner.run
@@ -0,0 +1,186 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>module Backup - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="module">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/backup_version.rb
51
+ <li>lib/backup/file_backup.rb
52
+ <li>lib/backup/process.rb
53
+ <li>lib/backup/mysql_backup.rb
54
+ <li>lib/backup/options.rb
55
+ <li>lib/backup/cron_edit.rb
56
+ <li>lib/backup/environment.rb
57
+ <li>lib/backup/runner.rb
58
+ </ul>
59
+ </nav>
60
+
61
+
62
+ </div>
63
+
64
+ <div id="class-metadata">
65
+
66
+
67
+
68
+
69
+ </div>
70
+
71
+ <div id="project-metadata">
72
+ <nav id="fileindex-section" class="section project-section">
73
+ <h3 class="section-header">Pages</h3>
74
+
75
+ <ul>
76
+
77
+ <li class="file"><a href="./README_rdoc.html">README</a>
78
+
79
+ <li class="file"><a href="./Rakefile.html">Rakefile</a>
80
+
81
+ </ul>
82
+ </nav>
83
+
84
+ <nav id="classindex-section" class="section project-section">
85
+ <h3 class="section-header">Class and Module Index</h3>
86
+
87
+ <ul class="link-list">
88
+
89
+ <li><a href="./Backup.html">Backup</a>
90
+
91
+ <li><a href="./Backup/CronEdit.html">Backup::CronEdit</a>
92
+
93
+ <li><a href="./Backup/Environment.html">Backup::Environment</a>
94
+
95
+ <li><a href="./Backup/FileBackup.html">Backup::FileBackup</a>
96
+
97
+ <li><a href="./Backup/MySQLBackup.html">Backup::MySQLBackup</a>
98
+
99
+ <li><a href="./Backup/Options.html">Backup::Options</a>
100
+
101
+ <li><a href="./Backup/Process.html">Backup::Process</a>
102
+
103
+ <li><a href="./Backup/Runner.html">Backup::Runner</a>
104
+
105
+ <li><a href="./TestCronEdit.html">TestCronEdit</a>
106
+
107
+ <li><a href="./TestEnvironment.html">TestEnvironment</a>
108
+
109
+ <li><a href="./TestFileBackup.html">TestFileBackup</a>
110
+
111
+ <li><a href="./TestMySQLBackup.html">TestMySQLBackup</a>
112
+
113
+ <li><a href="./TestOptions.html">TestOptions</a>
114
+
115
+ <li><a href="./TestProcess.html">TestProcess</a>
116
+
117
+ </ul>
118
+ </nav>
119
+
120
+ </div>
121
+ </nav>
122
+
123
+ <div id="documentation">
124
+ <h1 class="module">module Backup</h1>
125
+
126
+ <div id="description" class="description">
127
+
128
+ <p><a href="Backup.html">Backup</a> contains functions to backup a MySQL
129
+ database and files and directories to a default or specified backup
130
+ directory. Instead of instant backup the invoked command can be added to a
131
+ crontab and invoked based on the provided schedule that is a parameter of
132
+ the --cron option. The backed up files are per default compressed but this
133
+ can be ommitted</p>
134
+
135
+ <p><a href="Backup.html">Backup</a> contains functions to backup a MySQL
136
+ database and files and directories to a default or specified backup
137
+ directory. Instead of instant backup the invoked command can be added to a
138
+ crontab and invoked based on the provided schedule that is a parameter of
139
+ the --cron option. The backed up files are per default compressed but this
140
+ can be ommitted</p>
141
+
142
+ <p>The module <a href="Backup.html">Backup</a> provides functions to backup
143
+ MySQL databases and files and folders. The backup will be compressed to a
144
+ default or a specified backup folder. Rather than backing up the files a
145
+ cron job can be scheduled invoking the provided command.</p>
146
+
147
+ </div><!-- description -->
148
+
149
+
150
+
151
+
152
+ <section id="5Buntitled-5D" class="documentation-section">
153
+
154
+
155
+
156
+
157
+
158
+ <!-- Constants -->
159
+ <section id="constants-list" class="section">
160
+ <h3 class="section-header">Constants</h3>
161
+ <dl>
162
+
163
+ <dt id="VERSION">VERSION
164
+
165
+ <dd class="description"><p>Version of the application</p>
166
+
167
+
168
+ </dl>
169
+ </section>
170
+
171
+
172
+
173
+
174
+ <!-- Methods -->
175
+
176
+ </section><!-- 5Buntitled-5D -->
177
+
178
+ </div><!-- documentation -->
179
+
180
+
181
+ <footer id="validator-badges">
182
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
183
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
184
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
185
+ </footer>
186
+
@@ -0,0 +1,381 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>class Backup::CronEdit - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "../";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="class">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="../index.html">Home</a>
28
+ <a href="../table_of_contents.html#classes">Classes</a>
29
+ <a href="../table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/backup/cron_edit.rb
51
+ </ul>
52
+ </nav>
53
+
54
+
55
+ </div>
56
+
57
+ <div id="class-metadata">
58
+
59
+ <nav id="parent-class-section" class="section">
60
+ <h3 class="section-header">Parent</h3>
61
+
62
+ <p class="link">Object
63
+
64
+ </nav>
65
+
66
+
67
+ <!-- Method Quickref -->
68
+ <nav id="method-list-section" class="section">
69
+ <h3 class="section-header">Methods</h3>
70
+
71
+ <ul class="link-list">
72
+
73
+ <li><a href="#method-i-add_command">#add_command</a>
74
+
75
+ <li><a href="#method-i-cleanup">#cleanup</a>
76
+
77
+ <li><a href="#method-i-remove_command">#remove_command</a>
78
+
79
+ </ul>
80
+ </nav>
81
+
82
+ </div>
83
+
84
+ <div id="project-metadata">
85
+ <nav id="fileindex-section" class="section project-section">
86
+ <h3 class="section-header">Pages</h3>
87
+
88
+ <ul>
89
+
90
+ <li class="file"><a href="../README_rdoc.html">README</a>
91
+
92
+ <li class="file"><a href="../Rakefile.html">Rakefile</a>
93
+
94
+ </ul>
95
+ </nav>
96
+
97
+ <nav id="classindex-section" class="section project-section">
98
+ <h3 class="section-header">Class and Module Index</h3>
99
+
100
+ <ul class="link-list">
101
+
102
+ <li><a href="../Backup.html">Backup</a>
103
+
104
+ <li><a href="../Backup/CronEdit.html">Backup::CronEdit</a>
105
+
106
+ <li><a href="../Backup/Environment.html">Backup::Environment</a>
107
+
108
+ <li><a href="../Backup/FileBackup.html">Backup::FileBackup</a>
109
+
110
+ <li><a href="../Backup/MySQLBackup.html">Backup::MySQLBackup</a>
111
+
112
+ <li><a href="../Backup/Options.html">Backup::Options</a>
113
+
114
+ <li><a href="../Backup/Process.html">Backup::Process</a>
115
+
116
+ <li><a href="../Backup/Runner.html">Backup::Runner</a>
117
+
118
+ <li><a href="../TestCronEdit.html">TestCronEdit</a>
119
+
120
+ <li><a href="../TestEnvironment.html">TestEnvironment</a>
121
+
122
+ <li><a href="../TestFileBackup.html">TestFileBackup</a>
123
+
124
+ <li><a href="../TestMySQLBackup.html">TestMySQLBackup</a>
125
+
126
+ <li><a href="../TestOptions.html">TestOptions</a>
127
+
128
+ <li><a href="../TestProcess.html">TestProcess</a>
129
+
130
+ </ul>
131
+ </nav>
132
+
133
+ </div>
134
+ </nav>
135
+
136
+ <div id="documentation">
137
+ <h1 class="class">class Backup::CronEdit</h1>
138
+
139
+ <div id="description" class="description">
140
+
141
+ <p>Adds or removes a command to the user’s crontab. To make sure that the Ruby
142
+ application is invoked as a cron job it needs the environment variables
143
+ that are available when run from command line. To meet these requirements
144
+ the environment variables are read and added to the crontab. If variables
145
+ already exist in the crontab they are overridden.</p>
146
+
147
+ </div><!-- description -->
148
+
149
+
150
+
151
+
152
+ <section id="5Buntitled-5D" class="documentation-section">
153
+
154
+
155
+
156
+
157
+
158
+ <!-- Constants -->
159
+ <section id="constants-list" class="section">
160
+ <h3 class="section-header">Constants</h3>
161
+ <dl>
162
+
163
+ <dt id="CRON_ENTRIES_FILE">CRON_ENTRIES_FILE
164
+
165
+ <dd class="description"><p>Temporary file that holds the entries to be written to the crontab</p>
166
+
167
+
168
+ </dl>
169
+ </section>
170
+
171
+
172
+
173
+
174
+ <!-- Methods -->
175
+
176
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
177
+ <h3 class="section-header">Public Instance Methods</h3>
178
+
179
+
180
+ <div id="method-i-add_command" class="method-detail ">
181
+
182
+ <div class="method-heading">
183
+ <span class="method-name">add_command</span><span
184
+ class="method-args">(command, environment=[])</span>
185
+ <span class="method-click-advice">click to toggle source</span>
186
+ </div>
187
+
188
+
189
+ <div class="method-description">
190
+
191
+ <p>Adds a command to the user’s crontab. If the provided command is empty <a
192
+ href="CronEdit.html#method-i-add_command">#add_command</a> will exit the
193
+ application with exit status -1. The method uses the <code>crontab
194
+ -l</code> and <code>crontab file</code> command. If the crontab call fails
195
+ the error message and exit status of <code>crontab</code> will be returned
196
+ and the application exits</p>
197
+
198
+
199
+
200
+ <div class="method-source-code" id="add_command-source">
201
+ <pre><span class="ruby-comment"># File lib/backup/cron_edit.rb, line 20</span>
202
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">add_command</span>(<span class="ruby-identifier">command</span>, <span class="ruby-identifier">environment</span>=[])
203
+ <span class="ruby-identifier">command</span> = <span class="ruby-identifier">command</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">&quot; &quot;</span>)
204
+
205
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">command</span>.<span class="ruby-identifier">empty?</span>
206
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Cannot add empty command to cron&quot;</span>
207
+ <span class="ruby-identifier">exit</span> <span class="ruby-value">-1</span>
208
+ <span class="ruby-keyword">end</span>
209
+
210
+ <span class="ruby-identifier">read_crontab_command</span> = <span class="ruby-string">'crontab -l'</span>
211
+
212
+ <span class="ruby-identifier">stdout</span>, <span class="ruby-identifier">stderr</span>, <span class="ruby-identifier">status</span> = <span class="ruby-constant">Open3</span>.<span class="ruby-identifier">capture3</span>(<span class="ruby-identifier">read_crontab_command</span>)
213
+
214
+ <span class="ruby-identifier">entries</span> = [] <span class="ruby-operator">+</span> <span class="ruby-identifier">environment</span>
215
+
216
+ <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">%r\n/</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">entry</span><span class="ruby-operator">|</span>
217
+ <span class="ruby-identifier">entry</span> = <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">&quot; &quot;</span>)
218
+ <span class="ruby-identifier">variable</span> = <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">%r\A\w+(?=\=)/</span>).<span class="ruby-identifier">to_s</span>
219
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">variable</span>.<span class="ruby-identifier">empty?</span>
220
+ <span class="ruby-identifier">entries</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">entry</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">environment</span>.<span class="ruby-identifier">grep</span>(<span class="ruby-node">%r\A#{variable}/</span>)
221
+ <span class="ruby-keyword">else</span>
222
+ <span class="ruby-identifier">entries</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">entry</span>
223
+ <span class="ruby-keyword">end</span>
224
+ <span class="ruby-keyword">end</span>
225
+
226
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">command</span>
227
+ <span class="ruby-identifier">entries</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">command</span>
228
+
229
+ <span class="ruby-identifier">cron_entries_file</span> = <span class="ruby-constant">CRON_ENTRIES_FILE</span>
230
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cron_entries_file</span>, <span class="ruby-string">'w'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
231
+ <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">entry</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">entry</span>}
232
+ <span class="ruby-keyword">end</span>
233
+
234
+ <span class="ruby-identifier">write_crontab_command</span> = <span class="ruby-node">&quot;crontab #{cron_entries_file}&quot;</span>
235
+
236
+ <span class="ruby-identifier">stdout</span>, <span class="ruby-identifier">stderr</span>, <span class="ruby-identifier">status</span> = <span class="ruby-constant">Open3</span>.<span class="ruby-identifier">capture3</span>(<span class="ruby-identifier">write_crontab_command</span>)
237
+
238
+ <span class="ruby-identifier">cleanup</span>
239
+
240
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
241
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;There is a problem executing command&quot;</span>
242
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">write_crontab_command</span>
243
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">stderr</span>
244
+ <span class="ruby-identifier">exit</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span>
245
+ <span class="ruby-keyword">end</span>
246
+ <span class="ruby-keyword">end</span>
247
+
248
+ <span class="ruby-identifier">command</span>
249
+
250
+ <span class="ruby-keyword">end</span></pre>
251
+ </div><!-- add_command-source -->
252
+
253
+ </div>
254
+
255
+
256
+
257
+
258
+ </div><!-- add_command-method -->
259
+
260
+
261
+ <div id="method-i-cleanup" class="method-detail ">
262
+
263
+ <div class="method-heading">
264
+ <span class="method-name">cleanup</span><span
265
+ class="method-args">()</span>
266
+ <span class="method-click-advice">click to toggle source</span>
267
+ </div>
268
+
269
+
270
+ <div class="method-description">
271
+
272
+ <p>Removes the <a href="CronEdit.html#CRON_ENTRIES_FILE">CRON_ENTRIES_FILE</a>
273
+ after the values have been written to crontab</p>
274
+
275
+
276
+
277
+ <div class="method-source-code" id="cleanup-source">
278
+ <pre><span class="ruby-comment"># File lib/backup/cron_edit.rb, line 123</span>
279
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">cleanup</span>
280
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span> <span class="ruby-constant">CRON_ENTRIES_FILE</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-constant">CRON_ENTRIES_FILE</span>
281
+ <span class="ruby-keyword">end</span></pre>
282
+ </div><!-- cleanup-source -->
283
+
284
+ </div>
285
+
286
+
287
+
288
+
289
+ </div><!-- cleanup-method -->
290
+
291
+
292
+ <div id="method-i-remove_command" class="method-detail ">
293
+
294
+ <div class="method-heading">
295
+ <span class="method-name">remove_command</span><span
296
+ class="method-args">(command)</span>
297
+ <span class="method-click-advice">click to toggle source</span>
298
+ </div>
299
+
300
+
301
+ <div class="method-description">
302
+
303
+ <p>Removes a command from the user’s crontab. If the provided command is
304
+ empty <a href="CronEdit.html#method-i-remove_command">#remove_command</a>
305
+ will exit the application with exit status -1. The method uses the
306
+ <code>crontab -l</code> and <code>crontab file</code> command. If the
307
+ crontab call fails the error message and exit status of
308
+ <code>crontab</code> will be returned and the application exits</p>
309
+
310
+
311
+
312
+ <div class="method-source-code" id="remove_command-source">
313
+ <pre><span class="ruby-comment"># File lib/backup/cron_edit.rb, line 75</span>
314
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">remove_command</span>(<span class="ruby-identifier">command</span>)
315
+ <span class="ruby-identifier">command</span> = <span class="ruby-identifier">command</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">&quot; &quot;</span>)
316
+
317
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">command</span>.<span class="ruby-identifier">empty?</span>
318
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Cannot delete empty command from crontab&quot;</span>
319
+ <span class="ruby-identifier">exit</span> <span class="ruby-value">-1</span>
320
+ <span class="ruby-keyword">end</span>
321
+
322
+ <span class="ruby-identifier">read_crontab_command</span> = <span class="ruby-string">&quot;crontab -l&quot;</span>
323
+
324
+ <span class="ruby-identifier">stdout</span>, <span class="ruby-identifier">stderr</span>, <span class="ruby-identifier">status</span> = <span class="ruby-constant">Open3</span>.<span class="ruby-identifier">capture3</span>(<span class="ruby-identifier">read_crontab_command</span>)
325
+
326
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
327
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;There is a problem executing command&quot;</span>
328
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">read_crontab_command</span>
329
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">stderr</span>
330
+ <span class="ruby-identifier">exit</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">existatus</span>
331
+ <span class="ruby-keyword">end</span>
332
+
333
+ <span class="ruby-identifier">entries</span> = <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">%r\n/</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">entry</span><span class="ruby-operator">|</span> <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">&quot; &quot;</span>)}
334
+
335
+ <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">command</span>)
336
+
337
+ <span class="ruby-identifier">cron_entries_file</span> = <span class="ruby-constant">CRON_ENTRIES_FILE</span> <span class="ruby-comment">#&quot;.cron_entries&quot;</span>
338
+
339
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cron_entries_file</span>, <span class="ruby-string">'w'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
340
+ <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">entry</span><span class="ruby-operator">|</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">entry</span>}
341
+ <span class="ruby-keyword">end</span>
342
+
343
+ <span class="ruby-identifier">write_crontab_command</span> = <span class="ruby-node">&quot;crontab #{cron_entries_file}&quot;</span>
344
+
345
+ <span class="ruby-identifier">stdout</span>, <span class="ruby-identifier">stderr</span>, <span class="ruby-identifier">status</span> = <span class="ruby-constant">Open3</span>.<span class="ruby-identifier">capture3</span>(<span class="ruby-identifier">write_crontab_command</span>)
346
+
347
+ <span class="ruby-identifier">cleanup</span>
348
+
349
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
350
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;There is a problem executing command&quot;</span>
351
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">write_crontab_command</span>
352
+ <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">stderr</span>
353
+ <span class="ruby-identifier">exit</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span>
354
+ <span class="ruby-keyword">end</span>
355
+
356
+ <span class="ruby-identifier">command</span>
357
+
358
+ <span class="ruby-keyword">end</span></pre>
359
+ </div><!-- remove_command-source -->
360
+
361
+ </div>
362
+
363
+
364
+
365
+
366
+ </div><!-- remove_command-method -->
367
+
368
+
369
+ </section><!-- public-instance-method-details -->
370
+
371
+ </section><!-- 5Buntitled-5D -->
372
+
373
+ </div><!-- documentation -->
374
+
375
+
376
+ <footer id="validator-badges">
377
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
378
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
379
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
380
+ </footer>
381
+