]> arthur.barton.de Git - bup.git/blob - README.md
git.PackWriter: assert on no precalculated sha
[bup.git] / README.md
1 bup: It backs things up
2 =======================
3
4 bup is a program that backs things up.  It's short for "backup." Can you
5 believe that nobody else has named an open source program "bup" after all
6 this time?  Me neither.
7
8 Despite its unassuming name, bup is pretty cool.  To give you an idea of
9 just how cool it is, I wrote you this poem:
10
11                              Bup is teh awesome
12                           What rhymes with awesome?
13                             I guess maybe possum
14                            But that's irrelevant.
15                         
16 Hmm.  Did that help?  Maybe prose is more useful after all.
17
18
19 Reasons bup is awesome
20 ----------------------
21
22 bup has a few advantages over other backup software:
23
24  - It uses a rolling checksum algorithm (similar to rsync) to split large
25    files into chunks.  The most useful result of this is you can backup huge
26    virtual machine (VM) disk images, databases, and XML files incrementally,
27    even though they're typically all in one huge file, and not use tons of
28    disk space for multiple versions.
29    
30  - It uses the packfile format from git (the open source version control
31    system), so you can access the stored data even if you don't like bup's
32    user interface.
33    
34  - Unlike git, it writes packfiles *directly* (instead of having a separate
35    garbage collection / repacking stage) so it's fast even with gratuitously
36    huge amounts of data.  bup's improved index formats also allow you to
37    track far more filenames than git (millions) and keep track of far more
38    objects (hundreds or thousands of gigabytes).
39    
40  - Data is "automagically" shared between incremental backups without having
41    to know which backup is based on which other one - even if the backups
42    are made from two different computers that don't even know about each
43    other.  You just tell bup to back stuff up, and it saves only the minimum
44    amount of data needed.
45    
46  - You can back up directly to a remote bup server, without needing tons of
47    temporary disk space on the computer being backed up.  And if your backup
48    is interrupted halfway through, the next run will pick up where you left
49    off.  And it's easy to set up a bup server: just install bup on any
50    machine where you have ssh access.
51    
52  - Bup can use "par2" redundancy to recover corrupted backups even if your
53    disk has undetected bad sectors.
54    
55  - Even when a backup is incremental, you don't have to worry about
56    restoring the full backup, then each of the incrementals in turn; an
57    incremental backup *acts* as if it's a full backup, it just takes less
58    disk space.
59    
60  - You can mount your bup repository as a FUSE filesystem and access the
61    content that way, and even export it over Samba.
62    
63  - It's written in python (with some C parts to make it faster) so it's easy
64    for you to extend and maintain.
65
66
67 Reasons you might want to avoid bup
68 -----------------------------------
69
70  - It's not remotely as well tested as something like tar, so it's
71    more likely to eat your data.  It's also missing some
72    probably-critical features, though fewer than it used to be.
73    
74  - It requires python 3.7 or newer, a C compiler, and an installed git
75    version >= 1.5.6.  It also requires par2 if you want fsck to be
76    able to generate the information needed to recover from some types
77    of corruption.
78  
79  - It currently only works on Linux, FreeBSD, NetBSD, OS X >= 10.4,
80    Solaris, or Windows (with Cygwin, and WSL).  Patches to support
81    other platforms are welcome.
82
83  - Until resolved, a [glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=26034)
84    might cause bup to crash on startup for some (unusual) command line
85    argument values, when bup is configured to use Python 3.
86
87  - Any items in "Things that are stupid" below.
88
89
90 Notable changes introduced by a release
91 =======================================
92
93  - <a href="note/0.32-from-0.31.md">Changes in 0.32 as compared to 0.31</a>
94  - <a href="note/0.31-from-0.30.1.md">Changes in 0.31 as compared to 0.30.1</a>
95  - <a href="note/0.30.1-from-0.30.md">Changes in 0.30.1 as compared to 0.30</a>
96  - <a href="note/0.30-from-0.29.3.md">Changes in 0.30 as compared to 0.29.3</a>
97  - <a href="note/0.29.3-from-0.29.2.md">Changes in 0.29.3 as compared to 0.29.2</a>
98  - <a href="note/0.29.2-from-0.29.1.md">Changes in 0.29.2 as compared to 0.29.1</a>
99  - <a href="note/0.29.1-from-0.29.md">Changes in 0.29.1 as compared to 0.29</a>
100  - <a href="note/0.29-from-0.28.1.md">Changes in 0.29 as compared to 0.28.1</a>
101  - <a href="note/0.28.1-from-0.28.md">Changes in 0.28.1 as compared to 0.28</a>
102  - <a href="note/0.28-from-0.27.1.md">Changes in 0.28 as compared to 0.27.1</a>
103  - <a href="note/0.27.1-from-0.27.md">Changes in 0.27.1 as compared to 0.27</a>
104
105
106 Test status
107 ===========
108
109 | master | 0.30.x | 0.29.x |
110 |--------|--------|--------|
111 | [![master branch test status](https://api.cirrus-ci.com/github/bup/bup.svg?branch=master)](https://cirrus-ci.com/github/bup/bup) | [![0.30 branch test status](https://api.cirrus-ci.com/github/bup/bup.svg?branch=0.30.x)](https://cirrus-ci.com/github/bup/bup) | [![0.29 branch test status](https://api.cirrus-ci.com/github/bup/bup.svg?branch=0.29.x)](https://cirrus-ci.com/github/bup/bup) |
112
113 Getting started
114 ===============
115
116 From source
117 -----------
118
119  - Check out the bup source code using git:
120
121     ```sh
122     git clone https://github.com/bup/bup
123     ```
124
125  - This will leave you on the master branch, which is perfect if you
126    would like to help with development, but if you'd just like to use
127    bup, please check out the latest stable release like this:
128
129     ```sh
130     git checkout 0.32
131     ```
132
133    You can see the latest stable release here:
134    https://github.com/bup/bup/releases.
135
136  - Install the required python libraries (including the development
137    libraries).
138
139    On very recent Debian/Ubuntu versions, this may be sufficient (run
140    as root):
141
142     ```sh
143     apt-get build-dep bup
144     ```
145
146    Otherwise try this:
147
148     ```sh
149     apt-get install python3.7-dev python3-fuse
150     apt-get install python3-pyxattr python3-pytest
151     apt-get install python3-distutils
152     apt-get install pkg-config linux-libc-dev libacl1-dev
153     apt-get install gcc make acl attr rsync
154     apt-get isntall python3-pytest-xdist # optional (parallel tests)
155     apt-get install par2 # optional (error correction)
156     apt-get install libreadline-dev # optional (bup ftp)
157     apt-get install python3-tornado # optional (bup web)
158
159     ```
160
161    On Cygwin, install python, make, rsync, and gcc4.
162
163    If you would like to use the optional bup web server on systems
164    without a tornado package, you may want to try this:
165
166     ```sh
167     pip install tornado
168     ```
169
170  - Build:
171
172     ```sh
173     make
174     ```
175         
176  - Run the tests:
177
178     ```sh
179     make long-check
180     ```
181
182     or if you're in a bit more of a hurry:
183
184     ```sh
185     make check
186     ```
187         
188     If you have the Python xdist module installed, then you can
189     probably run the tests faster by adding the make -j option (see <a
190     href="HACKING">./HACKING</a> for additional information):
191
192     ```sh
193     make -j check
194     ```
195
196     The tests should pass.  If they don't pass for you, stop here and
197     send an email to bup-list@googlegroups.com.  Though if there are
198     symbolic links along the current working directory path, the tests
199     may fail.  Running something like this before "make test" should
200     sidestep the problem:
201
202     ```sh
203     cd "$(pwd -P)"
204     ```
205
206  - You can install bup via "make install", and override the default
207    destination with DESTDIR and PREFIX.
208
209    Files are normally installed to "$DESTDIR/$PREFIX" where DESTDIR is
210    empty by default, and PREFIX is set to /usr/local.  So if you wanted to
211    install bup to /opt/bup, you might do something like this:
212
213     ```sh
214     make install DESTDIR=/opt/bup PREFIX=''
215     ```
216
217  - The Python version that bup will use is determined by the
218    `python-config` program chosen by `./configure`, which will search
219    for a reasonable version unless `BUP_PYTHON_CONFIG` is set in the
220    environment.  You can see which Python executable was chosen by
221    looking at the configure output, or examining
222    `config/config.var/bup-python-config`, and you can change the
223    selection by re-running `./configure`.
224
225 - If you want to specify your own `CPPFLAGS`, `CFLAGS`, or `LDFLAGS`,
226   you can set them for individual `make` invocations, e.g. `make
227   CFLAGS=-O0 check`, or persistently via `./configure` with
228   `CFLAGS=-O0 ./configure`.  At the moment, `make clean` clears the
229   configuration, but we may change that at some point, perhaps by
230   adding and requiring a `make distclean` to clear the configuration.
231
232 From binary packages
233 --------------------
234
235 Binary packages of bup are known to be built for the following OSes:
236
237  - Debian:
238     http://packages.debian.org/search?searchon=names&keywords=bup
239  - Ubuntu:
240     http://packages.ubuntu.com/search?searchon=names&keywords=bup
241  - pkgsrc (NetBSD, Dragonfly, and others)
242     http://pkgsrc.se/sysutils/bup
243     http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/sysutils/bup/
244  - Arch Linux:
245     https://www.archlinux.org/packages/?sort=&q=bup
246  - Fedora:
247     https://apps.fedoraproject.org/packages/bup
248  - macOS (Homebrew):
249     https://formulae.brew.sh/formula/bup
250
251
252 Using bup
253 ---------
254
255  - Get help for any bup command:
256
257     ```sh
258     bup help
259     bup help init
260     bup help index
261     bup help save
262     bup help restore
263     ...
264     ```
265
266  - Initialize the default BUP_DIR (~/.bup -- you can choose another by
267    either specifying `bup -d DIR ...` or setting the `BUP_DIR`
268    environment variable for a command):
269
270     ```sh
271     bup init
272     ```
273
274  - Make a local backup (-v or -vv will increase the verbosity):
275
276     ```sh
277     bup index /etc
278     bup save -n local-etc /etc
279     ```
280
281  - Restore a local backup to ./dest:
282
283     ```sh
284     bup restore -C ./dest local-etc/latest/etc
285     ls -l dest/etc
286     ```
287
288  - Look at how much disk space your backup took:
289
290     ```sh
291     du -s ~/.bup
292     ```
293
294  - Make another backup (which should be mostly identical to the last one;
295    notice that you don't have to *specify* that this backup is incremental,
296    it just saves space automatically):
297
298     ```sh
299     bup index /etc
300     bup save -n local-etc /etc
301     ```
302
303  - Look how little extra space your second backup used (on top of the first):
304
305     ```sh
306     du -s ~/.bup
307     ```
308
309  - Get a list of your previous backups:
310
311     ```sh
312     bup ls local-etc
313     ```
314
315  - Restore your first backup again:
316
317     ```sh
318     bup restore -C ./dest-2 local-etc/2013-11-23-11195/etc
319     ```
320
321  - Make a backup to a remote server which must already have the 'bup' command
322    somewhere in its PATH (see /etc/profile, etc/environment, ~/.profile, or
323    ~/.bashrc), and be accessible via ssh.
324    Make sure to replace SERVERNAME with the actual hostname of your server:
325
326     ```sh
327     bup init -r SERVERNAME:path/to/remote-bup-dir
328     bup index /etc
329     bup save -r SERVERNAME:path/to/remote-bup-dir -n local-etc /etc
330     ```
331
332  - Make a remote backup to ~/.bup on SERVER:
333
334     ```sh
335     bup index /etc
336     bup save -r SERVER: -n local-etc /etc
337     ```
338
339  - See what saves are available in ~/.bup on SERVER:
340
341     ```sh
342     bup ls -r SERVER:
343     ```
344
345  - Restore the remote backup to ./dest:
346
347     ```sh
348     bup restore -r SERVER: -C ./dest local-etc/latest/etc
349     ls -l dest/etc
350     ```
351
352  - Defend your backups from death rays (OK fine, more likely from the
353    occasional bad disk block).  This writes parity information
354    (currently via par2) for all of the existing data so that bup may
355    be able to recover from some amount of repository corruption:
356
357     ```sh
358     bup fsck -g
359     ```
360
361  - Use split/join instead of index/save/restore.  Try making a local
362    backup using tar:
363
364     ```sh
365     tar -cvf - /etc | bup split -n local-etc -vv
366     ```
367         
368  - Try restoring the tarball:
369
370     ```sh
371     bup join local-etc | tar -tf -
372     ```
373         
374  - Look at how much disk space your backup took:
375
376     ```sh
377     du -s ~/.bup
378     ```
379         
380  - Make another tar backup:
381
382     ```sh
383     tar -cvf - /etc | bup split -n local-etc -vv
384     ```
385         
386  - Look at how little extra space your second backup used on top of
387    the first:
388
389     ```sh
390     du -s ~/.bup
391     ```
392         
393  - Restore the first tar backup again (the ~1 is git notation for "one
394    older than the most recent"):
395
396     ```sh
397     bup join local-etc~1 | tar -tf -
398     ```
399  
400  - Get a list of your previous split-based backups:
401
402     ```sh
403     GIT_DIR=~/.bup git log local-etc
404     ```
405         
406  - Save a tar archive to a remote server (without tar -z to facilitate
407    deduplication):
408
409     ```sh
410     tar -cvf - /etc | bup split -r SERVERNAME: -n local-etc -vv
411     ```
412  
413  - Restore the archive:
414
415     ```sh
416     bup join -r SERVERNAME: local-etc | tar -tf -
417     ```
418         
419 That's all there is to it!
420
421
422 Notes on FreeBSD
423 ----------------
424
425 - FreeBSD's default 'make' command doesn't like bup's Makefile. In order to
426   compile the code, run tests and install bup, you need to install GNU Make
427   from the port named 'gmake' and use its executable instead in the commands
428   seen above. (i.e. 'gmake test' runs bup's test suite)
429
430 - Python's development headers are automatically installed with the 'python'
431   port so there's no need to install them separately.
432
433 - To use the 'bup fuse' command, you need to install the fuse kernel module
434   from the 'fusefs-kmod' port in the 'sysutils' section and the libraries from
435   the port named 'py-fusefs' in the 'devel' section.
436
437 - The 'par2' command can be found in the port named 'par2cmdline'.
438
439 - In order to compile the documentation, you need pandoc which can be found in
440   the port named 'hs-pandoc' in the 'textproc' section.
441
442
443 Notes on NetBSD/pkgsrc
444 ----------------------
445
446  - See pkgsrc/sysutils/bup, which should be the most recent stable
447    release and includes man pages.  It also has a reasonable set of
448    dependencies (git, par2, py-fuse-bindings).
449
450  - The "fuse-python" package referred to is hard to locate, and is a
451    separate tarball for the python language binding distributed by the
452    fuse project on sourceforge.  It is available as
453    pkgsrc/filesystems/py-fuse-bindings and on NetBSD 5, "bup fuse"
454    works with it.
455
456  - "bup fuse" presents every directory/file as inode 0.  The directory
457    traversal code ("fts") in NetBSD's libc will interpret this as a
458    cycle and error out, so "ls -R" and "find" will not work.
459
460  - There is no support for ACLs.  If/when some enterprising person
461    fixes this, adjust dev/compare-trees.
462
463
464 Notes on Cygwin
465 ---------------
466
467  - There is no support for ACLs.  If/when some enterprising person
468    fixes this, adjust dev/compare-trees.
469
470  - In test/ext/test-misc, two tests have been disabled.  These tests
471    check to see that repeated saves produce identical trees and that
472    an intervening index doesn't change the SHA1.  Apparently Cygwin
473    has some unusual behaviors with respect to access times (that
474    probably warrant further investigation).  Possibly related:
475    http://cygwin.com/ml/cygwin/2007-06/msg00436.html
476
477
478 Notes on OS X
479 -------------
480
481  - There is no support for ACLs.  If/when some enterprising person
482    fixes this, adjust dev/compare-trees.
483
484
485 How it works
486 ============
487
488 Basic storage:
489 --------------
490
491 bup stores its data in a git-formatted repository.  Unfortunately, git
492 itself doesn't actually behave very well for bup's use case (huge numbers of
493 files, files with huge sizes, retaining file permissions/ownership are
494 important), so we mostly don't use git's *code* except for a few helper
495 programs.  For example, bup has its own git packfile writer written in
496 python.
497
498 Basically, 'bup split' reads the data on stdin (or from files specified on
499 the command line), breaks it into chunks using a rolling checksum (similar to
500 rsync), and saves those chunks into a new git packfile.  There is at least one
501 git packfile per backup.
502
503 When deciding whether to write a particular chunk into the new packfile, bup
504 first checks all the other packfiles that exist to see if they already have that
505 chunk.  If they do, the chunk is skipped.
506
507 git packs come in two parts: the pack itself (*.pack) and the index (*.idx).
508 The index is pretty small, and contains a list of all the objects in the
509 pack.  Thus, when generating a remote backup, we don't have to have a copy
510 of the packfiles from the remote server: the local end just downloads a copy
511 of the server's *index* files, and compares objects against those when
512 generating the new pack, which it sends directly to the server.
513
514 The "-n" option to 'bup split' and 'bup save' is the name of the backup you
515 want to create, but it's actually implemented as a git branch.  So you can
516 do cute things like checkout a particular branch using git, and receive a
517 bunch of chunk files corresponding to the file you split.
518
519 If you use '-b' or '-t' or '-c' instead of '-n', bup split will output a
520 list of blobs, a tree containing that list of blobs, or a commit containing
521 that tree, respectively, to stdout.  You can use this to construct your own
522 scripts that do something with those values.
523
524 The bup index:
525 --------------
526
527 'bup index' walks through your filesystem and updates a file (whose name is,
528 by default, ~/.bup/bupindex) to contain the name, attributes, and an
529 optional git SHA1 (blob id) of each file and directory.
530
531 'bup save' basically just runs the equivalent of 'bup split' a whole bunch
532 of times, once per file in the index, and assembles a git tree
533 that contains all the resulting objects.  Among other things, that makes
534 'git diff' much more useful (compared to splitting a tarball, which is
535 essentially a big binary blob).  However, since bup splits large files into
536 smaller chunks, the resulting tree structure doesn't *exactly* correspond to
537 what git itself would have stored.  Also, the tree format used by 'bup save'
538 will probably change in the future to support storing file ownership, more
539 complex file permissions, and so on.
540
541 If a file has previously been written by 'bup save', then its git blob/tree
542 id is stored in the index.  This lets 'bup save' avoid reading that file to
543 produce future incremental backups, which means it can go *very* fast unless
544 a lot of files have changed.
545
546  
547 Things that are stupid for now but which we'll fix later
548 ========================================================
549
550 Help with any of these problems, or others, is very welcome.  Join the
551 mailing list (see below) if you'd like to help.
552
553  - 'bup save' and 'bup restore' have immature metadata support.
554  
555     On the plus side, they actually do have support now, but it's new,
556     and not remotely as well tested as tar/rsync/whatever's.  However,
557     you have to start somewhere, and as of 0.25, we think it's ready
558     for more general use.  Please let us know if you have any trouble.
559
560     Also, if any strip or graft-style options are specified to 'bup
561     save', then no metadata will be written for the root directory.
562     That's obviously less than ideal.
563
564  - bup is overly optimistic about mmap.  Right now bup just assumes
565    that it can mmap as large a block as it likes, and that mmap will
566    never fail.  Yeah, right... If nothing else, this has failed on
567    32-bit architectures (and 31-bit is even worse -- looking at you,
568    s390).
569
570    To fix this, we might just implement a FakeMmap[1] class that uses
571    normal file IO and handles all of the mmap methods[2] that bup
572    actually calls.  Then we'd swap in one of those whenever mmap
573    fails.
574
575    This would also require implementing some of the methods needed to
576    support "[]" array access, probably at a minimum __getitem__,
577    __setitem__, and __setslice__ [3].
578
579      [1] http://comments.gmane.org/gmane.comp.sysutils.backup.bup/613
580      [2] http://docs.python.org/3/library/mmap.html
581      [3] http://docs.python.org/3/reference/datamodel.html#emulating-container-types
582
583  - 'bup index' is slower than it should be.
584  
585     It's still rather fast: it can iterate through all the filenames on my
586     600,000 file filesystem in a few seconds.  But it still needs to rewrite
587     the entire index file just to add a single filename, which is pretty
588     nasty; it should just leave the new files in a second "extra index" file
589     or something.
590    
591  - bup could use inotify for *really* efficient incremental backups.
592
593     You could even have your system doing "continuous" backups: whenever a
594     file changes, we immediately send an image of it to the server.  We could
595     give the continuous-backup process a really low CPU and I/O priority so
596     you wouldn't even know it was running.
597
598  - bup only has experimental support for pruning old backups.
599
600    While you should now be able to drop old saves and branches with
601    `bup rm`, and reclaim the space occupied by data that's no longer
602    needed by other backups with `bup gc`, these commands are
603    experimental, and should be handled with great care.  See the
604    man pages for more information.
605
606    Unless you want to help test the new commands, one possible
607    workaround is to just start a new BUP_DIR occasionally,
608    i.e. bup-2013, bup-2014...
609
610  - bup has never been tested on anything but Linux, FreeBSD, NetBSD,
611    OS X, and Windows+Cygwin.
612  
613     There's nothing that makes it *inherently* non-portable, though, so
614     that's mostly a matter of someone putting in some effort.  (For a
615     "native" Windows port, the most annoying thing is the absence of ssh in
616     a default Windows installation.)
617     
618  - bup needs better documentation.
619  
620     According to an article about bup in Linux Weekly News
621     (https://lwn.net/Articles/380983/), "it's a bit short on examples and
622     a user guide would be nice."  Documentation is the sort of thing that
623     will never be great unless someone from outside contributes it (since
624     the developers can never remember which parts are hard to understand).
625     
626  - bup is "relatively speedy" and has "pretty good" compression.
627  
628     ...according to the same LWN article.  Clearly neither of those is good
629     enough.  We should have awe-inspiring speed and crazy-good compression. 
630     Must work on that.  Writing more parts in C might help with the speed.
631    
632  - bup has no GUI.
633  
634    Actually, that's not stupid, but you might consider it a
635    limitation.  See the ["Related Projects"](https://bup.github.io/)
636    list for some possible options.
637     
638 More Documentation
639 ==================
640
641 bup has an extensive set of man pages.  Try using 'bup help' to get
642 started, or use 'bup help SUBCOMMAND' for any bup subcommand (like split,
643 join, index, save, etc.) to get details on that command.
644
645 For further technical details, please see ./DESIGN.
646
647
648 How you can help
649 ================
650
651 bup is a work in progress and there are many ways it can still be improved.
652 If you'd like to contribute patches, ideas, or bug reports, please join the
653 <a href="mailto:bup-list@googlegroups.com">bup mailing list</a>:
654
655 You can find the mailing list archives here:
656
657         http://groups.google.com/group/bup-list
658         
659 and you can subscribe by sending a message to:
660
661         bup-list+subscribe@googlegroups.com
662
663 You can also reach us via the
664 \#bup IRC channel at ircs://irc.libera.chat:6697/bup
665 on the [libera.chat](https://libera.chat/) network or via this
666 [web interface](https://web.libera.chat/?channels=bup).
667
668 Please see <a href="HACKING">./HACKING</a> for
669 additional information, i.e. how to submit patches (hint - no pull
670 requests), how we handle branches, etc.
671
672
673 Have fun,
674
675 Avery
676
677 <!--
678 Local Variables:
679 mode: markdown
680 End:
681 -->