run_database_backup 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d3b015d4b9f55cf0be966d737349b918c8e3aaca6b6ae1b31cdac9a58bab698e
4
+ data.tar.gz: 28d91318c4ac301dd9ab18f28d22f31b3d8d358a4d961a36b2ee994ed2650cf9
5
+ SHA512:
6
+ metadata.gz: 8646bcd53a24551e59950c6ef7053b497a3dea2818e1c66c5c24bce0911a42cc8e1a627d0581c06f24edb3bed5708a4754be7b5b9e410a0587f1a1355e7f4da1
7
+ data.tar.gz: e158fbe39b3039fd89a202a979303ca51fe449943c79402bf9a2930e720b5e10d802b01dc2a48a02c9025a76b67872f169b6d007dc8ca30d7cd9825e7eb94d86
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-24
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Alef Ojeda de Oliveira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # RunDatabaseBackup
2
+
3
+ This gem provides rake tasks to backup different types of databases, including MongoDB, Postgres, and MySQL.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add run_database_backup
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install run_database_backup
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```bash
22
+ # Backup MongoDB
23
+ rails mongo:backup[uri,database_name,backup_directory]
24
+ # Env vars to set:
25
+ # MONGO_URL=mongodb://user:password@host:port
26
+ # MONGO_DATABASE=database_name
27
+ # MONGO_BACKUP_DIRECTORY='/path/to/backup/directory'
28
+ # Obs: set uri as mongodb://user:password@host:port without the database name
29
+
30
+ # Backup Postgres
31
+ rails postgres:backup[uri,database_name,backup_directory]
32
+ # Env vars to set:
33
+ # POSTGRES_URL=postgres://user:password@host:port
34
+ # POSTGRES_DATABASE=database_name
35
+ # POSTGRES_BACKUP_DIRECTORY='/path/to/backup/directory'
36
+ # Obs: set uri as postgres://user:password@host:port without the database name
37
+
38
+ # Backup MySQL
39
+ rails mysql:backup[uri,database_name,backup_directory]
40
+ # Env vars to set:
41
+ # MYSQL_URL=mysql2://user:password@host:port
42
+ # MYSQL_DATABASE=database_name
43
+ # MYSQL_BACKUP_DIRECTORY='/path/to/backup/directory'
44
+ #Obs: set uri as mysql2://user:password@host:port without the database name
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/nemuba/run_database_backup>.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,380 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: RunDatabaseBackup::Mongo
8
+
9
+ &mdash; Documentation by YARD 0.9.28
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "RunDatabaseBackup::Mongo";
19
+ relpath = '../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../_index.html">Index (M)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../RunDatabaseBackup.html" title="RunDatabaseBackup (module)">RunDatabaseBackup</a></span></span>
41
+ &raquo;
42
+ <span class="title">Mongo</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: RunDatabaseBackup::Mongo
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">Object</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">RunDatabaseBackup::Mongo</li>
78
+
79
+ </ul>
80
+ <a href="#" class="inheritanceTree">show all</a>
81
+
82
+ </dd>
83
+ </dl>
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ <dl>
96
+ <dt>Defined in:</dt>
97
+ <dd>lib/run_database_backup/mongo.rb</dd>
98
+ </dl>
99
+
100
+ </div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+
105
+ <p>Class to backup MongoDB Description: This class is responsible for backing up MongoDB databases Example: RunDatabaseBackup::Mongo.new(</p>
106
+
107
+ <pre class="code ruby"><code class="ruby">uri: &#39;mongodb://localhost:27017&#39;,
108
+ database_name: &#39;my_database&#39;,
109
+ backup_directory: &#39;/tmp&#39;
110
+ </code></pre>
111
+
112
+ <p>).dump</p>
113
+
114
+
115
+ </div>
116
+ </div>
117
+ <div class="tags">
118
+
119
+
120
+ </div>
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+ <h2>
129
+ Instance Method Summary
130
+ <small><a href="#" class="summary_toggle">collapse</a></small>
131
+ </h2>
132
+
133
+ <ul class="summary">
134
+
135
+ <li class="public ">
136
+ <span class="summary_signature">
137
+
138
+ <a href="#dump-instance_method" title="#dump (instance method)">#<strong>dump</strong> &#x21d2; void </a>
139
+
140
+
141
+
142
+ </span>
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+ <span class="summary_desc"><div class='inline'>
153
+ <p>Dump MongoDB database Description: This method is responsible for backing up MongoDB databases.</p>
154
+ </div></span>
155
+
156
+ </li>
157
+
158
+
159
+ <li class="public ">
160
+ <span class="summary_signature">
161
+
162
+ <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(uri:, database_name:, backup_directory:) &#x21d2; Mongo </a>
163
+
164
+
165
+
166
+ </span>
167
+
168
+
169
+ <span class="note title constructor">constructor</span>
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+ <span class="summary_desc"><div class='inline'>
179
+ <p>A new instance of Mongo.</p>
180
+ </div></span>
181
+
182
+ </li>
183
+
184
+
185
+ </ul>
186
+
187
+
188
+ <div id="constructor_details" class="method_details_list">
189
+ <h2>Constructor Details</h2>
190
+
191
+ <div class="method_details first">
192
+ <h3 class="signature first" id="initialize-instance_method">
193
+
194
+ #<strong>initialize</strong>(uri:, database_name:, backup_directory:) &#x21d2; <tt><span class='object_link'><a href="" title="RunDatabaseBackup::Mongo (class)">Mongo</a></span></tt>
195
+
196
+
197
+
198
+
199
+
200
+ </h3><div class="docstring">
201
+ <div class="discussion">
202
+
203
+ <p>Returns a new instance of Mongo.</p>
204
+
205
+
206
+ </div>
207
+ </div>
208
+ <div class="tags">
209
+ <p class="tag_title">Parameters:</p>
210
+ <ul class="param">
211
+
212
+ <li>
213
+
214
+ <span class='name'>uri</span>
215
+
216
+
217
+ <span class='type'>(<tt>String</tt>)</span>
218
+
219
+
220
+
221
+ &mdash;
222
+ <div class='inline'>
223
+ <p>MongoDB URI</p>
224
+ </div>
225
+
226
+ </li>
227
+
228
+ <li>
229
+
230
+ <span class='name'>database_name</span>
231
+
232
+
233
+ <span class='type'>(<tt>String</tt>)</span>
234
+
235
+
236
+
237
+ &mdash;
238
+ <div class='inline'>
239
+ <p>Database name</p>
240
+ </div>
241
+
242
+ </li>
243
+
244
+ <li>
245
+
246
+ <span class='name'>backup_directory</span>
247
+
248
+
249
+ <span class='type'>(<tt>String</tt>)</span>
250
+
251
+
252
+
253
+ &mdash;
254
+ <div class='inline'>
255
+ <p>Backup directory</p>
256
+ </div>
257
+
258
+ </li>
259
+
260
+ </ul>
261
+
262
+
263
+ </div><table class="source_code">
264
+ <tr>
265
+ <td>
266
+ <pre class="lines">
267
+
268
+
269
+ 19
270
+ 20
271
+ 21
272
+ 22
273
+ 23
274
+ 24</pre>
275
+ </td>
276
+ <td>
277
+ <pre class="code"><span class="info file"># File 'lib/run_database_backup/mongo.rb', line 19</span>
278
+
279
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>uri:</span><span class='comma'>,</span> <span class='label'>database_name:</span><span class='comma'>,</span> <span class='label'>backup_directory:</span><span class='rparen'>)</span>
280
+ <span class='ivar'>@uri</span> <span class='op'>=</span> <span class='id identifier rubyid_uri'>uri</span>
281
+ <span class='ivar'>@database_name</span> <span class='op'>=</span> <span class='id identifier rubyid_database_name'>database_name</span>
282
+ <span class='ivar'>@backup_directory</span> <span class='op'>=</span> <span class='id identifier rubyid_backup_directory'>backup_directory</span>
283
+ <span class='ivar'>@file_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='ivar'>@backup_directory</span><span class='embexpr_end'>}</span><span class='tstring_content'>/</span><span class='embexpr_beg'>#{</span><span class='ivar'>@database_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>-</span><span class='embexpr_beg'>#{</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%Y%m%d%H%M%S</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_content'>.gz</span><span class='tstring_end'>&quot;</span></span>
284
+ <span class='kw'>end</span></pre>
285
+ </td>
286
+ </tr>
287
+ </table>
288
+ </div>
289
+
290
+ </div>
291
+
292
+
293
+ <div id="instance_method_details" class="method_details_list">
294
+ <h2>Instance Method Details</h2>
295
+
296
+
297
+ <div class="method_details first">
298
+ <h3 class="signature first" id="dump-instance_method">
299
+
300
+ #<strong>dump</strong> &#x21d2; <tt>void</tt>
301
+
302
+
303
+
304
+
305
+
306
+ </h3><div class="docstring">
307
+ <div class="discussion">
308
+ <p class="note returns_void">This method returns an undefined value.</p>
309
+ <p>Dump MongoDB database Description: This method is responsible for backing up MongoDB databases</p>
310
+
311
+
312
+ </div>
313
+ </div>
314
+ <div class="tags">
315
+
316
+
317
+ </div><table class="source_code">
318
+ <tr>
319
+ <td>
320
+ <pre class="lines">
321
+
322
+
323
+ 29
324
+ 30
325
+ 31
326
+ 32
327
+ 33
328
+ 34
329
+ 35
330
+ 36
331
+ 37
332
+ 38
333
+ 39
334
+ 40
335
+ 41
336
+ 42
337
+ 43
338
+ 44
339
+ 45
340
+ 46</pre>
341
+ </td>
342
+ <td>
343
+ <pre class="code"><span class="info file"># File 'lib/run_database_backup/mongo.rb', line 29</span>
344
+
345
+ <span class='kw'>def</span> <span class='id identifier rubyid_dump'>dump</span>
346
+ <span class='comment'># Check if the backup directory exists
347
+ </span> <span class='const'>FileUtils</span><span class='period'>.</span><span class='id identifier rubyid_mkdir_p'>mkdir_p</span><span class='lparen'>(</span><span class='id identifier rubyid_backup_directory'>backup_directory</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_directory?'>directory?</span><span class='lparen'>(</span><span class='id identifier rubyid_backup_directory'>backup_directory</span><span class='rparen'>)</span>
348
+
349
+ <span class='comment'># Cmd to backup MongoDB database
350
+ </span> <span class='id identifier rubyid_cmd'>cmd</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>mongodump --uri=</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_uri'>uri</span><span class='embexpr_end'>}</span><span class='tstring_content'> --db=</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_database_name'>database_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> --gzip --archive=</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_file_path'>file_path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
351
+
352
+ <span class='comment'># Execute cmd
353
+ </span> <span class='id identifier rubyid_system'>system</span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
354
+
355
+ <span class='comment'># Output
356
+ </span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Backup of MongoDB database </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_database_name'>database_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> completed</span><span class='tstring_end'>&quot;</span></span>
357
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Backup directory: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_file_path'>file_path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
358
+ <span class='kw'>rescue</span> <span class='const'>StandardError</span>
359
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error: Backup of MongoDB database </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_database_name'>database_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> failed</span><span class='tstring_end'>&quot;</span></span>
360
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Verify if the MongoDB URI is correct and if the database name is correct</span><span class='tstring_end'>&quot;</span></span>
361
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Verify if the MongoDB database is running and command mongodump are installed</span><span class='tstring_end'>&quot;</span></span>
362
+ <span class='kw'>end</span></pre>
363
+ </td>
364
+ </tr>
365
+ </table>
366
+ </div>
367
+
368
+ </div>
369
+
370
+ </div>
371
+
372
+ <div id="footer">
373
+ Generated on Fri Feb 24 16:24:39 2023 by
374
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
375
+ 0.9.28 (ruby-3.2.0).
376
+ </div>
377
+
378
+ </div>
379
+ </body>
380
+ </html>