Commit graph

114 commits

Author SHA1 Message Date
Thomas Waldmann
6df21df3f4 Merge branch 'master' into multithreading
Note: although I hopefully fixed all the conflicts,
some tests are quite broken.

Conflicts:
	borg/_chunker.c
	borg/archive.py
	borg/archiver.py
	borg/cache.py
	borg/helpers.py
	borg/testsuite/archiver.py
2016-02-04 20:34:18 +01:00
Thomas Waldmann
4b339f5d69 cosmetic source cleanup (flake8) 2016-01-30 21:32:45 +01:00
TW
49cf25fce7 Merge pull request #615 from ThomasWaldmann/fix-trailing-slashes
use os.path.normpath on repository paths, fixes #606
2016-01-30 20:07:57 +01:00
TW
5d93b6cda9 Merge pull request #613 from ThomasWaldmann/xdg-base-dir-keys
use xdg base dir for keys
2016-01-30 20:02:38 +01:00
Thomas Waldmann
8ec62d5e2e use os.path.normpath on repository paths, fixes #606
this does NOT fix absolute vs. relative path usage,
but as this also deals with remote paths, this can't be done in general.
2016-01-30 00:39:25 +01:00
Thomas Waldmann
7773e632db fix some minor cosmetic code/docs issues 2016-01-30 00:01:13 +01:00
Thomas Waldmann
b8d954e60a use XDG_CONFIG_HOME for borg keys instead of ~/.borg, fixes #515 2016-01-28 22:26:58 +01:00
Thomas Waldmann
3476fffe7d remove deprecated "--compression <number>"
use --compression zlib,<number> instead
in case of 0, you could also use --compression none
2016-01-24 16:04:00 +01:00
Thomas Waldmann
b2dedee3c8 refactor yes(), cleanup env var semantics, fixes #355
refactorings:

- introduced concept of default answer:

if the answer string is in the defaultish sequence, the return value of yes() will be the default.
e.g. if just pressing <enter> when asked on the console or if an empty string or "default" is
in the environment variable for overriding.

if an environment var has an invalid value and no retries are enabled: return default
if retries are enabled, next retry won't use the env var again, but either ask via input().

- simplify:

only one default - this should be a SAFE default as it is used in some special conditions
like EOF or invalid input with retries disallowed.

no isatty() magic, the "yes" shell command exists, so we could receive input even if it is not from a tty.

- clean:

separate retry flag from retry_msg
2016-01-24 16:04:00 +01:00
Thomas Waldmann
9fa18c9ee9 use stat.filemode instead of homegrown code 2016-01-24 15:40:04 +01:00
Thomas Waldmann
ef00f5d12d we always have shutil.get_terminal_size on py 3.3+ 2016-01-24 15:36:04 +01:00
Thomas Waldmann
fc52101d46 suppress unneeded exception context (PEP 409) 2016-01-24 15:36:04 +01:00
Thomas Waldmann
6a5629226f simplify to print(...., flush=True) 2016-01-24 15:16:05 +01:00
Thomas Waldmann
265da6286f remove conditionals/wrappers, we always have stat nanosecond support on 3.4+
also: no wrapper needed for binascii.unhexlify any more
2016-01-24 15:16:05 +01:00
Thomas Waldmann
8a819d4499 remove borg.support, fixes #358
we only needed it because argparse was broken on some 3.2.x and 3.3.x pythons.
2016-01-24 14:57:48 +01:00
Michael Hanselmann
c7fb598ab9 Add shell-style pattern syntax
The fnmatch module in Python's standard library implements a pattern
format for paths which is similar to shell patterns. However, “*”
matches any character including path separators. This newly introduced
pattern syntax with the selector “sh” no longer matches the path
separator with “*”. Instead “**/” can be used to match zero or more
directory levels.
2016-01-21 16:07:24 +01:00
Michael Hanselmann
dad0ba9661 Remove old-style pattern handling functions
Remove the “adjust_pattern” and “exclude_path” functions and replace
them with the recently introduced pattern matcher class.
2016-01-18 21:26:08 +01:00
Michael Hanselmann
848375e2fe Add and document path prefix as pattern style
The “extract” command supports extracting all files underneath a given
set of prefix paths. The forthcoming support for extracting files using
a pattern (i.e. only files ending in “.zip”) requires the introduction
of path prefixes as a third pattern style, making it also available for
exclusions.
2016-01-18 21:26:08 +01:00
Michael Hanselmann
b6362b5963 Flexible default pattern style
A function to parse pattern specifications was introduced in commit
2bafece. Since then it had a hardcoded default style of “fm”, meaning
fnmatch. With the forthcoming support for extracting files using
patterns this default style must be more flexible.
2016-01-18 20:59:09 +01:00
Michael Hanselmann
1fa4d2e516 Use constants for pattern style prefixes
The prefix used for pattern styles should be kept together with the
respective style implementation.
2016-01-18 20:59:08 +01:00
Michael Hanselmann
9747755131 Add pattern matcher wrapper
The utility functions “adjust_patterns” and “exclude_path” produce
respectively use a standard list object containing pattern objects.
With the forthcoming introduction of patterns for filtering files
to be extracted it's better to move the logic of these classes into
a single class.

The wrapper allows adding any number of patterns to an internal list
together with a value to be returned if a match function finds that
one of the patterns matches. A fallback value is returned otherwise.
2016-01-18 20:59:08 +01:00
Michael Hanselmann
3a39ddbd83 Rename pattern classes for consistency
The class names “IncludePattern” and “ExcludePattern” may have been
appropriate when they were the only styles. With the recent addition of
regular expression support and with at least one more style being added
in forthcoming changes these classes should be renamed to be more
descriptive. “ExcludeRegex” is also renamed to match the new names.
2016-01-15 17:16:25 +01:00
TW
89169c3f87 Merge pull request #542 from ThomasWaldmann/fix-stats-logging
log stats consistently, fixes #526
2016-01-14 14:33:53 +01:00
Michael Hanselmann
2369b8a0f2 Strip whitespace when loading exclusions from file
Patterns to exclude files can be loaded from a text file using the
“--exclude-from” option. Whitespace at the beginning or end of lines was
not stripped. Indented comments would be interpreted as a pattern and
a misplaced space at the end of a line--some text editors don't strip
them--could cause an exclusion pattern to not match as desired. With the
recent addition of regular expression support for exclusions the spaces
can be matched if necessary (“^\s” or “\s$”), though it's highly
unlikely that there are many paths deliberately starting or ending with
whitespace.
2016-01-13 17:39:22 +01:00
Michael Hanselmann
2bafece093 Implement exclusions using regular expressions
The existing option to exclude files and directories, “--exclude”, is
implemented using fnmatch[1]. fnmatch matches the slash (“/”) with “*”
and thus makes it impossible to write patterns where a directory with
a given name should be excluded at a specific depth in the directory
hierarchy, but not anywhere else. Consider this structure:

  home/
  home/aaa
  home/aaa/.thumbnails
  home/user
  home/user/img
  home/user/img/.thumbnails

fnmatch incorrectly excludes “home/user/img/.thumbnails” with a pattern
of “home/*/.thumbnails” when the intention is to exclude “.thumbnails”
in all home directories while retaining directories with the same name
in all other locations.

With this change regular expressions are introduced as an additional
pattern syntax. The syntax is selected using a prefix on “--exclude”'s
value. “re:” is for regular expression and “fm:”, the default, selects
fnmatch. Selecting the syntax is necessary when regular expressions are
desired or when the desired fnmatch pattern starts with two alphanumeric
characters followed by a colon (i.e. “aa:something/*”). The exclusion
described above can be implemented as follows:

  --exclude 're:^home/[^/]+/\.thumbnails$'

The “--exclude-from” option permits loading exclusions from a text file
where the same prefixes can now be used, e.g. “re:\.tmp$”.

The documentation has been extended and now not only describes the two
pattern styles, but also the file format supported by “--exclude-from”.

This change has been discussed in issue #43 and in change request #497.

[1] https://docs.python.org/3/library/fnmatch.html

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
2016-01-13 17:39:19 +01:00
Michael Hanselmann
93c9c49250 Reduce code duplication in inclusion/exclusion pattern logic
The two classes for applying inclusion and exclusion patterns contained
unnecessarily duplicated logic. The introduction of a shared base class
allows for easier reuse, especially considering that two more classes
are going to be added in forthcoming changes (regular expressions and
shell-style patterns).
2016-01-13 14:35:59 +01:00
TW
2921b60e69 Merge pull request #539 from ThomasWaldmann/add-version
display borg version below tracebacks, fixes #532
2016-01-12 19:57:41 +01:00
Thomas Waldmann
84672f7081 log stats consistently, fixes #526
prune and create now both require --verbose --stats to show stats.
it was implemented in this way (and not with print) so you can feed the stats data
into the logging system, too.

delete now says "Archive deleted" in verbose mode (for consistency,
it already said "Repository deleted" when deleting a repo).

also: add helpers.log_multi to comfortably and prettily output a block of log lines
2016-01-12 00:41:06 +01:00
Thomas Waldmann
e5c29bd145 add abbreviated weekday to timestamp format, fixes #496 2016-01-11 23:31:24 +01:00
Thomas Waldmann
857f563307 display borg version below tracebacks, fixes #532 2016-01-11 23:22:04 +01:00
Michael Hanselmann
02e04653b6 Factorize and test loading of excludes from file
The parsing code for exclude files (given via `--exclude-from`) was not
tested. Its core is factorized into a separate function to facilitate an
easier test. The observable behaviour is unchanged.
2016-01-11 12:24:26 +01:00
Michael Hanselmann
d668901df4 Fix typo in comment 2016-01-07 11:18:03 +01:00
Thomas Waldmann
c9afa2b27b output progress indication from inner loop, fixes #500
- so it shows progress while it backups a bigger file
- so it announces the filename earlier

also: move rate limiting code to show_progress()
2015-12-27 11:06:03 +01:00
Thomas Waldmann
f59db03c60 ProgressIndicator: flush the output file or it won't work correctly via ssh
likely due to buffering, the progress indication was not visible.
2015-12-12 22:15:08 +01:00
Jakob Schnitzer
17952dff48 helpers: remove functions that are only used once
The read_msgpack and write_msgpack functions were only used in one place
each.  Since msgpack is read and written in lots of places, having
functions with these generic names is confusing. Also, the helpers
module is quite a mess, so reducing its size seems to be a good idea.
2015-12-07 14:29:01 +01:00
Thomas Waldmann
887196b00e progress indicators: better docstring, minor code improvement 2015-12-03 14:14:28 +01:00
Thomas Waldmann
7a1316cb79 implement ProgressIndicators, use it for repo check and segment replay, fixes #195, fixes #188 2015-12-02 01:06:07 +01:00
Thomas Waldmann
adb35ab07f include system info below traceback, fixes #324 2015-11-21 22:51:59 +01:00
Thomas Waldmann
b1ba7a84f0 --keep-tag-files: fix file status, fix multiple tag files in one directory, fixes #432 2015-11-19 20:03:50 +01:00
Thomas Waldmann
2e64c29e01 use ISO-8601 date and time format, fixes #375 2015-11-16 23:51:21 +01:00
Antoine Beaupré
f13dd6e579 completely remove have_cython() hack
this was making us require mock, which is really a test component and
shouldn't be part of the runtime dependencies. furthermore, it was
making the imports and the code more brittle: it may have been
possible that, through an environment variable, backups could be
corrupted because mock libraries would be configured instead of real
once, which is a risk we shouldn't be taking.

finally, this was used only to build docs, which we will build and
commit to git by hand with a fully working borg when relevant.

see #384.
2015-11-13 10:40:53 -05:00
Thomas Waldmann
7d178e09b0 Implement --keep-tag-files to preserve directory roots/tag-files
We also add --keep-tag-files to keep in the archive the root directory and the
tag/exclusion file in the archive.

This is taken from a attic PR (and adapted for borg):
    commit f61e22cacc90e76e6c8f4b23677eee62c09e97ac
    Author: Yuri D'Elia <yuri.delia@eurac.edu>
    Date:   Mon Dec 15 12:27:43 2014 +0100
2015-11-09 04:08:49 +01:00
Thomas Waldmann
a6a8a4ebd9 Implement --exclude-if-present
Add a new --exclude-if-present command-line flag to ``borg create``.  If
specified, directories containing the specified tag file will be excluded from
the backup. The flag can be repeated to ignore more than a single tag file,
irregardless of the contents.

This is taken from a attic PR (and adapted for borg):
    commit 3462a9ca90388dc5d8b4fa4218a32769676b3623
    Author: Yuri D'Elia <yuri.delia@eurac.edu>
    Date:   Sun Dec 7 19:15:17 2014 +0100
2015-11-09 03:41:06 +01:00
Thomas Waldmann
007572594f try to fix build on readthedocs 2015-11-08 02:00:51 +01:00
Thomas Waldmann
c9090fc3c2 helper: minor style fix 2015-11-07 15:37:05 +01:00
Thomas Waldmann
e6231896cd emit a deprecation warning for --compression N
deprecating it in the source is not enough, we also need to tell the users to fix their scripts.
2015-11-02 00:14:01 +01:00
Thomas Waldmann
0a6e6cfe2e refactor confirmation code, reduce code duplication, add tests 2015-11-01 19:18:29 +01:00
TW
5f86959762 Merge pull request #349 from ThomasWaldmann/pretty-errors
prettier error messages, fixes #57
2015-10-31 22:44:04 +01:00
Thomas Waldmann
762fdaadd8 prettier error messages, fixes #57
subclasses of "Error": do not show traceback
(this is used when a failure is expected and has rather trivial reasons and usually
does not need debugging)

subclasses of "ErrorWithTraceback": show a traceback
(this is for severe and rather unexpected stuff, like consistency / corruption issues
or stuff that might need debugging)

I reviewed all the Error subclasses whether they fit into the one or other class.

Also: fixed docstring typo, docstring formatting
2015-10-31 22:23:32 +01:00
Thomas Waldmann
3490469734 emit a warning if we have a slow msgpack installed
the reason for a slow msgpack can be:
- pip install: missing compiler (gcc)
- pip install: missing compiler parts (e.g. gcc-c++)
- pip install: cached wheel package that was built while the compiler wasn't present
- distribution package: badly built msgpack package
2015-10-31 20:37:21 +01:00