Commit graph

62 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
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
fc52101d46 suppress unneeded exception context (PEP 409) 2016-01-24 15:36:04 +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
TW
1878e223d6 Merge pull request #566 from ThomasWaldmann/cache-ctxmgr
implement and use context manager for Cache, partial fix for #285
2016-01-18 01:00:17 +01:00
Thomas Waldmann
22f218baef implement and use context manager for Cache, partial fix for #285
also: make check in Lock.close more precise, check for "is not None".

note: a lot of blocks were just indented to be under the "with" statement,
in one case a block had to be moved into a function.
2016-01-17 01:15:42 +01:00
Thomas Waldmann
4d73f3cdb9 implement and use context manager for RepositoryCache, fixes #548 2016-01-17 00:30:00 +01:00
Thomas Waldmann
720fc49498 hashindex_add C implementation
this was also the loop contents of hashindex_merge, but we also need it callable from Cython/Python code.

this saves some cycles, esp. if the key is already present in the index.
2015-12-07 19:13:58 +01:00
Thomas Waldmann
38994c78fc implement borg break-lock REPO command, fixes #157
due to borg's architecture, breaking the repo lock needs first creating a repository object.
this would usually try to get a lock and then block if there already is one.
thus I added a flag to open without trying to create a lock.
2015-11-21 20:50:53 +01:00
Thomas Waldmann
f19e95fcf7 implement --lock-wait, support timeout for UpgradableLock, fixes #210
also: simplify exceptions / exception handling
2015-11-21 15:34:51 +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
4c6be00d65 remove some superfluous / duplicate log messages 2015-11-06 14:58:12 +01:00
Thomas Waldmann
6d5cc06cf6 remove unused imports, add missing imports 2015-11-02 20:36:13 +01:00
Thomas Waldmann
36cc377329 use default_notty=False for confirmations, fixes #345
this is so that e.g. cron jobs do not hang indefinitely if yes() is called,
but it will just default to "no" if not tty is connected.

if you need to enforce a "yes" answer (which is not recommended for
the security critical questions), you can use the environment:

BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=Y
2015-11-02 01:59:22 +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
f4b0f57618 Merge branch 'master' into multithreading
Some tests are failing, some block, one new test needed skipping.
2015-10-31 19:36:33 +01:00
Radek Podgorny
5cc25d986a move away from RawConfigParser to ConfigParser
this is a recommended thing since direct use of RawConfigParser
is not deprecated according to python docs.
2015-10-29 02:37:43 +01:00
Antoine Beaupré
d666c86bfc adjust display of --stats
it was broken by recent commits.

also remove the __format__() anti-pattern from cache as well.
2015-10-17 21:21:33 -04:00
Antoine Beaupré
b120e5f119 output more progress information
without this, there would be a solid 20 seconds here without any sort
of output on the console, regardless of the verbosity level. this
makes nice incremental messages telling the user that borg is not
stalled (or waiting for a lock, for that matter)

the "processing files" message is a little clunky, as we somewhat
abuse the cache to figure out if we are just starting... but it helps
if there are problems reading the actual files: it tells us the
initialization is basically complete and we're going ahead with the
reading of all the files.
2015-10-17 21:21:31 -04:00
Antoine Beaupré
bdbdbdde90 Merge remote-tracking branch 'origin/master' into logging-refactor
Conflicts:
	borg/archive.py
	borg/archiver.py
	borg/cache.py
	borg/key.py
2015-10-09 12:58:27 -04:00
Thomas Waldmann
60d3b24df4 tagged/signed 0.27.0
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABCgAGBQJWFPIaAAoJECQ6z6lR944Bl6UQAJsRgzQqQBEFk1tmQiDjox36
 QEJA4SyaK6dPCKqxjXNVQ8T/hdDWm2mNGoxBq3A/gcLoU4NRg73DnxroPTg0YRtR
 /mX8ojyjA0Yz9mAAFCGm8LMgTXLRBxqjpow6U/89kA/iOJbfIr4sO0a6cCI/hr9c
 7lL7ZGXO5hgVP7OugJMvLpSG/mW8xRckIW6xx3wjSvcORYPerPAoDpotDGIdMzNy
 UvqZI+TIMIeW1U85PSKa0uODrxdtnVKHBxCJRznqAYb7mOButeYY3u7Ya48oMjdB
 ZucipdWQh++lTod7zhRmczkridVrH229mKMsoA2t9fxmkiJsqkTKzpB+70l8ws+H
 76YQsPc81VJyNg6Cj9rRqrbfSjQ8Wms9+SnKzD9f0MkyyHgwUwkOZhZph5DXH6xn
 xbHbwhBhYbtFyxTXhb9UJMjY2gUREWZ48BDbf81jHUIVfCo9IuXyeWnoEoRmYBJ5
 GGB0ul2V1LG6+divoS9K3HEzf+MPW3nQCi3U4J71wvYDfDR2JggFVayXt/aL/D3E
 ED2FJZMQEQXA5vPKmosBcDr7u1vv7SZ3pjzzbyDLMHHzOG36ScxKkAIzULjpWWhP
 y9fnOv+V2g7Hoq0y3XxBLel3P0Uvx1AADqgKUTeLK0GiSLndqEehHrU1TiYYq077
 NurFcaa97j08b1l8Dif2
 =q6Ou
 -----END PGP SIGNATURE-----

Merge tag '0.27.0' into multithreading

tagged/signed 0.27.0
2015-10-09 17:18:34 +02:00
Antoine Beaupré
1c61f87da3 remove debugging code and fix all have_cython calls 2015-10-08 17:20:52 -04:00
Antoine Beaupré
a869ab0702 try to fix RTD build *again* *again* 2015-10-08 17:03:35 -04:00
Antoine Beaupré
3f68399463 style: wrap multiline strings elegantly 2015-10-08 16:52:49 -04:00
Antoine Beaupré
2d4b735fed remove unintended changes 2015-10-08 16:38:53 -04:00
Antoine Beaupré
42cc17caed use new logger object initialisation code 2015-10-06 12:57:27 -04:00
Antoine Beaupré
24413136ee Merge remote-tracking branch 'origin/master' into logging-refactor
Conflicts:
	borg/archiver.py
2015-10-03 14:23:53 -04:00
TW
adac324b6c Merge pull request #240 from ThomasWaldmann/cache-config-check
fix multiple issues with the cache config version check, fixes #234
2015-10-03 19:19:22 +02:00
Antoine Beaupré
e5a0936a05 add formatters for Cache and Statistics objects
this greatly simplifies the display of those objects, as the
__format__() parameter allows for arbitrary display of the internal
fields of both objects

this will allow us to display those summaries without having to pass a
label to the string representation. we can also print the objects
directly without formatting at all.
2015-10-02 15:55:14 -04:00
Thomas Waldmann
893242ead4 fix multiple issues with the cache config version check, fixes #234
- issue #234: handle exception when config file is empty is really not a borg cache config
- there was a unused %s in the Exception string
- error msg was wrong when version check failed - this IS a borg cache, but not of expected version
2015-10-02 18:11:10 +02:00
Antoine Beaupré
ca6c52610f restore some print statements
the heuristics i used are the following:

 1. if we are prompting the use, use print on stderr (input() may
    produce some stuff on stdout, but it's outside the scope of this
    patch). we do not want those prompts to end up on the standard
    output in case we are piping stuff around

 2. if the command is primarily producing output for the user on the
    console (`list`, `info`, `help`), we simply print on the default
    file descriptor.

 3. everywhere else, we use the logging module with varying levels of
    verbosity, as appropriate.
2015-10-02 11:13:01 -04:00
Antoine Beaupré
c9b11316ab use a module-specific logger instead of global one
that way we have one logger per module, and we can pick and choose
which module we want verbose, for example
2015-10-02 11:05:44 -04:00
Thomas Waldmann
8978515991 temporary hack to avoid using lots of disk space for chunks.archive.d 2015-10-02 16:56:31 +02:00
Antoine Beaupré
09ffbb1d9d convert most print() calls to logging
the logging level varies: most is logging.info(), in some place
logging.warning() or logging.error() are used when the condition is
clearly an error or warning. in other cases, we keep using print, but
force writing to sys.stderr, unless we interact with the user.

there were 77 calls to print before this commit, now there are 7, most
of which in the archiver module, which interacts directly with the
user. in one case there, we still use print() only because logging is
not setup properly yet during argument parsing.

it could be argued that commands like info or list should use print
directly, but we have converted them anyways, without ill effects on
the unit tests

unit tests still use print() in some places

this switches all informational output to stderr, which should help
with, if not fix jborg/attic#312 directly
2015-10-01 13:41:45 -04:00
Thomas Waldmann
26bde96a3a Merge branch 'master' into faster-cache-sync 2015-09-10 23:12:55 +02:00
Thomas Waldmann
322a87cbfd Merge branch 'master' into multithreading
Note: there is a failing archiver test on py33-only now.
It is somehow related to __del__ method usage in Cache
and/or locking code. Could not find out the exact reason
why it behaves like that.
2015-09-08 21:22:37 +02:00
TW
70d97c4467 Merge pull request #180 from ThomasWaldmann/read-device
read special files as if they were regular files, update docs, closes #79
2015-09-06 21:38:31 +02:00
Thomas Waldmann
a912c02757 detect inconsistency / corruption / hash collision, closes #170
added a check that compares the size of the new chunk with the stored size of the
already existing chunk in storage that has the same id_hash value.
raise an exception if there is a size mismatch.

this could happen if:

- the stored size is somehow incorrect (corruption or software bug)
- we found a hash collision for the id_hash (for sha256, this is very unlikely)
2015-09-06 01:10:43 +02:00
Thomas Waldmann
0b1035746e read special files as if they were regular files, update docs, closes #79
do not use the files cache for such special files
2015-09-06 00:29:46 +02:00
Thomas Waldmann
54ccbc5ae2 chunks index resync: do all in one pass
if we do not have a cached archive index: fetch and build and merge it
if we have one: merge it
2015-08-30 15:15:15 +02:00
Thomas Waldmann
22dd925986 chunks index archive: remove all tar and compression related stuff and just use separate files in a directory
the compression was quite cpu intensive and didn't work that great anyway.
now the disk space usage is a bit higher, but it is much faster and less hard on the cpu.

disk space needs grow linearly with the amount and size of the archives, this
is a problem esp. if one has many and/or big archives (but this problem existed
before also because compression was not as effective as I believed).

the tar archive always needed a complete rebuild (and thus: decompression
and recompression) because deleting outdated archive indexes was not
possible in the tar file.

now we just have a directory chunks.archive.d and keep archive index files
there for all archives we already know.
if an archive does not exist any more in the repo, we just delete its index file.
if an archive is unknown still, we fetch the infos and build a new index file.

when merging, we avoid growing the hash table from zero, but just start
with the first archive's index as basis for merging.
2015-08-30 03:03:48 +02:00
Thomas Waldmann
f7210c749f remove cpu intensive compression methods for the chunks.archive
also remove the comment about how good xz compresses - while that was true for smaller index files,
it seems to be less effective with bigger ones. maybe just an issue with compression dict size.
2015-08-29 23:42:28 +02:00
Thomas Waldmann
91d2cfa671 Merge branch 'master' into multithreading 2015-08-15 21:45:52 +02:00
Thomas Waldmann
69456e07c4 cache sync: change progress output to separate lines
printing without \n plus sys.stdout.flush() didn't work as expected.
2015-08-09 19:02:35 +02:00
Thomas Waldmann
35b0f38f5c cache sync: show progress indication
sync can take quite long, so show what we are doing.
2015-08-09 01:14:37 +02:00
Thomas Waldmann
a1e039ba21 reimplement the chunk index merging in C
the python code could take a rather long time and likely most of it was converting stuff from python to C and back.
2015-08-06 23:32:53 +02:00
Thomas Waldmann
e4a41c8981 fix Traceback when running check --repair, attic issue #232
This fix is maybe not perfect yet, but maybe better than nothing.

A comment by Ernest0x (see https://github.com/jborg/attic/issues/232 ):

@ThomasWaldmann your patch did the job.
attic check --repair did the repairing and attic delete deleted the archive.
Thanks.

That said, however, I am not sure if the best place to put the check is where
you put it in the patch. For example, the check operation uses a custom msgpack
unpacker class named "RobustUnpacker", which it does try to check for correct
format (see the comment: "Abort early if the data does not look like a
serialized dict"), but it seems it does not catch my case. The relevant code
in 'cache.py', on the other hand, uses msgpack's Unpacker class.
2015-07-15 13:32:05 +02:00