Commit Graph

328 Commits

Author SHA1 Message Date
Jarek Kowalski
331ff076bb cli: added number of files that are in the process of being hashed 2020-03-14 15:56:09 -07:00
Jarek Kowalski
8d452a8285 performance: improvements to object manager (#336)
- added pooled splitters and ability to reset them without having to recreate
- added support for caller-provided compressor output to be able to pool it
- added pooling of compressor instances, since those are costly
2020-03-13 08:56:18 -07:00
Jarek Kowalski
526445a9c8 CLI: pre-allocated buffers for crypto benchmark (#343)
non-optimized (0.5.0)
  0. BLAKE2B-256-128      AES256-GCM-HMAC-SHA256 644.9 MiB / second

before this change:
  0. BLAKE2B-256-128      AES256-GCM-HMAC-SHA256 655.9 MiB / second

after (this change):
  0. BLAKE2B-256-128      AES256-GCM-HMAC-SHA256 781.5 MiB / second
2020-03-12 12:11:20 -07:00
Jarek Kowalski
e80f5536c3 performance: plumbed through output buffer to encryption and hashing,… (#333)
* performance: plumbed through output buffer to encryption and hashing, so that the caller can pre-allocate/reuse it

* testing: fixed how we do comparison of byte slices to account for possible nils, which can be returned from encryption
2020-03-12 08:27:44 -07:00
Julio López
89c0c6bac4 Refactor CLI stats (#341)
* Helper package internal/stats
* Use internal/stats for blob gc stats
* Use internal/stats for content list stats
* Refactor gc stats
  - Leverages internal/stats package
  - Return GC stats
  - nit: error message formatting
  - Refactor block in gc.Run.
     Simplifies and reduces a level of indentation
2020-03-11 22:16:07 -07:00
Jarek Kowalski
6ce8410a29 Added OpenCensus (#339)
* repo: added some initial metrics using OpenCensus

* cli: added flags to expose Prometheus metrics on a local endpoint

`--metrics-listen-addr=localhost:X` exposes prometheus metrics on
   http://localhost:X/metrics

Also, kopia server will automatically expose /metrics endpoint on the
same port it runs as, without authentication.
2020-03-11 22:07:31 -07:00
Julio López
edc87fcce8 Refactor content stats (#340)
* Remove unused fields from content.Stats
* Refactor content.Stats
2020-03-11 21:47:05 -07:00
Jarek Kowalski
514df69afa performance: added wrapper around io.Copy()
this pools copy buffers so they can be reused instead of throwing away
after each io.Copy()
2020-03-10 21:52:30 -07:00
Jarek Kowalski
cd35e3bab5 cli: 'snapshot migrate' improvements to help with data migration
- cleaned up migration progress output
- fixed migration idempotency
- added migration of policies
- renamed --parallelism to --parallel
- improved e2e test
- do not prompt for password to source repository if persisted
2020-03-07 21:47:32 -08:00
Jarek Kowalski
d526843124 cli: fixed metadata cache size on connect/create 2020-03-07 21:47:32 -08:00
Jarek Kowalski
c5cf95fdf6 cli: improved 'content verify'
Now you can quickly verify that all contents are correctly backed
by existing blob without downloading much.

You can still use '--full' to cause full download and decryption.
2020-03-05 17:33:56 -08:00
Jarek Kowalski
889f2ead59 cli: improved 'blob gc'
- do not remove blobs younger than 4h when performing blob GC,
  because they may have just been written
- parallelize deletes
- clean up console output
2020-03-05 17:33:56 -08:00
Jarek Kowalski
6f68b726a7 cli: improved 'content rewrite'
- removed confusing '--prefixed' option
- print timestamp of contents as they are rewritten
2020-03-05 17:33:56 -08:00
Jarek Kowalski
a4fad4ca5a cli: added 'blob stats' command 2020-03-05 17:33:56 -08:00
Jarek Kowalski
fb181257bf cli: implemented update check, fixes #119 2020-03-04 22:06:05 -08:00
Jarek Kowalski
d95e6a3d09 sftp: Fixed issues in SFTP provider, Fixes #216
- did not work on windows due to use of filepath which uses backslash
  instead of slash
- added support for embedding SFTP key
- fixed UI controls
- misc fixes for KopiaUI
- added progress reporting
2020-03-01 18:56:06 -08:00
Jarek Kowalski
38862a7bf9 kopia-ui: fixed redirection to /repo not working (404) 2020-02-29 21:55:06 -08:00
Jarek Kowalski
ddd267accc crypto: deprecated crypto algorithms and replaced with better alternatives
New ciphers are using authenticated encryption with associated data
(AEAD) and per-content key derived using HMAC-SHA256:

* AES256-GCM-HMAC-SHA256
* CHACHA20-POLY1305-HMAC-SHA256

They support content IDs of arbitrary length and are quite fast:

On my 2019 MBP:

- BLAKE2B-256 + AES256-GCM-HMAC-SHA256 - 648.7 MiB / second
- BLAKE2B-256 + CHACHA20-POLY1305-HMAC-SHA256 - 597.1 MiB / second
- HMAC-SHA256 + AES256-GCM-HMAC-SHA256 351 MiB / second
- HMAC-SHA256 + CHACHA20-POLY1305-HMAC-SHA256 316.2 MiB / second

Previous ciphers had several subtle issues:

* SALSA20 encryption, used weak nonce (64 bit prefix of content ID),
  which means that for any two contents, whose IDs that have the same
  64-bit prefix, their plaintext can be decoded from the ciphertext
  alone.

* AES-{128,192,256}-CTR were not authenticated, so we were
  required to hash plaintext after decryption to validate. This is not
  recommended due to possibility of subtle timing attacks if an attacker
  controls the ciphertext.

* SALSA20-HMAC was only validating checksum and not that the ciphertext
  was for the correct content ID.

New repositories cannot be created using deprecated ciphers, but they
will still be supported for existing repositories, until at least 0.6.0.

The users are encouraged to migrate to one of new ciphers when 0.5.0 is
out.
2020-02-29 20:50:50 -08:00
Jarek Kowalski
d181403284 crypto: refactored encryption, hashing and splitter into separate packages (#274)
Added some tests, deleted XSALSA20 which never worked E2E
2020-02-27 12:36:49 -08:00
Jarek Kowalski
765bff8e0b cli: restored snapshot create --hostname and --username flags 2020-02-25 20:40:23 -08:00
Jarek Kowalski
e3854f7773 BREAKING: changed how hostname/username are handled
The hostname/username are now persisted when connecting to repository
in a local config file.

This prevents weird behavior changes when hostname is suddenly changed,
such as when moving between networks.

repo.Repository will now expose Hostname/Username properties which
are always guarnateed to be set, and are used throughout.

Removed --hostname/--username overrides when taking snapshot et.al.
2020-02-25 20:40:23 -08:00
Jarek Kowalski
c8fcae93aa logging: refactored logging
This is mostly mechanical and changes how loggers are instantiated.

Logger is now associated with a context, passed around all methods,
(most methods had ctx, but had to add it in a few missing places).

By default Kopia does not produce any logs, but it can be overridden,
either locally for a nested context, by calling

ctx = logging.WithLogger(ctx, newLoggerFunc)

To override logs globally, call logging.SetDefaultLogger(newLoggerFunc)

This refactoring allowed removing dependency from Kopia repo
and go-logging library (the CLI still uses it, though).

It is now also possible to have all test methods emit logs using
t.Logf() so that they show up in failure reports, which should make
debugging of test failures suck less.
2020-02-25 17:24:44 -08:00
Prasad Ghangal
c682fffdf2 Support for Azure blob storage (#271)
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
2020-02-25 16:32:26 -08:00
Jarek Kowalski
897483299f Kopia UI & CLI: support for progress indicator (#268)
Percentage based on last-known snapshot size

* server: exposed last completed snapshot size in the API
* cli: added support for progress indicator (percentage based on last-known snapshot size)
* htmlui: added progress indicator in the UI (percentage based on last-known snapshot size)
2020-02-24 17:55:02 -08:00
Jarek Kowalski
f8006f8ce0 cli: removed flags for configuring global policy on repository creation 2020-02-18 12:21:11 -08:00
Jarek Kowalski
a21da7b960 cli: fixed double-close of repository during 'server start' 2020-02-16 22:43:36 -08:00
Jarek Kowalski
0f79279f5e server: added support for new verbs in the API
/api/v1/repo/create
/api/v1/repo/connect
/api/v1/repo/disconnect

Refactored server code and fixed a number of outstanding robustness
issues. Tweaked the API responses a bit to make more sense when consumed
by the UI.
2020-02-13 17:23:50 -08:00
Prasad Ghangal
1c3858a906 Add AWS Session Token support to Kopia
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
2020-02-12 08:19:24 -08:00
Jarek Kowalski
a8503a007c server: allow starting server on randomly-allocated port by specifing port 0 (#224)
allow starting server on randomly-allocated port by specifing port 0
2020-02-11 17:08:50 -08:00
Jarek Kowalski
862fc69bff cli: marked --ignore-{file,dir}-errors as enums, so that CLI parser enforces correct values 2020-02-11 06:41:20 -08:00
Nick
162db3e861 [minor] Fix error handling policy print (#221)
Fixes print for error handling policy. Previously was printing
pointer address, now dereference pointer to print boolean itself.
Nil check in case the caller passes a policy with nil. In that
case print "false" which is the behavior in uploader for nil
pointer.
2020-02-10 20:22:55 -08:00
Jarek Kowalski
4736e9037e revamped progress output and cleaned up logging
See https://asciinema.org/a/ykx6uzEhKY3451fWEnX9nm9uo
2020-02-10 19:08:35 -08:00
Nick
1a24c34df8 Ignore read errors based on policy settings (#207)
* Ignore read errors based on policy settings

Added an error handling policy section. Can independently control error handling for directory and file read errors, toggle-able from the `policy set` command to either "true", "false", or "inherit". If any read error is hit, the error handling will check the effective policy on whether to ignore it or not. Currently there is no differentiation between read error types, though in the future we may want to add the `errors.Is(err, os.ErrPermission)` conditional.

Fix was implemented such that the policy ignores read errors ONLY on child entries of the source. So a snapshot will still fail if the source root directory itself can't be read, but you can ignore the error if a file or a subdirectory in the snapshot source root can't be read. I did this to address some otherwise strange behavior where you would successfully snapshot (because you ignored the error), but couldn't restore that snapshot because nothing really happened during the operation.
2020-02-10 17:35:53 -08:00
Jarek Kowalski
edca1733b6 repo: moved password persistence to repository layer 2020-02-09 20:55:07 -08:00
Julio Lopez
4625e5ba9e Remove content.CompactOptions.MinSmallBlobs
Use MaxSmallBlobs instead. MaxSmallBlobs was not being really used.
Replaced uses of MinSmallBlobs with MaxSmallBlobs and removed
MinSmallBlobs
2020-02-06 21:51:51 -08:00
Jarek Kowalski
0a42ceab27 gcs: added --embed-credentials options which persists --credentials-file as part of Kopia configuration 2020-02-04 22:35:26 -08:00
Jarek Kowalski
9680dc376b cli: improvements for 'kopia server' and client
Those will make it possible to securely host 'kopia server' embedded
in a desktop app that runs in the background and can access UI.

- added support for using and generating TLS certificates
- added /api/v1/shutdown API to remotely trigger server shutdown
- added support for automatically shutting down server if no requests
  arrive in certain amount of time
- added support for generating and printing random password to STDERR

TLS supports 3 modes:

1. serve TLS using externally-provided cert/key PEM files
2. generate & write PEM files, then serve TLS using them
3. generate and use emphemeral cert/key (prints SHA256 fingerprint)
2020-01-24 17:25:45 -08:00
Nick
3913241159 [Trivial] Fix command description for blob delete
Fix probable copy paste error on "blob delete" subcommand from
the "blob show" description.
2020-01-20 21:28:44 -08:00
Jarek Kowalski
644ef93d45 s3: added optional --region parameter
Fixes #168
2020-01-09 16:37:36 -08:00
Jarek Kowalski
ac70a38101 lint: upgraded to 1.22.2 and make lint issues a build failure
fixed or silenced linter warnings, mostly due to magic numeric constants
2020-01-03 16:39:30 -08:00
Julio Lopez
ac6e84107e Add CopyOptions and copier structs 2020-01-02 13:49:28 -08:00
Julio Lopez
20b896da18 Add restore command flags 2020-01-02 13:49:28 -08:00
Julio Lopez
c03a143ae9 Fix flag description 2020-01-02 09:50:45 -08:00
Julio Lopez
194680adfc Refactor: relocate user/host helpers to userhost.go 2019-12-18 23:11:38 -08:00
Julio Lopez
0b7f30b6b4 rename cli/snapshot_utils.go -> cli/userhost.go 2019-12-18 23:11:38 -08:00
Julio Lopez
c8360ce6ca cleanup: fix linter errors
```
make lint
kopia/tools/.tools/bin/golangci-lint --deadline 180s run | tee .linterr.txt
cli/command_snapshot_delete.go:5: File is not `goimports`-ed with -local github.com/kopia/kopia (goimports)

tests/end_to_end_test/end_to_end_test.go:303: Function 'TestSnapshotDelete' is too long (187 > 100) (funlen)
func TestSnapshotDelete(t *testing.T) {
tests/end_to_end_test/end_to_end_test.go:306:2: only one cuddle assignment allowed before range statement (wsl)
	for _, tc := range []struct {
	^
tests/end_to_end_test/end_to_end_test.go:517:4: only one cuddle assignment allowed before if statement (wsl)
			if expectDeleteSucceeds {
			^
tests/end_to_end_test/end_to_end_test.go:537:2: assignments should only be cuddled with other assignments (wsl)
	line := lines[0]
	^
tests/end_to_end_test/end_to_end_test.go:542:2: only one cuddle assignment allowed before if statement (wsl)
	if typeVal != "policy" {
	^
tests/end_to_end_test/end_to_end_test.go:558:2: assignments should only be cuddled with other assignments (wsl)
	restoreDir := filepath.Join(e.dataDir, "restored")
	^
tests/end_to_end_test/end_to_end_test.go:568:2: if statements should only be cuddled with assignments (wsl)
	if got, want := len(si[0].snapshots), 1; got != want {
	^
tests/end_to_end_test/end_to_end_test.go:571:2: assignments should only be cuddled with other assignments (wsl)
	snapID := si[0].snapshots[0].snapshotID
	^
tests/end_to_end_test/end_to_end_test.go:604:2: if statements should only be cuddled with assignments (wsl)
	if len(fileInfo) != 0 {
	^
cli/command_snapshot_delete.go:25:2: only one cuddle assignment allowed before if statement (wsl)
	if err != nil {
	^
cli/command_snapshot_delete.go:36:3: if statements should only be cuddled with assignments (wsl)
		if labels["username"] != getUserName() {
		^
```
2019-12-18 18:17:15 -08:00
Jarek Kowalski
d9d4804dcb server: handle known UI routes specially by serving root index file 2019-12-14 13:10:32 -08:00
Nick
3f721aaf01 Snapshot restore command
Snapshot restore will take a snapshot ID and restore the
associated snapshot to the target path.
- Looks up the manifest with the snapshot ID
- Gets the snapshot root entry
- Copies the snapshot from the root entry to the target path

Because it uses the parent manifest with the copied permissions,
the restored directory will have the permissions of the original
source directory.
2019-12-13 06:18:50 -08:00
Nick
ae3d5610bf Dedicated snapshot delete command to delete by snap ID (#8)
Implemented snapshot delete command. Behaves similarly to manifest rm, but with extra verification steps. 
- Checks that the referenced manifest is of type "snapshot"
- Checks that the ID points to a snapshot, checks that the host name, user name, and path provided by flag or defaults match the source of the snapshot ID. Command will fail if they do not match, except if given --unsafe-ignore-source, which will bypass the associated safety requirement and delete anyway.

Added end to end tests for input combinations, restore in conjunction with delete, and trying to snapshot delete a manifest by ID of a non-snapshot manifest.
2019-12-12 18:02:48 -08:00
Jarek Kowalski
2ba4e83cef moved all compression to separate package and sanitized identifiers 2019-12-10 23:25:28 -08:00