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.
- data/README.rdoc +48 -0
- data/Rakefile +7 -0
- data/bin/sycbackup +6 -0
- data/doc/Backup.html +186 -0
- data/doc/Backup/CronEdit.html +381 -0
- data/doc/Backup/Environment.html +231 -0
- data/doc/Backup/FileBackup.html +363 -0
- data/doc/Backup/MySQLBackup.html +305 -0
- data/doc/Backup/Options.html +328 -0
- data/doc/Backup/Process.html +261 -0
- data/doc/Backup/Runner.html +244 -0
- data/doc/README_rdoc.html +202 -0
- data/doc/Rakefile.html +118 -0
- data/doc/TestCronEdit.html +211 -0
- data/doc/TestEnvironment.html +156 -0
- data/doc/TestFileBackup.html +237 -0
- data/doc/TestMySQLBackup.html +167 -0
- data/doc/TestOptions.html +156 -0
- data/doc/TestProcess.html +236 -0
- data/doc/created.rid +18 -0
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +106 -0
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +148 -0
- data/lib/backup/cron_edit.rb +127 -0
- data/lib/backup/environment.rb +44 -0
- data/lib/backup/file_backup.rb +94 -0
- data/lib/backup/mysql_backup.rb +58 -0
- data/lib/backup/options.rb +199 -0
- data/lib/backup/process.rb +99 -0
- data/lib/backup/runner.rb +79 -0
- data/lib/backup_version.rb +9 -0
- data/syc-backup-0.0.1.gem +0 -0
- data/syc-backup-0.0.3.gem +0 -0
- data/sycbackup.gemspec +20 -0
- data/test/test_cron_edit.rb +49 -0
- data/test/test_environment.rb +22 -0
- data/test/test_file_backup.rb +70 -0
- data/test/test_mysql_backup.rb +71 -0
- data/test/test_options.rb +189 -0
- data/test/test_process.rb +40 -0
- metadata +123 -0
@@ -0,0 +1,231 @@
|
|
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::Environment - 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/environment.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-c-ruby">::ruby</a>
|
74
|
+
|
75
|
+
</ul>
|
76
|
+
</nav>
|
77
|
+
|
78
|
+
</div>
|
79
|
+
|
80
|
+
<div id="project-metadata">
|
81
|
+
<nav id="fileindex-section" class="section project-section">
|
82
|
+
<h3 class="section-header">Pages</h3>
|
83
|
+
|
84
|
+
<ul>
|
85
|
+
|
86
|
+
<li class="file"><a href="../README_rdoc.html">README</a>
|
87
|
+
|
88
|
+
<li class="file"><a href="../Rakefile.html">Rakefile</a>
|
89
|
+
|
90
|
+
</ul>
|
91
|
+
</nav>
|
92
|
+
|
93
|
+
<nav id="classindex-section" class="section project-section">
|
94
|
+
<h3 class="section-header">Class and Module Index</h3>
|
95
|
+
|
96
|
+
<ul class="link-list">
|
97
|
+
|
98
|
+
<li><a href="../Backup.html">Backup</a>
|
99
|
+
|
100
|
+
<li><a href="../Backup/CronEdit.html">Backup::CronEdit</a>
|
101
|
+
|
102
|
+
<li><a href="../Backup/Environment.html">Backup::Environment</a>
|
103
|
+
|
104
|
+
<li><a href="../Backup/FileBackup.html">Backup::FileBackup</a>
|
105
|
+
|
106
|
+
<li><a href="../Backup/MySQLBackup.html">Backup::MySQLBackup</a>
|
107
|
+
|
108
|
+
<li><a href="../Backup/Options.html">Backup::Options</a>
|
109
|
+
|
110
|
+
<li><a href="../Backup/Process.html">Backup::Process</a>
|
111
|
+
|
112
|
+
<li><a href="../Backup/Runner.html">Backup::Runner</a>
|
113
|
+
|
114
|
+
<li><a href="../TestCronEdit.html">TestCronEdit</a>
|
115
|
+
|
116
|
+
<li><a href="../TestEnvironment.html">TestEnvironment</a>
|
117
|
+
|
118
|
+
<li><a href="../TestFileBackup.html">TestFileBackup</a>
|
119
|
+
|
120
|
+
<li><a href="../TestMySQLBackup.html">TestMySQLBackup</a>
|
121
|
+
|
122
|
+
<li><a href="../TestOptions.html">TestOptions</a>
|
123
|
+
|
124
|
+
<li><a href="../TestProcess.html">TestProcess</a>
|
125
|
+
|
126
|
+
</ul>
|
127
|
+
</nav>
|
128
|
+
|
129
|
+
</div>
|
130
|
+
</nav>
|
131
|
+
|
132
|
+
<div id="documentation">
|
133
|
+
<h1 class="class">class Backup::Environment</h1>
|
134
|
+
|
135
|
+
<div id="description" class="description">
|
136
|
+
|
137
|
+
<p>Reads and filters the user’s environment variables to meet Ruby and Gem
|
138
|
+
requirements to run the application as a cron job</p>
|
139
|
+
|
140
|
+
</div><!-- description -->
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<!-- Constants -->
|
152
|
+
<section id="constants-list" class="section">
|
153
|
+
<h3 class="section-header">Constants</h3>
|
154
|
+
<dl>
|
155
|
+
|
156
|
+
<dt id="VARIABLES">VARIABLES
|
157
|
+
|
158
|
+
<dd class="description"><p>Contains the environment variable names that are required to run a Ruby
|
159
|
+
application from as a cron job</p>
|
160
|
+
|
161
|
+
|
162
|
+
</dl>
|
163
|
+
</section>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
<!-- Methods -->
|
169
|
+
|
170
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
171
|
+
<h3 class="section-header">Public Class Methods</h3>
|
172
|
+
|
173
|
+
|
174
|
+
<div id="method-c-ruby" class="method-detail ">
|
175
|
+
|
176
|
+
<div class="method-heading">
|
177
|
+
<span class="method-name">ruby</span><span
|
178
|
+
class="method-args">()</span>
|
179
|
+
<span class="method-click-advice">click to toggle source</span>
|
180
|
+
</div>
|
181
|
+
|
182
|
+
|
183
|
+
<div class="method-description">
|
184
|
+
|
185
|
+
<p>Retrieves the environment variables that are required running a Ruby
|
186
|
+
application as a cron job. The variable are returned in an Array</p>
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
<div class="method-source-code" id="ruby-source">
|
191
|
+
<pre><span class="ruby-comment"># File lib/backup/environment.rb, line 25</span>
|
192
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">ruby</span>
|
193
|
+
<span class="ruby-identifier">file</span> = <span class="ruby-string">".current_environment.tmp"</span>
|
194
|
+
<span class="ruby-identifier">system</span> (<span class="ruby-node">"env > #{file}"</span>)
|
195
|
+
|
196
|
+
<span class="ruby-identifier">lines</span> = []
|
197
|
+
|
198
|
+
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>, <span class="ruby-string">'r'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
|
199
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">gets</span>
|
200
|
+
<span class="ruby-identifier">variable</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">%r\A\w+(?=\=)/</span>).<span class="ruby-identifier">to_s</span>
|
201
|
+
<span class="ruby-identifier">lines</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">chomp</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">VARIABLES</span>.<span class="ruby-identifier">find_index</span> <span class="ruby-identifier">variable</span>.<span class="ruby-identifier">upcase</span>
|
202
|
+
<span class="ruby-keyword">end</span>
|
203
|
+
<span class="ruby-keyword">end</span>
|
204
|
+
|
205
|
+
<span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">file</span>
|
206
|
+
|
207
|
+
<span class="ruby-identifier">lines</span>
|
208
|
+
<span class="ruby-keyword">end</span></pre>
|
209
|
+
</div><!-- ruby-source -->
|
210
|
+
|
211
|
+
</div>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
</div><!-- ruby-method -->
|
217
|
+
|
218
|
+
|
219
|
+
</section><!-- public-class-method-details -->
|
220
|
+
|
221
|
+
</section><!-- 5Buntitled-5D -->
|
222
|
+
|
223
|
+
</div><!-- documentation -->
|
224
|
+
|
225
|
+
|
226
|
+
<footer id="validator-badges">
|
227
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
228
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
|
229
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
230
|
+
</footer>
|
231
|
+
|
@@ -0,0 +1,363 @@
|
|
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::FileBackup - 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/file_backup.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-c-new">::new</a>
|
74
|
+
|
75
|
+
<li><a href="#method-i-backup">#backup</a>
|
76
|
+
|
77
|
+
<li><a href="#method-i-check_for_inexistent">#check_for_inexistent</a>
|
78
|
+
|
79
|
+
<li><a href="#method-i-compress">#compress</a>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
</nav>
|
83
|
+
|
84
|
+
</div>
|
85
|
+
|
86
|
+
<div id="project-metadata">
|
87
|
+
<nav id="fileindex-section" class="section project-section">
|
88
|
+
<h3 class="section-header">Pages</h3>
|
89
|
+
|
90
|
+
<ul>
|
91
|
+
|
92
|
+
<li class="file"><a href="../README_rdoc.html">README</a>
|
93
|
+
|
94
|
+
<li class="file"><a href="../Rakefile.html">Rakefile</a>
|
95
|
+
|
96
|
+
</ul>
|
97
|
+
</nav>
|
98
|
+
|
99
|
+
<nav id="classindex-section" class="section project-section">
|
100
|
+
<h3 class="section-header">Class and Module Index</h3>
|
101
|
+
|
102
|
+
<ul class="link-list">
|
103
|
+
|
104
|
+
<li><a href="../Backup.html">Backup</a>
|
105
|
+
|
106
|
+
<li><a href="../Backup/CronEdit.html">Backup::CronEdit</a>
|
107
|
+
|
108
|
+
<li><a href="../Backup/Environment.html">Backup::Environment</a>
|
109
|
+
|
110
|
+
<li><a href="../Backup/FileBackup.html">Backup::FileBackup</a>
|
111
|
+
|
112
|
+
<li><a href="../Backup/MySQLBackup.html">Backup::MySQLBackup</a>
|
113
|
+
|
114
|
+
<li><a href="../Backup/Options.html">Backup::Options</a>
|
115
|
+
|
116
|
+
<li><a href="../Backup/Process.html">Backup::Process</a>
|
117
|
+
|
118
|
+
<li><a href="../Backup/Runner.html">Backup::Runner</a>
|
119
|
+
|
120
|
+
<li><a href="../TestCronEdit.html">TestCronEdit</a>
|
121
|
+
|
122
|
+
<li><a href="../TestEnvironment.html">TestEnvironment</a>
|
123
|
+
|
124
|
+
<li><a href="../TestFileBackup.html">TestFileBackup</a>
|
125
|
+
|
126
|
+
<li><a href="../TestMySQLBackup.html">TestMySQLBackup</a>
|
127
|
+
|
128
|
+
<li><a href="../TestOptions.html">TestOptions</a>
|
129
|
+
|
130
|
+
<li><a href="../TestProcess.html">TestProcess</a>
|
131
|
+
|
132
|
+
</ul>
|
133
|
+
</nav>
|
134
|
+
|
135
|
+
</div>
|
136
|
+
</nav>
|
137
|
+
|
138
|
+
<div id="documentation">
|
139
|
+
<h1 class="class">class Backup::FileBackup</h1>
|
140
|
+
|
141
|
+
<div id="description" class="description">
|
142
|
+
|
143
|
+
<p><a href="../Backup.html">Backup</a> directories and files to a backup
|
144
|
+
directory</p>
|
145
|
+
|
146
|
+
</div><!-- description -->
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
<!-- Methods -->
|
161
|
+
|
162
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
163
|
+
<h3 class="section-header">Public Class Methods</h3>
|
164
|
+
|
165
|
+
|
166
|
+
<div id="method-c-new" class="method-detail ">
|
167
|
+
|
168
|
+
<div class="method-heading">
|
169
|
+
<span class="method-name">new</span><span
|
170
|
+
class="method-args">(files=[])</span>
|
171
|
+
<span class="method-click-advice">click to toggle source</span>
|
172
|
+
</div>
|
173
|
+
|
174
|
+
|
175
|
+
<div class="method-description">
|
176
|
+
|
177
|
+
<p>Initializes the files to be backed up. If no file is provided an error is
|
178
|
+
returned</p>
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
<div class="method-source-code" id="new-source">
|
183
|
+
<pre><span class="ruby-comment"># File lib/backup/file_backup.rb, line 16</span>
|
184
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">files</span>=[])
|
185
|
+
<span class="ruby-ivar">@files</span> = <span class="ruby-identifier">files</span>
|
186
|
+
<span class="ruby-keyword">end</span></pre>
|
187
|
+
</div><!-- new-source -->
|
188
|
+
|
189
|
+
</div>
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
</div><!-- new-method -->
|
195
|
+
|
196
|
+
|
197
|
+
</section><!-- public-class-method-details -->
|
198
|
+
|
199
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
|
200
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
201
|
+
|
202
|
+
|
203
|
+
<div id="method-i-backup" class="method-detail ">
|
204
|
+
|
205
|
+
<div class="method-heading">
|
206
|
+
<span class="method-name">backup</span><span
|
207
|
+
class="method-args">(backup_folder)</span>
|
208
|
+
<span class="method-click-advice">click to toggle source</span>
|
209
|
+
</div>
|
210
|
+
|
211
|
+
|
212
|
+
<div class="method-description">
|
213
|
+
|
214
|
+
<p>The files to be backed up are initilized when creating an instance of <a
|
215
|
+
href="FileBackup.html">FileBackup</a>. These files are then backed up to
|
216
|
+
the backup directory</p>
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
<div class="method-source-code" id="backup-source">
|
221
|
+
<pre><span class="ruby-comment"># File lib/backup/file_backup.rb, line 51</span>
|
222
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">backup</span>(<span class="ruby-identifier">backup_folder</span>)
|
223
|
+
|
224
|
+
<span class="ruby-identifier">inexistent_files</span> = []
|
225
|
+
|
226
|
+
<span class="ruby-ivar">@files</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
|
227
|
+
<span class="ruby-identifier">inexistent_files</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">file</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">file</span>
|
228
|
+
<span class="ruby-keyword">end</span>
|
229
|
+
|
230
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">inexistent_files</span>.<span class="ruby-identifier">empty?</span>
|
231
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"Cannot backup inexistent files"</span>
|
232
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"Following #{inexistent_files.size} file(s) do not exist"</span>
|
233
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"#{inexistent_files.join(', ')}"</span>
|
234
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
235
|
+
<span class="ruby-keyword">end</span>
|
236
|
+
|
237
|
+
<span class="ruby-identifier">backup_folder</span> <span class="ruby-operator">+=</span> <span class="ruby-string">'/'</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">backup_folder</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">%r.*\/\Z/</span>)
|
238
|
+
|
239
|
+
<span class="ruby-constant">Dir</span>.<span class="ruby-identifier">mkdir</span> <span class="ruby-identifier">backup_folder</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">backup_folder</span>
|
240
|
+
|
241
|
+
<span class="ruby-identifier">backup_files</span> = []
|
242
|
+
|
243
|
+
<span class="ruby-ivar">@files</span>.<span class="ruby-identifier">each</span>.<span class="ruby-identifier">with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
244
|
+
<span class="ruby-identifier">backup_files</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">backup_file</span> = <span class="ruby-identifier">backup_folder</span><span class="ruby-operator">+</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">file</span>)
|
245
|
+
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">cp</span> <span class="ruby-identifier">file</span>, <span class="ruby-identifier">backup_file</span>
|
246
|
+
<span class="ruby-keyword">end</span>
|
247
|
+
|
248
|
+
<span class="ruby-identifier">backup_files</span>
|
249
|
+
|
250
|
+
<span class="ruby-keyword">end</span></pre>
|
251
|
+
</div><!-- backup-source -->
|
252
|
+
|
253
|
+
</div>
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
</div><!-- backup-method -->
|
259
|
+
|
260
|
+
|
261
|
+
<div id="method-i-check_for_inexistent" class="method-detail ">
|
262
|
+
|
263
|
+
<div class="method-heading">
|
264
|
+
<span class="method-name">check_for_inexistent</span><span
|
265
|
+
class="method-args">(files)</span>
|
266
|
+
<span class="method-click-advice">click to toggle source</span>
|
267
|
+
</div>
|
268
|
+
|
269
|
+
|
270
|
+
<div class="method-description">
|
271
|
+
|
272
|
+
<p>Checks if the files all exist. Files that do not exist are returned in an
|
273
|
+
Array</p>
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
<div class="method-source-code" id="check_for_inexistent-source">
|
278
|
+
<pre><span class="ruby-comment"># File lib/backup/file_backup.rb, line 83</span>
|
279
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">check_for_inexistent</span> (<span class="ruby-identifier">files</span>)
|
280
|
+
<span class="ruby-identifier">inexistent_files</span> = []
|
281
|
+
<span class="ruby-identifier">files</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
|
282
|
+
<span class="ruby-identifier">inexistent_files</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">f</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">f</span>
|
283
|
+
<span class="ruby-keyword">end</span>
|
284
|
+
|
285
|
+
<span class="ruby-identifier">inexistent_files</span>
|
286
|
+
<span class="ruby-keyword">end</span></pre>
|
287
|
+
</div><!-- check_for_inexistent-source -->
|
288
|
+
|
289
|
+
</div>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
</div><!-- check_for_inexistent-method -->
|
295
|
+
|
296
|
+
|
297
|
+
<div id="method-i-compress" class="method-detail ">
|
298
|
+
|
299
|
+
<div class="method-heading">
|
300
|
+
<span class="method-name">compress</span><span
|
301
|
+
class="method-args">(files, backup_folder)</span>
|
302
|
+
<span class="method-click-advice">click to toggle source</span>
|
303
|
+
</div>
|
304
|
+
|
305
|
+
|
306
|
+
<div class="method-description">
|
307
|
+
|
308
|
+
<p>Compress the files to the backup directory</p>
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
<div class="method-source-code" id="compress-source">
|
313
|
+
<pre><span class="ruby-comment"># File lib/backup/file_backup.rb, line 21</span>
|
314
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">compress</span>(<span class="ruby-identifier">files</span>, <span class="ruby-identifier">backup_folder</span>)
|
315
|
+
<span class="ruby-identifier">inexistent_files</span> = <span class="ruby-identifier">check_for_inexistent</span> <span class="ruby-identifier">files</span>
|
316
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">inexistent_files</span>.<span class="ruby-identifier">empty?</span>
|
317
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"Cannot compress inexistent files"</span>
|
318
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"Following #{inexistent_files.size} file(s) do not exist"</span>
|
319
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">inexistent_files</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">" "</span>)
|
320
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-value">2</span>
|
321
|
+
<span class="ruby-keyword">end</span>
|
322
|
+
|
323
|
+
<span class="ruby-identifier">timestamp</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">"%Y%m%d-%H%M%S"</span>)
|
324
|
+
<span class="ruby-identifier">backup_folder</span> <span class="ruby-operator">+=</span> <span class="ruby-string">'/'</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">backup_folder</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">%r.*\/\Z/</span>)
|
325
|
+
<span class="ruby-identifier">compress_file</span> = <span class="ruby-identifier">backup_folder</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">timestamp</span> <span class="ruby-operator">+</span> <span class="ruby-string">"_"</span> <span class="ruby-operator">+</span> <span class="ruby-string">"files.tar.gz"</span>
|
326
|
+
|
327
|
+
<span class="ruby-identifier">tar_command</span> = <span class="ruby-node">"tar cfz #{compress_file} "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">files</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">" "</span>)
|
328
|
+
|
329
|
+
<span class="ruby-identifier">stdout_str</span>, <span class="ruby-identifier">stderr_str</span>, <span class="ruby-identifier">status</span> = <span class="ruby-constant">Open3</span>.<span class="ruby-identifier">capture3</span>(<span class="ruby-identifier">tar_command</span>)
|
330
|
+
|
331
|
+
<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>
|
332
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"There was a problem running tar command"</span>
|
333
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"--> #{tar_command}"</span>
|
334
|
+
<span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">stderr_str</span>
|
335
|
+
<span class="ruby-identifier">exit</span>(<span class="ruby-value">2</span>)
|
336
|
+
<span class="ruby-keyword">end</span>
|
337
|
+
|
338
|
+
<span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span>
|
339
|
+
|
340
|
+
<span class="ruby-keyword">end</span></pre>
|
341
|
+
</div><!-- compress-source -->
|
342
|
+
|
343
|
+
</div>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
</div><!-- compress-method -->
|
349
|
+
|
350
|
+
|
351
|
+
</section><!-- public-instance-method-details -->
|
352
|
+
|
353
|
+
</section><!-- 5Buntitled-5D -->
|
354
|
+
|
355
|
+
</div><!-- documentation -->
|
356
|
+
|
357
|
+
|
358
|
+
<footer id="validator-badges">
|
359
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
360
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
|
361
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
362
|
+
</footer>
|
363
|
+
|