├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── TODO
├── btrfs-borg
└── possible-future-btrfs-borg-config.csv
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at nsteeves@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # btrfs-borg
2 | Btrfs-borg makes snapshots and backs up a list of btrfs snapshotted subvolumes using Borg. It will also optionally back up a list of directories without first creating snapshots for them. It includes special support for containers managed by LXC's btrfs backend. Finally it supports building manifests of directories that won't be backed up. If you configure manifest support, please make sure that the target location of the manifest will be on one of the subvolumes that you back up.
3 |
4 | eg: if SUBS=`@home rootfs`, but you also have a subvolume called @backups mounted at /home/backups, then 1) /home/backups will not be part of your borg backup, because btrfs-subvolume snap does not back up child subvolumes. 2) If your manifest goes to /home/backups/manifest then it will not be backed up. If /home/backups is not a separate subvolume, then /home/backups/manifest will be part of the btrfs snapshot and part of the borg backup.
5 |
6 | The master branch is a combined feature+debugging branch, but I tag releases before doing something experimental.
7 |
8 | At some point I plan split it into a script+config file, because most people prefer to configure once and enable features as they need them, rather than reconfiguring with every new release...
9 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | * ASAP uncapitalise all variables, because CAPS_VARS are for
2 | environmental variables.
3 | * When btrfs-borg is feature-complete, tag 1.0
4 | * Goal: allow separation of configuration from script
5 | - start with upcoming CSV support
6 | - provide example script for populating the CSV?
7 | * Add SSH support (requires borgbackup on server)
8 | - Write HOWTO for server-initiated backup?
9 | > limit available commands for root on $HOST to btrfs-borg
10 | + Would it be better to configure passwordless sudo
11 | for the btrfs-borg command for $HOST's btrfs-borg user?
12 | > create btrfs-borg user on $SERVER with mount permissions
13 | > limit btrfs-borg commands to borg-server
14 | > link to passwordless ssh and borg key-creation HOWTOs
15 | = $SERVER sshes into $HOST, runs btrfs-borg,
16 | and this runs backup and sshes into $SERVER
17 | * More thoroughly test SSH support.
18 | * Store the partition and subvolume layout, ARCHIVEIDS,
19 | and also strong checksums of the generated files as:
20 | `hostname`_partitions_subvolume-layout_ARCHIVEIDS
21 | as a tiny borg-archive?
22 | * Add local backup disk mount/umount support? (or provide example
23 | wrapper script)
24 | - Is udisk really the best way to safely logically disconnect USB disks?
25 | - allow borg-btrfs to manage mount/umount via udisk by defining mount point
26 | !! Leaving it blank means borg-btrfs will not manage the mount !!
27 | !! MUST correspond to a fstab entry with adequate permissions !!
28 | - udisk encrypted device support?
29 | - get $DEVICE: df -h /home/media/usb/$REPO | tail -n1 | \
30 | awk '{print $1}' \
31 | || mount HOW_DO_I_FIND_THE_DEVICE/DIR_TO_MOUNT_IF_IT'S_NOT_MOUNTED?
32 | - sync; sleep 1; sync; udisksctl unmount -b $DEVICE
33 | - sync; sleep 1; sync; udisksctl power-off -b /dev/sdd1
34 | ? Optional generation of comprehensive manifest. eg:
35 | for i in `borg list $BORG_REPO | awk '{print $1}'`; do
36 | borg info $BORG_REPO::$i >> $BORG_REPO/$REPO/btrfs-borg/borg_info_output
37 | done
38 | - Alternatively, submit a request for this functionality upstream
39 | - Is this an information leak? Hmm....probably...
40 | * Shift lots of configuration into new btrfs-borg.csv; adapt the script to read
41 | from this file; allow the location of this config file to be defined
42 | - Include example btrfs-borg.csv
43 | - tail -n +2 ~/btrfs-borg.csv
44 | - while IFS=, read X Y Z rest; do echo "X is $X" "Y is $Y" "Z is $Z";\
45 | done < ~/btrfs-borg.csv
46 | !! PROBLEM !! -> need to somehow strip row 1, eg:
47 | ROOT,SNAPS,SUBS,CONTAINERS
48 | - easiest thing to do is tail -n +2 $CSV-CONFIG > \
49 | $REPO/btrfs-borg/config.csv.tmp
50 | then < REPO/btrfs-borg/config.csv.tmp
51 | !! Don't forget to remove config.csv.tmp in the cleanup !!
52 | * Work for README
53 | - Shift many long inline comments into README.md
54 | - Break things into sections (eg: Introduction, Recommendations,
55 | Configuration)
56 | - Section on backing up LX Containers: a) unprivileged containers are
57 | assumed to not be on their own subvolumes, therefore they are assumed to
58 | be included in a snapshot of a subvolume such as @home. b)
59 | * Clean up LXC snapshots by default
60 | # TODO: We now clean up snapshots by default...
61 | # Make this configurable in the future
62 | # TODO ASAP!!: remove LXC snapshot generated by $0
63 | # something like:
64 | #
65 | #for i in $CONTAINERS; do
66 | # lxc-snapshot -L -n $i
67 | # EXPIRE="`lxc-snapshot -L -n $i | tail -1 | awk '{print $1}'`"
68 | # echo "Removing $EXPIRE"
69 | # lxc-snapshot -n get-transmissions -d $EXPIRE
70 | #done
71 |
72 | * Create knob for btrfs snapshot of LXC containers, without using
73 | lxc-snapshot, which shuts them down. This is desirable for all but
74 | database workloads:
75 | https://www.flockport.com/supercharge-lxc-with-btrfs/
76 | - Alternatively, treat LXC containers as regular subvols by default
77 | * This means using btrfs sub list to automatically find them
78 | * If an absolute path is given, then check to see if it's an LXC
79 | and if it is a container, then run lxc-stop and lxc-snapshot
80 | * Add optional support for backing up multiple hosts to the same repo
81 | ...which means more efficient deduplication!
82 | - Gabor's suggestion :-)
83 | - Needs to automatically uniquely name backups
84 | Is `hostname` sufficient?
85 | - Needs to pass the unique identifier to borg prune, using the
86 | prefix parameter, so that the backups of each host are pruned
87 | (backups for host) instead of (backups for host1 and host2 and
88 | etc.)
89 | * Make location of ARCHIVEIDS configurable
90 | - alternatively, use the "--prefix" feature to store ARCHIVEIDS
91 | within the borg REPO and prevent them from being pruned... This prevents
92 | information leaks, but I'm not sure if it's sufficiently secure...
93 | * Related to the comma separated list and --prefix:
94 | - maybe I should do it as follows...
95 | 1) automatically prefix hostname 2) comma separated list for
96 | "backup unit" which becomes a particular "borg archive" 3)
97 | The backup unit must have the following elements:
98 | - ROOT volume
99 | - Directory: check to see if it's a btrfs subvol, otherwise make
100 | it an "OTHERS"
101 | - This SIMPLIFIES things for the user, because he/she no longer
102 | has to worry about SRC data types! ;-)
103 | 4) Pruning needs to be adapted to operate on these new backup
104 | 5) Iterate through all of the backup units
105 | 6) Accept a backup unit as the sole command line argument?
106 | - This idea enables multiple ageing tiers for backups, and multiple
107 | btrfs volumes. This functionality might come later...but it
108 | will immediately allow the sysadmin to recover hard drive space
109 | by "early retirement" of a backup unit that does not require as fine
110 | grained history as another backup unit. eg: @work-in-progress
111 | needs to always have an up-to-date backup, and X days of backups,
112 | but probably does not need months or years...it just takes up
113 | extra space, and @work-portfolio is what is important in the long-term.
114 | > eg: BACKUP-UNIT="/btrfs-admin/Red,@home var/lib/lxc/my_container"
115 | - test for data type with "btrfs sub show $ROOT/$SUBVOL" and check
116 | value of $? for each unit of the second element. If true
117 | append to $SUBS, otherwise append to $OTHERS
118 | - Backup units are important...OS data from multiple hosts might
119 | not matter that much, so multiple hosts can share the same
120 | repository. It is also advantageous to centralise backups of
121 | containers from multiple container servers. On the other hand,
122 | I think that it is probably just going to slow things down if
123 | deduplication of user data from host A is attempted against user
124 | data from host B.
125 | > Or should "backup units" include target disk?
126 | eg: BACKUP-UNIT="/Red,@home var/lib/lxc/my_container,[user@host:]/dest/mountpoint,[user@host:]/borg/repo"
127 | * Make /borg/repo variable relative to /dest/mountpoint! (see section
128 | on udisk mounting) By default, if BACKUP-UNIT is passed as a
129 | command line argument, do not unmount without explicit
130 | authorisation...needs another command line argument.
131 | The config-file.csv method makes one borg archive per line, and
132 | unmounts after the backup of the last line completes.
133 | * A cleanup is due!
134 | * Centralise documentation to an .asciidoc and use this to generate a manpage.
135 | * Support backing up LX containers with wildcards?
136 | eg: find the rootfs of all /var/lib/lxc/* /home/webdev0/* /home/webdev1/*
137 | get basename for each container
138 | snapshot them under /$ROOT/snapshots/LXC-$BN-rootfs
139 | come up with a special archive naming scheme?
140 | - /var/lib/lxc/* -> "$ARCHIVE_NAME lib_LXCs"
141 | - /home/webdev0/* -> "$ARCHIVE_NAME webdev0_LXCs"
142 | * Alternatively, provide a script to populate a .CSV with all
143 | containers found under a path.
144 | * Allow BACKUP-SRCS, or BACKUP-UNITS to point to a .csv file.
145 | The idea is to make basic configuration as easy as possible.
146 | Pre-populated value should be two lines: one for @ and one for
147 | @home. Write an example config for OpenSuSE users?
148 | * BORG-REPO needs to be part of BACKUP-UNIT
149 |
--------------------------------------------------------------------------------
/btrfs-borg:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # btrfs-borg makes and backs up a list of btrfs snapshotted subvolumes using
4 | # Borg. It supports a list of other (probably) non-btrfs directory sources,
5 | # and 1 second granularity of backups.
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public
9 | # License v2 as published by the Free Software Foundation.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | # General Public License for more details.
15 | #
16 | # Copyright (C) 2016 Nicholas D Steeves
17 | #
18 | # Requires: "install" (usually from coreutils), btrfs-progs, borg
19 | # Optional: lxc (for now...plan to remove it later), ssh
20 |
21 | ROOT='/btrfs-admin' # Mountpoint for the whole volume
22 | # Btrfs-borg is designed to operate on named subvolumes.
23 | # If you do not already have this directory, create it
24 | # like this:
25 | # install -d -m 700 /btrfs-admin
26 | # Then, for Ubuntu do this to /etc/fstab:
27 | # / was on /dev/sda1 during installation
28 | #UUID=0x000000-0000-0000-0000-000000000000 / btrfs defaults,subvol=@ 0 1
29 | # /\ duplicate this line, then the mountpoint and remove the subvol argument
30 | #UUID=0x000000-0000-0000-0000-000000000000 /btrfs-admin btrfs defaults 0 1
31 |
32 | SNAPS='snapshots' # $SNAPS is relative to $ROOT. eg: /btrfs-admin/snapshots
33 | # On my system it is a normal directory used to centralise
34 | # snapshots.
35 |
36 | SUBS='@home rootfs' # $SUBS are also relative to $ROOT. Use @home and @ for
37 | # Ubuntu, and use home and rootfs for Fedora.
38 | # Back up user data before system data, just in case.
39 |
40 | LXCDIR='/var/lib/lxc'
41 | CONTAINERS='my-LXC-container my-other-LXC-container'
42 |
43 | # If you have LXC containers on btrfs subvolumes beneath $ROOT,
44 | # that are managed by LXC's btrfs backend, then list them here in
45 | # the same format you would pass to lxc-stop -n $CONTAINER-NAME.
46 | # Please insure that they can be safely stopped without data loss,
47 | # because at this point in time (2016-11-12) LXC 2.x containers
48 | # need to be stopped before they can be snapshotted. Leave empty
49 | # to skip LXC container backup. If you leave it empty and your
50 | # LXC containers are somewhere inside one of the $SUBS then the
51 | # containers will be backed up without stopping them.
52 | # If your LXC containers are on their own subvolumes, but are not
53 | # listed here, and their subvolumes are not listed in SUBS,
54 | # they will not be backed up!
55 |
56 | # TODO! Contact someone who is intimately familiar with LXC+btrfs
57 | # and get his/her opinion on the best way to backup LXC containers
58 | # with btrfs backend. eg: lxc snapshot vs directly using btrfs snapshot
59 |
60 | REPO='/media/usb/Cuboid_Borg'
61 | #REPO='user@host:/path/to/borg/repo' # example for ssh-connected repo
62 |
63 | COMP='lz4' # see borg(1) section on -C COMPRESSION
64 |
65 | # If you don't use btrfs on /; useful backups need both /var & /etc
66 | # Please note that databases in /var won't be consistent unless you freeze
67 | # or snapshot them somehow
68 | OTHERS='' # If your /boot is on a separate partition, /boot needs to
69 | # be in the list of $OTHERS, or your backup won't be able
70 | # to restore a bootable system! It might also be a good
71 | # idea to backup the UEFI ESP ;-)
72 |
73 | # TODO: test if each $OTHERS is an empty directory, and try mounting it if
74 | # it is?
75 |
76 | # Comment out any of the following time periods to disable
77 | #HOURLY=24 # Disable hourly, because I backup once or twice a week
78 | DAILY=7
79 | WEEKLY=4
80 | MONTHLY=12
81 | YEARLY=5
82 | # Configure verbosity for various borg subcommands.
83 | BVERBO='--info' # See borg(1) for details.
84 | ARCHIVEIDS='' # Set to non-null to create copies of the output of
85 | # borg-list for each invocation of btrfs-borg
86 | # - used to mitigate against attacks such as the
87 | # "Pre-1.0.9 manifest spoofing vulnerability".
88 | # Please note that this will expose the output of borg-list
89 | # To any user who has root access to the drive where this
90 | # file is stored.
91 |
92 | # On my system, these are subvolumes that won't be backed up;
93 | # however, I'd like to keep a list of their contents.
94 | # Make sure that the manifests are put on a subvolume that will be backed up.
95 | echo "Manifests have not been configured, please edit $0"
96 | #cd /usr/src && find > /home/backups/src.manifest
97 | #cd /home/triage && find > /home/backups/triage.manifest
98 | #echo "Building manifests"
99 |
100 | # Uncomment this to exclude from the backup directories that
101 | # contain a file named CACHEDIR.TAG; these can be created like this:
102 | # touch /home/*/.cache/CACHEDIR.TAG
103 |
104 | # EXTRAARGS='--exclude-caches'
105 |
106 |
107 | ##############################################################################
108 | ####################### Configurable portion ends here #######################
109 | ##############################################################################
110 | export ROOT
111 | COMMAND="`basename $0`"
112 |
113 | # Seconds since epoch will allow you to make backups just about
114 | # as often as possible, unless you theoretically have a *really*
115 | # fast system and *really* fast disks, and no changed files
116 | # I chose not to use a format like 2016-01-12-17:03:09
117 | # because borg list already outputs this format in the right-hand
118 | # column, and someone might find machine-readable date stamps useful
119 | # for his/her custom pruning script. P.S. seconds since epoch is cool ;-)
120 | # Additionally, some filesystems don't handle the colon ":" very well
121 | # Finally, it's shorter than the ISO format (date, time, timezone) yet provides
122 | # the same information. eg:
123 | # 2017-02-05T14:41:19-0500 vs
124 | # 1486323679
125 | export DATE=`date +%s`
126 |
127 | # Sanity checks
128 | # Beginning with requirements
129 | if [ "`id -u`" -ne 0 ]; then
130 | cat </dev/null 2>&1
147 | if [ $? -ne 0 ]; then
148 | echo "$c not found"
149 | NOTFOUND=1
150 | fi
151 | done
152 | if [ -z ${NOTFOUND+x} ]; then
153 | echo -n "Proceed? "
154 | read choice
155 | case "$choice" in
156 | yes | y | Yes | YES )
157 | echo "Here be dragons..."
158 | break
159 | ;;
160 | no | n | No | NO )
161 | echo "Exiting"
162 | exit 1
163 | ;;
164 | * )
165 | printf "Please answer yes or no\n\n"
166 | ;;
167 | esac
168 | fi
169 |
170 | # Other sanity checks
171 | if [ -d $ROOT/$SNAPS ]; then
172 | cd $ROOT/$SNAPS
173 | for i in $SUBS; do
174 | if [ -d $i ]; then
175 | AGE=`stat -c %Y $i`
176 | echo "Moving existing snapshot of $i out of the way to $i@$AGE"
177 | mv $i $i@$AGE
178 | fi
179 | sync
180 | btrfs sub sync $ROOT
181 | sync
182 | done
183 | else
184 | echo "$ROOT/$SNAPS not found! $COMMAND cannot continue."
185 | echo "Please mkdir $ROOT/$SNAPS and try again"
186 | exit 1
187 | fi
188 |
189 | REMUSER=`echo $REPO | cut -d@ -f1`
190 | REMHOST=`echo $REPO | cut -d@ -f2 | cut -d: -f1`
191 | REMREPO=`echo $REPO | cut -d: -f2`
192 |
193 | if [ -n "$REMUSER" ] && [ -n "$REMHOST" ] && [ -n "$REMREPO" ]; then
194 | ssh $REMUSER@$REMHOST "test -e $REMREPO/config"
195 | elif [ ! -f $REPO/config ]; then
196 | false
197 | fi
198 | if [ $? -ne 0 ]; then
199 | cat <&3) 3>&2 2> $STATS
282 | echo -n "Cleanup took "
283 | cat $STATS
284 | echo
285 |
286 | unset PRUNE
287 | if [ -n "$HOURLY" ]; then PRUNE="-H $HOURLY"; fi
288 | if [ -n "$DAILY" ]; then PRUNE="$PRUNE -d $DAILY"; fi
289 | if [ -n "$WEEKLY" ]; then PRUNE="$PRUNE -w $WEEKLY"; fi
290 | if [ -n "$MONTHLY" ]; then PRUNE="$PRUNE -m $MONTHLY"; fi
291 | if [ -n "$YEARLY" ]; then PRUNE="$PRUNE -y $YEARLY"; fi
292 | if [ -n "$PRUNE" ]; then
293 | echo "Initiating pruning. Please do not be alarmed if this takes forever"
294 | (time borg prune $BVERBO --stats $PRUNE $REPO 2>&3) \
295 | 3>&2 2> $STATS
296 | echo -n "Pruning took "
297 | cat $STATS
298 | echo
299 | rm $STATS
300 | fi
301 | BASE=`basename $ROOT`
302 | # Bundle stuff that will make restoring from backup easier
303 | if [ -n "$REMUSER" ] && [ -n "$REMHOST" ] && [ -n "$REMREPO" ]; then
304 | ssh $REMUSER@$REMHOST "install -d -m 700 $REMREPO/btrfs-borg"
305 | if [ -z ${ARCHIVEIDS+x} ]; then
306 | borg list $REPO > $HOME/borg-list.$DATE
307 | chmod 400 $HOME/borg-list.$DATE
308 | # Add immutable ACL to $COMMAND-list.$DATE?
309 | scp $HOME/borg-list.$DATE \
310 | $REMUSER@$REMHOST:$REMREPO/btrfs-borg/borg-list.$DATE && \
311 | rm $HOME/borg-list.$DATE
312 | fi
313 | ssh $REMUSER@$REMHOST "test -e $REMREPO/btrfs-borg/$COMMAND"
314 | if [ $? -eq 0 ]; then
315 | ssh $REMUSER@$REMHOST "mv $REMREPO/btrfs-borg/$COMMAND $REMREPO/btrfs-borg/$COMMAND.old"
316 | fi
317 | install -m 500 "$0" $HOME/"$COMMAND.${DATE}" && \
318 | scp $HOME/$COMMAND.$DATE \
319 | $REMUSER@$REMHOST:$REMREPO/btrfs-borg/$COMMAND && \
320 | rm $HOME/"$COMMAND.${DATE}"
321 | # \/ TODO \/
322 | #install -d -m 400 $BTRFS-BORG.CSV $REPO/btrfs-borg/$BTRFS-BORG.CSV
323 | # TODO: make this iterate for multiple ROOTS
324 | btrfs sub list $ROOT | ssh $REMUSER@$REMHOST "cat > $REMREPO/btrfs-borg/subvolumes_of_$BASE"
325 | else
326 | # Bundle stuff that will make restoring from backup easier
327 | mkdir -p $REPO/btrfs-borg && chown 700 $REPO/btrfs-borg
328 | if [ -f $REPO/btrfs-borg/$COMMAND ]; then
329 | mv $REPO/btrfs-borg/$COMMAND $REPO/btrfs-borg/$COMMAND.old
330 | fi
331 | install -d -m 500 "$0" $REPO/btrfs-borg/$COMMAND
332 | if [ -z ${ARCHIVEIDS+x} ]; then
333 | borg list $REPO > $REPO/btrfs-borg/borg-list.$DATE
334 | chmod 400 $REPO/btrfs-borg/borg-list.$DATE
335 | # Add immutable ACL to $COMMAND-list.$DATE?
336 | fi
337 | # \/ TODO \/
338 | #install -d -m 400 $BTRFS-BORG.CSV $REPO/btrfs-borg/$BTRFS-BORG.CSV
339 | # TODO: make this iterate for multiple ROOTS
340 | btrfs sub list $ROOT > $REPO/btrfs-borg/subvolumes_of_$BASE
341 | fi
342 |
--------------------------------------------------------------------------------
/possible-future-btrfs-borg-config.csv:
--------------------------------------------------------------------------------
1 | Backup unit (optional custom –prefix name for borg archive),Root of Volume,Source objects (subvols or absolute paths),Manifests (optional),Path to Borg repo,Keep within,Keep hourly,Keep daily,Keep weekly,Keep monthly,Keep yearly
2 | hostname_@stuff,/btrfs-admin/Red,@stuff /absolute/path/does/not/need/to/be/under/Red,,/media/usb0/borg_repo,,,,1,4,1
3 | OS_userdata_LXCs,/btrfs-admin/Blue,@ @home /unprivileged/container.name/must/be/under/Blue,,user@host:/path/to/repo/for/hostname,,24,7,4,12,7
4 | ,/btrfs-admin/Black,@scratch /path/to/docker/containers?,/absolute/path,/media/usb1/borg_repo,,,1,1,1,1
5 | System-LXCs,/btrfs-admin/Blue,/var/lib/lxc/my-container0 /var/lib/lxc/my-container1 automatically-find-my-container3,,user@offsite:/path/to/repo/for/LXCs,3m,,,,12,5
6 | ,,,,,,,,,,
7 | "In the absence of a backup unit name, default to a format like `hostname`-`basename $volume_root`-@stuff_@home_container.name-`date +%s`",,,,,,,,,,
8 |
--------------------------------------------------------------------------------