backupgemsteven 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,48 @@
1
+ = Backup Changelog
2
+ == Version 0.0.11
3
+ * Removed the tmpdir directive because it was screwing up the meta-code
4
+ * Moved the graffle and keynote files to an "extras" directory because it was breaking windows machines
5
+
6
+ == Version 0.0.10
7
+ * added a rubyforge rake task. This doesnt affect anyone but me so there is no gem for it.
8
+
9
+ == Version 0.0.9
10
+ * mercurial support
11
+ * multiple backups per day
12
+ * and a variety of bug fixes from patches submitted from the community. Its a
13
+ little bit closer to windows ready (thanks Jonathan Stott!) because of
14
+ increased use of FileUtils over "sh".
15
+
16
+ == Version 0.0.8
17
+ * The attached patch will add the 'backup' executable to your bin path using
18
+ the built-in RubyGems method for adding things to bin. Thanks to Anthony
19
+ Eden (aeden) for this patch.
20
+
21
+ == Version 0.0.7
22
+ * Fixed the default ssh port. It was wrong in version 0.0.6
23
+ * Added a 'rake test' task
24
+
25
+ == Version 0.0.6
26
+ * Added a default port
27
+ * Fixed an s3 'require' typo
28
+
29
+ == Version 0.0.5
30
+ * Added Amazon s3 support. Thanks to Jason Perry for this patch.
31
+ * Added an option for ssh port. Thanks to Frank Oxener for this patch.
32
+
33
+ == Version 0.0.4
34
+
35
+ * Fixed a bug in 'scp' in the standard recipe that ignored the user when using
36
+ scp. Thanks to Colin Slater for catching this.
37
+
38
+ == Version 0.0.3
39
+
40
+ * Fixed a critical bug that did not allow re-defining the :delivery or :rotate
41
+ methods. Thanks to James Healy for pointing this out.
42
+
43
+ == Version 0.0.2
44
+
45
+ * First stable code in place.
46
+ * Packaged in an gem format
47
+
48
+
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = 'backup'
5
+ gemspec.author = "Nate Murray"
6
+ gemspec.email = "nate@natemurray.com"
7
+ gemspec.homepage = "http://tech.natemurray.com/backup"
8
+ gemspec.platform = Gem::Platform::RUBY
9
+ gemspec.summary = "Beginning-to-end solution for backups and rotation."
10
+ gemspec.files = FileList["{bin,lib,tests,examples,doc}/**/*"].to_a
11
+ gemspec.require_path = "lib"
12
+ gemspec.test_files = FileList["{tests}/**/*test.rb"].to_a
13
+ gemspec.bindir = "bin" # Use these for applications.
14
+ gemspec.executables = ['backup']
15
+ gemspec.default_executable = "backup"
16
+ gemspec.has_rdoc = true
17
+ gemspec.extra_rdoc_files = ["README", "CHANGELOG", "TODO", "Rakefile"]
18
+ gemspec.rubyforge_project = "backupgem"
19
+ gemspec.add_dependency("rake", ">= 0.7.1")
20
+ gemspec.add_dependency("runt", ">= 0.3.0")
21
+ gemspec.add_dependency("net-ssh", ">= 2.0.0")
22
+ gemspec.add_dependency("madeleine", ">= 0.7.3")
23
+ end
24
+ rescue LoadError
25
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
26
+ end
data/TODO ADDED
@@ -0,0 +1,7 @@
1
+ == 2007-01-26
2
+ * Write some better tests
3
+ * Create a "rake test" task
4
+ * Create rake tasks for generating documentation
5
+ * Move documentation maker to this project
6
+ * Add documentation for s3
7
+ * Add documentation for ssh port
data/bin/backup ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__) + "/../lib"
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # no rubygems to load, so we fail silently
8
+ end
9
+
10
+ require 'backup/cli'
11
+
12
+ Backup::CLI.execute!
data/bin/commands.sh ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ ./bin/backup --recipe examples/mediawiki.rb
@@ -0,0 +1,280 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Library General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
data/doc/index.html ADDED
@@ -0,0 +1,716 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <title>BackupGem Manual</title>
5
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
6
+ <meta name="generator" content="Click">
7
+ <style type="text/css">
8
+ @import url("styles.css");
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <div id="container">
13
+ <div id="header"><h1>BackupGem Manual</h1></div>
14
+
15
+ <div id="wrapper">
16
+ <div id="content">
17
+
18
+ <div class="rightad">
19
+ <script type="text/javascript"><!--
20
+ google_ad_client = "pub-0934913060779093";
21
+ google_ad_width = 120;
22
+ google_ad_height = 600;
23
+ google_ad_format = "120x600_as";
24
+ google_ad_type = "image";
25
+ //2006-10-06: backup_skyscraper1
26
+ google_ad_channel ="7310496335";
27
+ //--></script>
28
+ <script type="text/javascript"
29
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
30
+ </script>
31
+ </div>
32
+
33
+
34
+
35
+
36
+
37
+ <a name="Introduction"></a><h2>Introduction</h2>
38
+
39
+ <a name="Introduction_Welcome"
40
+ ></a><h3>Welcome</h3>
41
+ <p><code><span class="constant">Backup</span></code> is the easiest and most flexible backup, archive and rotate tool. It&#8217;s a beginning-to-end solution for scheduled backups in a clean ruby package that is simple use and powerful when customized.
42
+ Backup allows you to specify each of the following options:</p>
43
+
44
+
45
+ <ul>
46
+ <li>what is being archived (files, folders, arbitrary scripts)</li>
47
+ <li>how it&#8217;s being archived (tar gzip, bz2)</li>
48
+ <li>where the archive is going (multiple backup servers? easy)</li>
49
+ <li>how the archive is going to get there (scp, ftp, mv)</li>
50
+ <li>where is will be stored when it gets there</li>
51
+ <li>how it&#8217;s going to be rotated when it gets there (grandfather-father-son, etc)</li>
52
+ <li>how often will this process happen (customizable cycles)</li>
53
+ <li>what happens to the working copy after the process (recreate files, folders etc. restart daemons)</li>
54
+ </ul>
55
+
56
+
57
+ <p>Backup is a collection of scripts that is complete enough to save you time, but flexible enough to work with any situation.
58
+ This is an early version of <code><span class="constant">Backup</span></code>. Please feel free to ask questions on how to use <code><span class="constant">Backup</span></code> or post suggestions for this manual in the <a href="http://rubyforge.org/mailman/listinfo/backupgem-users">mailing lists</a></p>
59
+
60
+
61
+
62
+
63
+ <a name="Housekeeping"></a><h2>Housekeeping</h2>
64
+
65
+ <a name="Housekeeping_Prerequisites"
66
+ ></a><h3>Prerequisites</h3>
67
+ <p><code><span class="constant">Backup</span></code> makes the following assumptions about your machines:</p>
68
+
69
+
70
+ <ul>
71
+ <li>server and client understand <span class="caps">POSIX</span> commmands</li>
72
+ <li>passwords and paths are the same on each backup server</li>
73
+ </ul>
74
+
75
+
76
+ <p><code><span class="constant">Backup</span></code> depends on the following libraries:</p>
77
+
78
+
79
+ <ul>
80
+ <li><a href="http://runt.rubyforge.org/">Runt</a> for describing temporal ranges.</li>
81
+ <li><a href="http://net-ssh.rubyforge.org/">Net::SSH</a> for <span class="caps">SSH</span> backups</li>
82
+ <li><a href="http://www.ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/index.html">Net::FTP</a> for <span class="caps">FTP</span> backups</li>
83
+ </ul>
84
+
85
+
86
+ <p>These are listed as dependencies in the gem file so you should be prompted to install them when you install Backup.</p>
87
+
88
+ <a name="Housekeeping_Using_RubyGems"
89
+ ></a><h3>Using RubyGems</h3>
90
+ If you have <a href="http://rubygems.rubyforge.org">RubyGems</a> installed, installing Backup is simple:
91
+ <blockquote>
92
+ <p><code><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">backupgem</span></code></p>
93
+ </blockquote>
94
+
95
+ <a name="Housekeeping_Using_svn"
96
+ ></a><h3>Using svn</h3>
97
+ If you prefer, you can checkout backupgem from the <a href="http://rubyforge.org/scm/?group_id=2110">RubyForge Repository</a>. Feel free to browse the releases or trunk <a href="http://rubyforge.org/scm/?group_id=2110">here</a>.
98
+ <blockquote>
99
+ <p><code><span class="ident">svn</span> <span class="ident">checkout</span> <span class="ident">svn</span><span class="punct">+</span><span class="ident">ssh</span><span class="punct">:/</span><span class="regex"></span><span class="punct">/</span><span class="ident">rubyforge</span><span class="punct">.</span><span class="ident">org</span><span class="punct">/</span><span class="ident">var</span><span class="punct">/</span><span class="ident">svn</span><span class="punct">/</span><span class="ident">backupgem</span></code></p>
100
+ </blockquote>
101
+
102
+ <a name="Housekeeping_License_Information"
103
+ ></a><h3>License Information</h3>
104
+ <p>Backup is made available under either the <span class="caps">BSD</span> license, or the same license Ruby (which, by extension, also allows the <span class="caps">GPL</span> as a permissable license as well). You can view the full text of any of these licenses in the <code><span class="ident">doc</span></code> subdirectory of the Backup distrubtion. The texts of the <span class="caps">BSD</span> and <span class="caps">GPL</span> licenses are also available online: <a href="http://www.opensource.org/licenses/bsd-license.php"><span class="caps">BSD</span></a> and <a href="http://www.opensource.org/licenses/gpl-license.php"><span class="caps">GPL</span></a>.</p>
105
+
106
+
107
+ <p>If you desire permission to use either Backup in a manner incompatible with these licenses, please contact the copyright holder <a href="mailto:nate+backup@natemurray.com">Nate Murray</a> in order to negotiate a more compatible license.</p>
108
+
109
+ <a name="Housekeeping_Support"
110
+ ></a><h3>Support</h3>
111
+ <p>Mailing lists, bug trackers, feature requests, and public forums are all available courtesty of <a href="http://rubyforge.org">RubyForge</a> at the <a href="http://rubyforge.org/projects/backupgem">BackupGem project page</a>.</p>
112
+
113
+ <a name="Housekeeping_Mailing_Lists"
114
+ ></a><h3>Mailing Lists</h3>
115
+ <table>
116
+ <tr>
117
+ <th>List Name </th>
118
+ <th>&nbsp; </th>
119
+ <th>Desc. </th>
120
+ </tr>
121
+ <tr>
122
+ <td> <a href="http://rubyforge.org/pipermail/backupgem-users">backupgem-users</a> </td>
123
+ <td> <a href="http://rubyforge.org/mailman/listinfo/backupgem-users">subscribe / unsubscribe</a> </td>
124
+ <td> The BackupGem users list is devoted to the discussion of and questions about the usage of Backup. If you can&#8217;t quite figure out how to get a feature of Backup to work, this is the list you would go to in order to ask your questions. </td>
125
+ </tr>
126
+ <tr>
127
+ <td> <a href="http://rubyforge.org/pipermail/backupgem-devel">backupgem-devel</a> </td>
128
+ <td> <a href="http://rubyforge.org/mailman/listinfo/backupgem-devel">subscribe / unsubscribe</a> </td>
129
+ <td> The Backup developers list is devoted to the discussion of Backup&#8217;s implementation. If you have created a patch that you would like to discuss, or if you would like to discuss a new feature, this is the list for you. </td>
130
+ </tr>
131
+ </table>
132
+
133
+ <a name="Housekeeping_About_the_Author"
134
+ ></a><h3>About the Author</h3>
135
+ <p>Backup was written by <a href="mailto:nate@natemurray.com">Nate Murray</a>.</p>
136
+
137
+
138
+ <p>Nate currently works at an internet retailer in Southern California. Feel free to send him compliments, money, praise, or new feature patches. You can also send questions and suggestions. However, for bug reports and general feature requests, please use the trackers on the <a href="http://rubyforge.org/projects/backupgem">BackupGem project page</a>.</p>
139
+
140
+ <a name="Housekeeping_Special_Thanks"
141
+ ></a><h3>Special Thanks</h3>
142
+ <p>Special thanks to:</p>
143
+
144
+
145
+ <ul>
146
+ <li>Matt Pulver for help with various technical problems and ideas.</li>
147
+ <li>Jamis Buck for writing <a href="http://weblog.rubyonrails.com/2006/8/30/capistrano-1-1-9-beta">Capistrano</a>. Capistrano provided the inspiration and some code for this work. Additionally, the Net::SSH manual provided partial inspiration for this manual. </li>
148
+ <li><a href="mailto:info@digitalclash.com">Matthew Lipper</a> for writing the Runt Ruby Temporal Expressions Library</li>
149
+ <li><a href="http://whytheluckystiff.net/">why the lucky stiff</a> for inspiration and some of the code to generate this manual.</li>
150
+ </ul>
151
+
152
+
153
+
154
+ <div class="ad">
155
+
156
+ <script type="text/javascript"><!--
157
+ google_ad_client = "pub-0934913060779093";
158
+ google_ad_width = 728;
159
+ google_ad_height = 90;
160
+ google_ad_format = "728x90_as";
161
+ google_ad_type = "text_image";
162
+ //2006-10-06: backup_before_recipe_1
163
+ google_ad_channel ="7683863986";
164
+ //--></script>
165
+ <script type="text/javascript"
166
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
167
+ </script>
168
+
169
+ </div>
170
+
171
+ <a name="How_Backup_Works"></a><h2>How Backup Works</h2>
172
+
173
+ <a name="How_Backup_Works_A_Typical_Backup"
174
+ ></a><h3>A Typical Backup</h3>
175
+ <p>A typical backup has the following sequence:</p>
176
+
177
+
178
+ <ul>
179
+ <li>content</li>
180
+ <li>compress</li>
181
+ <li>encrypt</li>
182
+ <li>deliver</li>
183
+ <li>rotate</li>
184
+ <li>cleanup</li>
185
+ </ul>
186
+
187
+
188
+ <p>This order is the default, however, like most things it is customizable. Think of it like a pipline: the input of each step is the output of the last step.
189
+ Each of these things are specified in a <code><span class="ident">recipe</span></code> file which is describe below.</p>
190
+
191
+ <a name="How_Backup_Works_CLI"
192
+ ></a><h3>CLI</h3>
193
+ <div class='example'><pre><code> <span class="constant">Usage</span><span class="punct">:</span> <span class="punct">./</span><span class="regex">backup [options]
194
+ Recipe Options -----------------------
195
+ -r, --recipe RECIPE A recipe file to load.
196
+
197
+ -g, --global FILE Specify the global recipe file to work
198
+ with. Defaults to the file +global.rb+
199
+ in the directory of +recipe+
200
+ -s, --set NAME=VALUE Specify a variable and it's value to
201
+ set. This will be set after loading all
202
+ recipe files.</span></code></pre></div>
203
+
204
+ <p><code><span class="constant">Backup</span></code> <i>is still in an early version. For now, I run the script directly from its <code><span class="ident">bin</span></code> folder in <code><span class="global">$GEMSROOT</span></code>. This will be moved to something like <code><span class="punct">/</span><span class="regex">usr</span><span class="punct">/</span><span class="ident">local</span><span class="punct">/</span><span class="ident">lib</span></code> in a future version. Patches to do this are welcome.</i></p>
205
+
206
+
207
+ <p>For now, you can run backup like so:</p>
208
+
209
+
210
+ <div class='example'><pre><code> <span class="punct">/</span><span class="regex">usr</span><span class="punct">/</span><span class="ident">local</span><span class="punct">/</span><span class="ident">lib</span><span class="punct">/</span><span class="ident">ruby</span><span class="punct">/</span><span class="ident">gems</span><span class="punct">/</span><span class="number">1.8</span><span class="punct">/</span><span class="ident">gems</span><span class="punct">/</span><span class="ident">backupgem</span><span class="punct">-</span><span class="number">0.0</span><span class="punct">.</span><span class="number">2</span><span class="punct">/</span><span class="ident">bin</span><span class="punct">/</span><span class="ident">backup</span> <span class="punct">--</span><span class="ident">recipe</span> <span class="punct">/</span><span class="ident">path</span><span class="punct">/</span><span class="ident">to</span><span class="punct">/</span><span class="ident">examples</span><span class="punct">/</span><span class="ident">mediawiki</span><span class="punct">.</span><span class="ident">rb</span></code></pre></div>
211
+
212
+ <p>Usually, you would set this as a cron job or something similar.</p>
213
+
214
+
215
+
216
+
217
+ <a name="Backup_Recipe_File_Format"></a><h2>Backup Recipe File Format</h2>
218
+
219
+ <a name="Backup_Recipe_File_Format_Recipes_Explained"
220
+ ></a><h3>Recipes Explained</h3>
221
+ <div class="longlist">
222
+
223
+ <ul>
224
+ <li>The Backup Recipe format is pure ruby code. Anything that is valid ruby is valid in the recipe file. There are, however, a number of shortcuts that will make your life easier.</li>
225
+ <li>Each of the steps are specified as an <code><span class="ident">action</span></code>. (An action is really nothing more than a method that becomes defined in the Actor instance. See the <a href="http://rubyforge.org/docman/?group_id=2110"><span class="caps">API</span> docs</a> if you&#8217;re interestd.)</li>
226
+ <li>You may create &#8220;hook&#8221; actions for any of the actions. So if you define a method <code><span class="ident">before_content</span></code> it will be called immediately before <code><span class="comment">#content</span></code> is called. A method named <code><span class="ident">after_rotation</span></code> would be called after <code><span class="comment">#rotation</span></code>. This may not always be needed as you can customize the rotation order by setting the <code><span class="ident">action_order</span></code>. See the <code><span class="ident">recipes</span><span class="punct">/</span><span class="ident">standard</span><span class="punct">.</span><span class="ident">rb</span></code> file for examples.</li>
227
+ <li>In each action, the variable <code><span class="ident">last_result</span></code> is set. This is the return value of the previously called method in the chain. Note that this includes the output of the &#8220;hook&#8221; methods. </li>
228
+ <li>All configuration variables are available to actions via the hash <code><span class="ident">c</span><span class="punct">[]</span></code>. For example, the backup path is available to your actions as <code><span class="ident">c</span><span class="punct">[</span><span class="symbol">:backup_path</span><span class="punct">]</span></code>.</li>
229
+ </ul>
230
+
231
+
232
+ </div>
233
+
234
+ <a name="Backup_Recipe_File_Format_Variables"
235
+ ></a><h3>Variables</h3>
236
+ <p>Setting variables is the bulk of the work you have to do when configuring your <code><span class="constant">Backup</span></code> scripts. These first two variables are required for all configurations.</p>
237
+
238
+
239
+ <p><i>The second variable could be omitted completely if the code was updated to use <code><span class="ident">tmpdir</span></code>. This is currently a <span class="caps">TODO</span>.</i></p>
240
+
241
+
242
+ <table>
243
+ <tr>
244
+ <th>Name </th>
245
+ <th>Desc. </th>
246
+ <th>Example </th>
247
+ </tr>
248
+ <tr>
249
+ <td> :backup_path </td>
250
+ <td> The path to place backup archives. </td>
251
+ <td> <code><span class="ident">set</span> <span class="symbol">:backup_path</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">/var/local/backups/mediawiki</span><span class="punct">&quot;</span></code> </td>
252
+ </tr>
253
+ <tr>
254
+ <td> :tmp_dir </td>
255
+ <td> Specify a directory that backup can use as a temporary directory. Default <code><span class="punct">/</span><span class="regex">tmp</span></code>. </td>
256
+ <td> <code><span class="ident">set</span> <span class="symbol">:tmp_dir</span><span class="punct">,</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">dirname</span><span class="punct">(</span><span class="constant">__FILE__</span><span class="punct">)</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">/../tmp</span><span class="punct">&quot;</span></code> </td>
257
+ </tr>
258
+ </table>
259
+
260
+
261
+
262
+
263
+ <p>The user running the script must have write permissions for each of these directories.</p>
264
+
265
+ <a name="Backup_Recipe_File_Format_Content"
266
+ ></a><h3>Content</h3>
267
+ <p>The first step in any backup is to locate (or create) the content that is to be backed up. Backup provides a couple of shortcuts for common ways to locate content and allows you to arbitrarily define your own.
268
+ Some typical types of content are:</p>
269
+
270
+
271
+ <ul>
272
+ <li>a particular file</li>
273
+ <li>a particular folder</li>
274
+ <li>the contents of a particular folder</li>
275
+ </ul>
276
+
277
+
278
+ These could be specified like so:
279
+ <div class='example'><pre><code> <span class="ident">action</span> <span class="symbol">:content</span><span class="punct">,</span> <span class="symbol">:is_file</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">/path/to/file</span><span class="punct">&quot;</span> <span class="comment"># content is a single file</span>
280
+ <span class="ident">action</span> <span class="symbol">:content</span><span class="punct">,</span> <span class="symbol">:is_folder</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">/path/to/folder</span><span class="punct">&quot;</span> <span class="comment"># content is the folder itself </span>
281
+ <span class="ident">action</span> <span class="symbol">:content</span><span class="punct">,</span> <span class="symbol">:is_contents_of</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">/path/to/other/folder</span><span class="punct">&quot;</span> <span class="comment"># content is folder/* , recursive option</span></code></pre></div>
282
+ If you want <code><span class="symbol">:content</span></code> to be a series of shell commands just pass <code><span class="comment">#action</span></code> a block:
283
+ <div class='example'><pre><code> <span class="ident">action</span><span class="punct">(</span><span class="symbol">:content</span><span class="punct">)</span> <span class="keyword">do</span>
284
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">echo <span class="escape">\&quot;</span>hello $HOSTNAME<span class="escape">\&quot;</span></span><span class="punct">&quot;</span>
285
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">mysqldump -uroot database &gt; /path/to/db.sql</span><span class="punct">&quot;</span>
286
+ <span class="punct">&quot;</span><span class="string">/path/to/db.sql</span><span class="punct">&quot;</span> <span class="comment"># make sure you return the full path to the folder/file you wish to be the content </span>
287
+ <span class="keyword">end</span></code></pre></div>
288
+
289
+ <a name="Backup_Recipe_File_Format_Compress"
290
+ ></a><h3>Compress</h3>
291
+ Next you may want to compress your content. Again, there are a few one-liners for common cases and you can create your own.
292
+ <div class='example'><pre><code> <span class="ident">action</span> <span class="symbol">:compress</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:tar_bz2</span> <span class="comment"># actually calls a method named tar_bz2 with output of &quot;:content&quot; ( or &quot;:after_content&quot; ) </span>
293
+ <span class="comment"># or</span>
294
+ <span class="ident">action</span> <span class="symbol">:compress</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:tar_gzip</span></code></pre></div>
295
+ Again, you can create your own.
296
+ <div class='example'><pre><code> <span class="ident">action</span><span class="punct">(</span><span class="symbol">:compress</span><span class="punct">)</span>
297
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">my_tar <span class="expr">#{last_result}</span> <span class="expr">#{last_result}</span>.tar</span><span class="punct">&quot;</span>
298
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">my_bzip <span class="expr">#{last_result}</span>.tar <span class="expr">#{last_result}</span>.tar.bz2</span><span class="punct">&quot;</span>
299
+ <span class="ident">last_result</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">.tar.bz2</span><span class="punct">&quot;</span>
300
+ <span class="keyword">end</span></code></pre></div>
301
+
302
+ <a name="Backup_Recipe_File_Format_Encrypt"
303
+ ></a><h3>Encrypt</h3>
304
+ Encryption is available to you, if you wish to use it.
305
+ <div class='example'><pre><code> <span class="ident">set</span> <span class="symbol">:encrypt</span><span class="punct">,</span> <span class="constant">true</span> <span class="comment"># default is +false+</span>
306
+ <span class="ident">set</span> <span class="symbol">:gpg_encrypt_options</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">--default-recipient</span><span class="punct">&quot;</span> <span class="comment"># default is an empty string</span>
307
+ <span class="ident">action</span> <span class="symbol">:encrypt</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:gpg</span> <span class="comment"># default, none</span></code></pre></div>
308
+ or your own:
309
+ <div class='example'><pre><code> <span class="ident">action</span><span class="punct">(</span><span class="symbol">:encrypt</span><span class="punct">)</span>
310
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">gpg <span class="expr">#{c[:gpg_encrypt_options]}</span> --encrypt <span class="expr">#{last_result}</span></span><span class="punct">&quot;</span>
311
+ <span class="ident">last_result</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">.gpg</span><span class="punct">&quot;</span>
312
+ <span class="keyword">end</span></code></pre></div>
313
+
314
+ <p>I would recommend that you think seriously about how you wish to manage your keys for this backup process. If you are backing up encrypted data then you need to backup your keys or else risk losing access to your data. Secure key management is beyond the scope of this document.</p>
315
+
316
+ <a name="Backup_Recipe_File_Format_Delivery"
317
+ ></a><h3>Delivery</h3>
318
+ <h4>Action</h4>
319
+
320
+
321
+ <p>Delivery is supported via <code><span class="ident">scp</span></code>, <code><span class="ident">ftp</span></code>, and <code><span class="ident">mv</span></code></p>
322
+
323
+
324
+ <p><i>Full <span class="caps">FTP</span> support is <a href="#Known_Bugs_and_Limitations_TODO">unfinished</a>. Currently, only <code><span class="ident">scp</span></code> and <code><span class="ident">mv</span></code> fully support rotation</i></p>
325
+
326
+
327
+ <div class='example'><pre><code> <span class="ident">action</span> <span class="symbol">:deliver</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:scp</span>
328
+ <span class="ident">action</span> <span class="symbol">:deliver</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:ftp</span>
329
+ <span class="ident">action</span> <span class="symbol">:deliver</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:mv</span></code></pre></div>
330
+ The <code><span class="symbol">:mv</span></code> action is defined (in <code><span class="ident">backup</span><span class="punct">/</span><span class="ident">recipes</span><span class="punct">/</span><span class="ident">standard</span><span class="punct">.</span><span class="ident">rb</span></code>) like any user-defined action:
331
+ <div class='example'><pre><code> <span class="ident">action</span><span class="punct">(</span><span class="symbol">:mv</span><span class="punct">)</span> <span class="keyword">do</span>
332
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">mv <span class="expr">#{last_result}</span> <span class="expr">#{c[:backup_path]}</span>/</span><span class="punct">&quot;</span>
333
+ <span class="ident">c</span><span class="punct">[</span><span class="symbol">:backup_path</span><span class="punct">]</span> <span class="attribute">@</span> <span class="punct">&quot;</span><span class="string">/</span><span class="punct">&quot;</span> <span class="attribute">@</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">basename</span><span class="punct">(</span><span class="ident">last_result</span><span class="punct">)</span>
334
+ <span class="keyword">end</span></code></pre></div>
335
+
336
+ <h4>Variables</h4>
337
+
338
+
339
+ <table>
340
+ <tr>
341
+ <th>Name </th>
342
+ <th>Desc. </th>
343
+ <th>Example </th>
344
+ </tr>
345
+ <tr>
346
+ <td> <code><span class="symbol">:servers</span></code> </td>
347
+ <td> An array of host names to deliver the data to. <br /><strong><a href="#Known_Bugs_and_Limitations_TODO"><span class="caps">TODO</span></a> this currently supports one 1 server</strong>. </td>
348
+ <td> <code><span class="ident">set</span> <span class="symbol">:servers</span><span class="punct">,</span> <span class="punct">%w{</span><span class="string"> localhost </span><span class="punct">}</span></code> </td>
349
+ </tr>
350
+ <tr>
351
+ <td> <code><span class="symbol">:ssh_user</span></code> </td>
352
+ <td> The name of the ssh user on the foreign server. Default <span class="caps">ENV</span>[&#8216;USER&#8217;]. </td>
353
+ <td> <code><span class="ident">set</span> <span class="symbol">:ssh_user</span><span class="punct">,</span> <span class="constant">ENV</span><span class="punct">['</span><span class="string">USER</span><span class="punct">']</span></code> </td>
354
+ </tr>
355
+ <tr>
356
+ <td> <code><span class="symbol">:identity_key</span></code> </td>
357
+ <td> The path to the key to use when ssh&#8217;ing into a foreign server. </td>
358
+ <td> <code><span class="ident">set</span> <span class="symbol">:identity_key</span><span class="punct">,</span> <span class="constant">ENV</span><span class="punct">['</span><span class="string">HOME</span><span class="punct">']</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">/.ssh/id_rsa</span><span class="punct">&quot;</span></code> </td>
359
+ </tr>
360
+ </table>
361
+
362
+ <a name="Backup_Recipe_File_Format_Rotate"
363
+ ></a><h3>Rotate</h3>
364
+ <p>Rotation of your backups is a way to keep snapshot copies of your backups in time while not keeping every single backup for every single day. Currently the only form of rotation Backup supports is <a href="http://en.wikipedia.org/wiki/Grandfather-father-son">grandfather-father-son</a>. See <a href="http://en.wikipedia.org/wiki/Grandfather-father-son">Wikipedia</a> if you are unfamiliar with how this works.</p>
365
+
366
+
367
+ <div class='example'><pre><code> <span class="ident">set</span> <span class="symbol">:rotation_method</span><span class="punct">,</span> <span class="symbol">:gfs</span> <span class="comment"># this is the default. you don't need to set it and there are no other supported options</span></code></pre></div>
368
+
369
+ <p>By deafult, a <code><span class="ident">son</span></code> is created daily, unless it is a day to create a <code><span class="ident">father</span></code> or <code><span class="ident">grandfather</span></code>. It is assumed that every time you run Backup you want to create a backup. Therefore, if you do not want to a <code><span class="ident">son</span></code> (etc), do not run the program. You can specify when a <code><span class="ident">son</span></code> is promoted to a <code><span class="ident">father</span></code> by the following variable:</p>
370
+
371
+
372
+ <div class='example'><pre><code> <span class="ident">set</span> <span class="symbol">:son_promoted_on</span><span class="punct">,</span> <span class="symbol">:fri</span></code></pre></div>
373
+
374
+ <p>You specify when fathers are promoted to grandfathers by something like the following</p>
375
+
376
+
377
+ <div class='example'><pre><code> <span class="ident">set</span> <span class="symbol">:father_promoted_on</span><span class="punct">,</span> <span class="symbol">:last_fri_of_the_month</span></code></pre></div>
378
+
379
+ <p>Valid arguments for specifying these promotions are as follows:</p>
380
+
381
+
382
+ <ul>
383
+ <li><code><span class="symbol">:mon</span></code>-<code><span class="symbol">:sun</span></code> &#8211; A symbol of the abbreviation of any day of the week</li>
384
+ <li><code><span class="symbol">:last_</span><span class="punct">[</span><span class="ident">mon</span><span class="punct">-</span><span class="ident">sun</span><span class="punct">]</span><span class="ident">_of_the_month</span></code> &#8211; A symbol, replacing <code><span class="punct">[</span><span class="ident">mon</span><span class="punct">-</span><span class="ident">sun</span><span class="punct">]</span></code> with the
385
+ abbreviation for the day of the weeks. <br />
386
+ Example: <code><span class="symbol">:last_thu_of_the_month</span></code>.</li>
387
+ <li>Any valid <code><span class="constant">Runt</span></code> object.</li>
388
+ </ul>
389
+
390
+
391
+ Representing these temporal ranges is done internally by using <code><span class="constant">Runt</span></code>. You are, therefore, allowed to pass in your own arbitrarily complex <code><span class="constant">Runt</span></code> object. For example, say that you wanted to promote to <code><span class="ident">father</span></code> on Monday, Wednesday and Friday. You could do the following:
392
+ <div class='example'><pre><code> <span class="ident">mon_wed_fri</span> <span class="punct">=</span> <span class="constant">Runt</span><span class="punct">::</span><span class="constant">DIWeek</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="constant">Runt</span><span class="punct">::</span><span class="constant">Mon</span><span class="punct">)</span> <span class="punct">|</span>
393
+ <span class="constant">Runt</span><span class="punct">::</span><span class="constant">DIWeek</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="constant">Runt</span><span class="punct">::</span><span class="constant">Wed</span><span class="punct">)</span> <span class="punct">|</span>
394
+ <span class="constant">Runt</span><span class="punct">::</span><span class="constant">DIWeek</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="constant">Runt</span><span class="punct">::</span><span class="constant">Fri</span><span class="punct">)</span>
395
+ <span class="ident">set</span> <span class="symbol">:son_promoted_on</span><span class="punct">,</span> <span class="ident">mon_wed_fri</span></code></pre></div>
396
+
397
+ <p>See the <a href="http://runt.rubyforge.org/">Runt documentation</a> for more information on this.</p>
398
+
399
+
400
+ <p>You can set how many of each rank to keep:</p>
401
+
402
+
403
+ <div class='example'><pre><code> <span class="comment"># assuming daily backups...</span>
404
+ <span class="ident">set</span> <span class="symbol">:sons_to_keep</span><span class="punct">,</span> <span class="number">14</span> <span class="comment"># this would be two weeks</span>
405
+ <span class="ident">set</span> <span class="symbol">:fathers_to_keep</span><span class="punct">,</span> <span class="number">6</span>
406
+ <span class="ident">set</span> <span class="symbol">:grandfathers_to_keep</span><span class="punct">,</span> <span class="number">6</span></code></pre></div>
407
+
408
+
409
+
410
+
411
+ <a name="Examples"></a><h2>Examples</h2>
412
+
413
+ <a name="Examples_Good_things_come_in_threes"
414
+ ></a><h3>Good things come in threes</h3>
415
+ <p>Here we will cover three examples. </p>
416
+
417
+
418
+ <ul>
419
+ <li>a super-simple backup to a local directory. This will show how easy
420
+ things can be.</li>
421
+ <li>a more complex implementation. This will show some of the variables
422
+ you can set and show how to use a foreign server.</li>
423
+ <li>an even more complex configuration. This will show how to define
424
+ your own methods and set more advanced variables.</li>
425
+ </ul>
426
+
427
+ <a name="Examples_Example_One___Backup_a_Folder_of_Logs"
428
+ ></a><h3>Example One | Backup a Folder of Logs</h3>
429
+ <p>Our first example will be backing up a folder of logs. Say we have a folder <code><span class="punct">/</span><span class="regex">var</span><span class="punct">/</span><span class="ident">my_logs</span><span class="punct">/</span></code> and it is full of log files.</p>
430
+
431
+
432
+ <p>What we want to do is:</p>
433
+
434
+
435
+ <ul>
436
+ <li>move out all the old log files</li>
437
+ <li>compress them and store them in a local folder</li>
438
+ <li>store 2 weeks of daily backups (sons)</li>
439
+ <li>store a weekly backup (father) going back 6 weeks</li>
440
+ <li>and create a monthly backup on the last friday of every month (grandfather) for 6 months</li>
441
+ </ul>
442
+
443
+
444
+ Thankfully, this is incredibly simple:
445
+ <div class='example'><pre><code> <span class="ident">set</span> <span class="symbol">:backup_path</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">/var/local/backups/my_old_logs</span><span class="punct">&quot;</span>
446
+ <span class="ident">set</span> <span class="symbol">:tmp_dir</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">/tmp</span><span class="punct">&quot;</span> <span class="comment"># this is the default so you actually dont have to specify it</span>
447
+ <span class="ident">action</span> <span class="symbol">:content</span><span class="punct">,</span> <span class="symbol">:is_contents_of</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">/var/my_logs</span><span class="punct">&quot;</span></code></pre></div>
448
+
449
+ <p>And thats it!</p>
450
+
451
+
452
+ <p>Notice a couple of things here.</p>
453
+
454
+
455
+ <ol>
456
+ <li>Each time we <code><span class="ident">set</span></code> a variable that becomes available to the actions as <code><span class="ident">c</span><span class="punct">[</span><span class="symbol">:var</span><span class="punct">]</span></code></li>
457
+ <li>In this case, make sure that <code><span class="symbol">:backup_path</span></code> and <code><span class="symbol">:tmp_dir</span></code> are writable by the user that is running the backup script.</li>
458
+ </ol>
459
+
460
+ <a name="Examples_Example_Two___SQL_Backup"
461
+ ></a><h3>Example Two | SQL Backup</h3>
462
+ <p>Our second example will be backing up a <a href="http://www.mediawiki.org">MediaWiki</a> installation. Say we have a MySQL database named <code><span class="ident">mediawiki</span></code>.</p>
463
+
464
+
465
+ <p>This time we want to:</p>
466
+
467
+
468
+ <ul>
469
+ <li>create a dump of the database every day</li>
470
+ <li>compress this backup and store it in a local folder</li>
471
+ <li>store 2 weeks of daily backups (son) [<em>same as last time</em>]</li>
472
+ <li>store &#8220;father&#8221; backups every Monday, Wednesday and Friday going back 6 weeks</li>
473
+ <li>and create a monthly backup on the last Friday of every month (grandfather) for 6 months</li>
474
+ </ul>
475
+
476
+
477
+ <div class='example'><pre><code> <span class="ident">set</span> <span class="symbol">:backup_path</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">/var/local/backups/mediawiki</span><span class="punct">&quot;</span>
478
+
479
+ <span class="ident">action</span><span class="punct">(</span><span class="symbol">:content</span><span class="punct">)</span> <span class="keyword">do</span>
480
+ <span class="ident">dump</span> <span class="punct">=</span> <span class="ident">c</span><span class="punct">[</span><span class="symbol">:tmp_dir</span><span class="punct">]</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">/mediawiki.sql</span><span class="punct">&quot;</span>
481
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">mysqldump -uroot mediawiki &gt; <span class="expr">#{dump}</span></span><span class="punct">&quot;</span>
482
+ <span class="ident">dump</span> <span class="comment"># make sure you return the name of the file</span>
483
+ <span class="keyword">end</span>
484
+
485
+ <span class="ident">action</span> <span class="symbol">:deliver</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:scp</span>
486
+ <span class="ident">action</span> <span class="symbol">:rotate</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:via_ssh</span>
487
+
488
+ <span class="ident">set</span> <span class="symbol">:servers</span><span class="punct">,</span> <span class="punct">%w{</span><span class="string"> my.server.com </span><span class="punct">}</span>
489
+
490
+ <span class="ident">set</span> <span class="symbol">:son_promoted_on</span><span class="punct">,</span> <span class="symbol">:sun</span>
491
+ <span class="ident">set</span> <span class="symbol">:father_promoted_on</span><span class="punct">,</span> <span class="symbol">:last_sun_of_the_month</span>
492
+
493
+ <span class="ident">set</span> <span class="symbol">:sons_to_keep</span><span class="punct">,</span> <span class="number">21</span>
494
+ <span class="ident">set</span> <span class="symbol">:fathers_to_keep</span><span class="punct">,</span> <span class="number">12</span>
495
+ <span class="ident">set</span> <span class="symbol">:grandfathers_to_keep</span><span class="punct">,</span> <span class="number">12</span></code></pre></div>
496
+
497
+ <p>A couple things to note:</p>
498
+
499
+
500
+ <ol>
501
+ <li>In this example, it is assumed that the current user running the
502
+ script has <code><span class="ident">ssh</span></code> keys configured for password-less login to
503
+ <code><span class="ident">my</span><span class="punct">.</span><span class="ident">server</span><span class="punct">.</span><span class="ident">com</span></code>. If you want to change the user to login as set the
504
+ variable <code><span class="symbol">:ssh_user</span></code>. You can also specify a key with
505
+ <code><span class="symbol">:identity_key</span></code>.</li>
506
+ <li>Number 1 is the only thing</li>
507
+ </ol>
508
+
509
+ <a name="Examples_Example_Three___Something_more_complex"
510
+ ></a><h3>Example Three | Something more complex</h3>
511
+ <p>By now it should be easy to see what is going on here:</p>
512
+
513
+
514
+ <div class='example'><pre><code> <span class="ident">action</span> <span class="symbol">:content</span><span class="punct">,</span> <span class="symbol">:is_file</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">/path/to/file.abc</span><span class="punct">&quot;</span>
515
+ <span class="ident">action</span> <span class="symbol">:compress</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:my_tar_gzip</span>
516
+
517
+ <span class="ident">action</span><span class="punct">(</span><span class="symbol">:my_tar_gzip</span><span class="punct">)</span> <span class="keyword">do</span>
518
+ <span class="ident">name</span> <span class="punct">=</span> <span class="ident">c</span><span class="punct">[</span><span class="symbol">:tmp_dir</span><span class="punct">]</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">/</span><span class="punct">&quot;</span> <span class="punct">+</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">basename</span><span class="punct">(</span><span class="ident">last_result</span><span class="punct">)</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">.tar.gzip</span><span class="punct">&quot;</span>
519
+ <span class="ident">sh</span> <span class="punct">&quot;</span><span class="string">tar -czv --exclude .DS* --exclude CVS <span class="expr">#{last_result}</span> &gt; <span class="expr">#{name}</span></span><span class="punct">&quot;</span>
520
+ <span class="ident">name</span> <span class="comment"># make sure you return the name of the tar.gzip file</span>
521
+ <span class="keyword">end</span>
522
+
523
+ <span class="ident">set</span> <span class="symbol">:encrypt</span><span class="punct">,</span> <span class="constant">true</span>
524
+
525
+ <span class="ident">action</span> <span class="symbol">:deliver</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:scp</span>
526
+ <span class="ident">action</span> <span class="symbol">:rotate</span><span class="punct">,</span> <span class="symbol">:method</span> <span class="punct">=&gt;</span> <span class="symbol">:via_ssh</span>
527
+
528
+ <span class="ident">set</span> <span class="symbol">:ssh_user</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">backup_user</span><span class="punct">&quot;</span>
529
+ <span class="ident">set</span> <span class="symbol">:identity_key</span><span class="punct">,</span> <span class="constant">ENV</span><span class="punct">['</span><span class="string">HOME</span><span class="punct">']</span> <span class="punct">+</span> <span class="punct">&quot;</span><span class="string">/.ssh/backup_key</span><span class="punct">&quot;</span></code></pre></div>
530
+
531
+
532
+
533
+ <div class="ad">
534
+
535
+ <script type="text/javascript"><!--
536
+ google_ad_client = "pub-0934913060779093";
537
+ google_ad_width = 728;
538
+ google_ad_height = 90;
539
+ google_ad_format = "728x90_as";
540
+ google_ad_type = "text_image";
541
+ //2006-10-06: backup_before_recipe_1
542
+ google_ad_channel ="7683863986";
543
+ //--></script>
544
+ <script type="text/javascript"
545
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
546
+ </script>
547
+
548
+ </div>
549
+
550
+ <a name="Known_Bugs_and_Limitations"></a><h2>Known Bugs and Limitations</h2>
551
+
552
+ <a name="Known_Bugs_and_Limitations_TODO"
553
+ ></a><h3>TODO</h3>
554
+ <p>What is left to do:</p>
555
+
556
+
557
+ <ul>
558
+ <li>Finish <span class="caps">FTP</span> support</li>
559
+ <li>Add support for multiple backup servers</li>
560
+ <li>Add in better logging </li>
561
+ <li>Remove all the <code><span class="ident">tmp_dir</span></code> references. use and test the standard library <code><span class="ident">tmpdir</span></code></li>
562
+ <li>Continue testing it</li>
563
+ </ul>
564
+
565
+
566
+ <p>If you find yourself writing the code for <code><span class="constant">Backup</span></code> to fix these things, please consider <a href="http://rubyforge.org/mailman/listinfo/backupgem-devel">submitting your patch</a> for the benefit of the community.</p>
567
+
568
+ <a name="Known_Bugs_and_Limitations_BUGS"
569
+ ></a><h3>BUGS</h3>
570
+ <ul>
571
+ <li>You can&#8217;t <code><span class="keyword">return</span></code> in the user-defined actions for some reason. I think this
572
+ has to do with the <code><span class="ident">instance_eval</span></code>. But still, I wouldn&#8217;t think it would
573
+ matter. I&#8217;d be interested in any suggestions on how to fix this.</li>
574
+ <li>Please submit other bugs via the trackers at the
575
+ <a href="http://rubyforge.org/projects/backupgem">BackupGem project page</a>.</li>
576
+ </ul>
577
+
578
+
579
+
580
+
581
+ </div> <!-- end content -->
582
+ </div> <!-- end wrapper -->
583
+
584
+ <div id="navigation">
585
+ <ol>
586
+
587
+ <li><a href="#Introduction">Introduction</a>
588
+ <ol>
589
+
590
+ <li><a href="#Introduction_Welcome"
591
+ >Welcome</a></li>
592
+
593
+ </ol>
594
+ </li>
595
+
596
+ <li><a href="#Housekeeping">Housekeeping</a>
597
+ <ol>
598
+
599
+ <li><a href="#Housekeeping_Prerequisites"
600
+ >Prerequisites</a></li>
601
+
602
+ <li><a href="#Housekeeping_Using_RubyGems"
603
+ >Using RubyGems</a></li>
604
+
605
+ <li><a href="#Housekeeping_Using_svn"
606
+ >Using svn</a></li>
607
+
608
+ <li><a href="#Housekeeping_License_Information"
609
+ >License Information</a></li>
610
+
611
+ <li><a href="#Housekeeping_Support"
612
+ >Support</a></li>
613
+
614
+ <li><a href="#Housekeeping_Mailing_Lists"
615
+ >Mailing Lists</a></li>
616
+
617
+ <li><a href="#Housekeeping_About_the_Author"
618
+ >About the Author</a></li>
619
+
620
+ <li><a href="#Housekeeping_Special_Thanks"
621
+ >Special Thanks</a></li>
622
+
623
+ </ol>
624
+ </li>
625
+
626
+ <li><a href="#How_Backup_Works">How Backup Works</a>
627
+ <ol>
628
+
629
+ <li><a href="#How_Backup_Works_A_Typical_Backup"
630
+ >A Typical Backup</a></li>
631
+
632
+ <li><a href="#How_Backup_Works_CLI"
633
+ >CLI</a></li>
634
+
635
+ </ol>
636
+ </li>
637
+
638
+ <li><a href="#Backup_Recipe_File_Format">Backup Recipe File Format</a>
639
+ <ol>
640
+
641
+ <li><a href="#Backup_Recipe_File_Format_Recipes_Explained"
642
+ >Recipes Explained</a></li>
643
+
644
+ <li><a href="#Backup_Recipe_File_Format_Variables"
645
+ >Variables</a></li>
646
+
647
+ <li><a href="#Backup_Recipe_File_Format_Content"
648
+ >Content</a></li>
649
+
650
+ <li><a href="#Backup_Recipe_File_Format_Compress"
651
+ >Compress</a></li>
652
+
653
+ <li><a href="#Backup_Recipe_File_Format_Encrypt"
654
+ >Encrypt</a></li>
655
+
656
+ <li><a href="#Backup_Recipe_File_Format_Delivery"
657
+ >Delivery</a></li>
658
+
659
+ <li><a href="#Backup_Recipe_File_Format_Rotate"
660
+ >Rotate</a></li>
661
+
662
+ </ol>
663
+ </li>
664
+
665
+ <li><a href="#Examples">Examples</a>
666
+ <ol>
667
+
668
+ <li><a href="#Examples_Good_things_come_in_threes"
669
+ >Good things come in threes</a></li>
670
+
671
+ <li><a href="#Examples_Example_One___Backup_a_Folder_of_Logs"
672
+ >Example One | Backup a Folder of Logs</a></li>
673
+
674
+ <li><a href="#Examples_Example_Two___SQL_Backup"
675
+ >Example Two | SQL Backup</a></li>
676
+
677
+ <li><a href="#Examples_Example_Three___Something_more_complex"
678
+ >Example Three | Something more complex</a></li>
679
+
680
+ </ol>
681
+ </li>
682
+
683
+ <li><a href="#Known_Bugs_and_Limitations">Known Bugs and Limitations</a>
684
+ <ol>
685
+
686
+ <li><a href="#Known_Bugs_and_Limitations_TODO"
687
+ >TODO</a></li>
688
+
689
+ <li><a href="#Known_Bugs_and_Limitations_BUGS"
690
+ >BUGS</a></li>
691
+
692
+ </ol>
693
+ </li>
694
+
695
+ </ol>
696
+
697
+ </div>
698
+
699
+ <div id="extra">
700
+ <ul>
701
+ <li><a href="http://tech.natemurray.com">tech.natemurray.com</a></li>
702
+ </ul>
703
+
704
+ </div>
705
+
706
+ <div id="footer">
707
+ <p>
708
+ &copy; 2006 <a href="mailto:nate+backupgem@natemurray.com">Nate Murray</a>. <span class="last_updated">Last updated Tue Oct 10 09:20:53 PDT 2006</span>
709
+ </p>
710
+
711
+ </div>
712
+
713
+
714
+ </div> <!-- end container -->
715
+ </body>
716
+ </html>