Commit Graph

646 Commits

Author SHA1 Message Date
Julio Lopez
8f2499b94b breaking(cli): remove deprecated 'snapshot gc' command (#2862)
* remove deprecated `snapshot gc` command
* run `maintenance` instead of `snapshot gc` in robustness
* use `maintenance` command instead of `gc` alias for clarity
* use `maintenance run` in `TestSnapshotDeleteRestore`
2023-04-10 23:17:32 -04:00
Julio Lopez
9a9048c121 breaking(cli): remove default behavior for CLI command (#2861)
* breaking(cli): remove default behavior for `snapshot` command

command: snapshot
default-subcommand: create

* breaking(cli): remove default behavior for `cache` command

command: cache
default-subcommand: info

* breaking(cli): remove default behavior for `index` command

command: index
default-subcommand: list

* breaking(cli): remove default behavior for `maintenance` command

command: maintenance
default-subcommand: run

* breaking(cli): remove default behavior for `manifest` command

command: manifest
default-subcommand: list

* breaking(cli): remove default behavior for `repository upgrade` command

command: repository upgrade
default-subcommand: begin

* breaking(cli): remove default behavior for `server` command

command: server
default-subcommand: start
2023-04-09 01:34:36 +00:00
Damien Degois
f17daee9ea feat(repository): Add Custom Root CA option for S3 (#2845)
* Add Custom Root CA option

example:

```bash
kopia repository connect s3 \
  --access-key the-access-key \
  --secret-access-key the-secret-key \
  --bucket my-backup-bucket \
  --endpoint localhost:9000 \
  --rootca=$(cat public.crt|base64 -w0)
```

* Handle CA as file too
* Lower case JSON option
* Handle file as well as inline
* Add env variable
* Standardize options names
2023-03-31 14:32:34 -07:00
Aaron Alpar
c65613ccba feat(cli): ability to read repository status ... (#2799)
* fix spelling

* permissive index read

* fixup v1 permissive index

* fixups for lint

* trigger rebuild

* Update repo/local_config.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* rename permissive read flag

* extend "permissive-read" rename

* hide permissive command-line flag

* syntax fixup

* fixup for test

* fixups for tests

* Update .golangci.yml

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2023-03-27 16:08:11 -07:00
Ali Dowair
c4d722d2c5 feat(cli): Make format upgrade command idempotent (#2824)
This commit changes the behavior of the command
`kopia repo upgrade begin...` to not fail (exit code 1) when the repository is already using the latest format version. Instead, a helpful message is output and the program exits with zero code. In effect the command becomes idempotent-successive upgrades would return the same exit code. Such an idempotent api is desirable, especially in cases where we build automation around format upgrades.

Before this change, an error code 1 is returned when upgrading a repository that is already up to date:

```
$ kopia repo status | grep "Format Version"
Format version:      3
$ kopia repo upgrade begin --upgrade-owner-id admin
[1] ERROR error setting the upgrade lock intent: repository is using version 3, and version 3 is the maximum
```

and after this change, a 0 code is returned:

```
$ kopia repo upgrade begin --upgrade-owner-id admin
[0] Repository format is already upto date.
```
2023-03-27 12:37:16 +03:00
Jarek Kowalski
6fa50640f4 build(deps): manual upgrade to github.com/alecthomas/kingpin/v2 (#2804)
also upgraded github.com/klauspost/reedsolomon to latest non-retracted version
go mod tidy
2023-03-11 06:28:05 -08:00
Jarek Kowalski
e6612977b7 feat(server): improved server shutdown and integration tests (#2722)
* feat(server): improved server shutdown and integration tests

Added `--shutdown-grace-period` flag to `kopia server start` command
which can be used to specify how long the server will wait for active
connections to finish before forcibly shutting down.

This allowed removal of final out-of-process execution of
during integration tests and the need for `integration-tests` target
which was running the same tests as `tests` but in out-of-process mode.

We thus now have all the test coverage in-process without having to
build and launch `kopia` binary.

* fixed logging

* increase test timeout

* speed up and/or parallelize longest-running tests
2023-02-01 22:19:32 -08:00
Ali Dowair
e5387cec0a docs(cli): minor improvements to upgrade CLI usage/documentation (#2686)
* feat(cli): print upgrade owner in repository status

To help users understand the state of their repository better, this one
line change also prints out the upgrade owner's ID in the output of
`kopia repository status`.

* Upgrade `create --format-version` help message

To show that there is now a format version 3 that can be set.
2023-01-23 12:23:05 +03:00
ashmrtn
fba94ff61e feat(snapshots): Return ReadCloser from StreamingFiles (#2692)
* Return ReadCloser from StreamingFile

Allow better resource management by returning something that can be closed
when dealing with StreamingFiles.

* Close StreamingFile Reader during upload

* Use NopCloser on inputs that don't implement Close

Fixup callers of the StreamingFile API by wrapping regular Readers with
NopCloser calls where necessary.
2023-01-21 16:02:57 +00:00
Edward Betts
1e97574391 fix(general): correct spelling mistakes (#2684) 2023-01-21 07:37:15 -08:00
Jarek Kowalski
f8be8f6a56 refactor(repository): extract parts repo/content into packages (#2651)
- repolog package
- blobcrypto package
- indexblob package

Minor cleanups:

- removed dead code
- introduced New*() methods for object construction
2022-12-17 16:19:12 +00:00
Aaron Alpar
4c0fe390e1 feat(repository): new repository upgrade sub-command to validate indices. (#2561)
* remove unused context param

* add index validation

* add test

* add command stub

* add comments. fixup.

* Update cli/command_repository_upgrade.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* fixup bad merge

* add validation to command line

* set-parameter fixup

* move poison blob to commit

* fixups from PR comments

* fix bug for set-parameter

* robust commit-mode. add upgrade test

* fixup incorrect methods

* fixup for lint

* fixup for lint

* fixup named return values

* fixup failing test

* fixup lint

* fixup for lint

* Update repo/content/committed_read_manager.go

Co-authored-by: Nick <nick@kasten.io>

* Update repo/content/committed_read_manager.go

Co-authored-by: Nick <nick@kasten.io>

* use xor instead of fixed value

* lint fixups

* fixup for lint cyclomatic complexity

* fixup bad merge

* fixup set-parameters downgrade

* Update cli/command_repository_upgrade.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* Update cli/command_repository_upgrade.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* fixup set-parameters downgrade

* cleanup set-parameters test

* fixup tests, refactor for index verification

* fixups and clarity

* remove set-parameter downgrade check

* index on feat-k10-12441-B-validate-index: b63879cd Merge 'master' into feat-k10-12441-B-validate-index

* trigger build

* remove needless blank line

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
Co-authored-by: Nick <nick@kasten.io>
2022-12-13 09:42:09 -08:00
Aaron Alpar
ca7df80e64 fix(cli): do not allow index downgrade by using set-parameter (#2629)
* disallow downgrades

* fixup merge
2022-12-06 18:33:55 -08:00
Jarek Kowalski
65f295ed79 refactor(repository): replaced atomic values with Go 1.19 atomic wrappers (#2590)
Almost all were easy to replace, except ones exposed via JSON which
have been left as-is.

The linter has a cool behavior where it flags attempts to pass
`atomic.Int32` for example by value , which is always a mistake,
say as an argument to `fmt.Sprintf()`
2022-11-19 18:39:04 +00:00
Jarek Kowalski
78edd92692 refactor(repository): refactored Prometheus metrics (#2532)
This may be a breaking change for users who rely on particular kopia metrics (unlikely):

- introduced blob-level metrics:

* `kopia_blob_download_full_blob_bytes_total`
* `kopia_blob_download_partial_blob_bytes_total`
* `kopia_blob_upload_bytes_total`
* `kopia_blob_storage_latency_ms` - per-method latency distribution
* `kopia_blob_errors_total` - per-method error counter

- updated cache metrics to indicate particular cache

* `kopia_cache_hit_bytes_total{cache="CACHE_TYPE"}`
* `kopia_cache_hit_total{cache="CACHE_TYPE"}`
* `kopia_cache_malformed_total{cache="CACHE_TYPE"}`
* `kopia_cache_miss_total{cache="CACHE_TYPE"}`
* `kopia_cache_miss_errors_total{cache="CACHE_TYPE"}`
* `kopia_cache_miss_bytes_total{cache="CACHE_TYPE"}`
* `kopia_cache_store_errors_total{cache="CACHE_TYPE"}`

where `CACHE_TYPE` is one of `contents`, `metadata` or `index-blobs`

- reorganized and unified content-level metrics:

* `kopia_content_write_bytes_total`
* `kopia_content_write_duration_nanos_total`

* `kopia_content_compression_attempted_bytes_total`
* `kopia_content_compression_attempted_duration_nanos_total`
* `kopia_content_compression_savings_bytes_total`
* `kopia_content_compressible_bytes_total`
* `kopia_content_non_compressible_bytes_total`
* `kopia_content_after_compression_bytes_total`

* `kopia_content_decompressed_bytes_total`
* `kopia_content_decompressed_duration_nanos_total`

* `kopia_content_encrypted_bytes_total`
* `kopia_content_encrypted_duration_nanos_total`

* `kopia_content_hashed_bytes_total`
* `kopia_content_hashed_duration_nanos_total`

* `kopia_content_deduplicated_bytes_total`

* `kopia_content_read_bytes_total`
* `kopia_content_read_duration_nanos_total`

* `kopia_content_decrypted_bytes_total`
* `kopia_content_decrypted_duration_nanos_total`

* `kopia_content_uploaded_bytes_total`

Also introduced `internal/metrics` framework which constructs Prometheus metrics in a uniform way and will allow us to include some of these metrics in telemetry report in future PRs.
2022-11-10 05:30:06 +00:00
Jarek Kowalski
0554e2f7ce refactor(general): introduced generics to reduce boilerplate code (#2527)
This removes tons of boilerplate code around:

- retry loop
- connection management
- storage registration

* used generics in runInParallel
* introduced generics in freepool
* introduced strong typing for workshare.Pool and workshare.AsyncGroup
* fixed linter error on openbsd
2022-10-29 01:56:51 +00:00
Jarek Kowalski
f69424961f chore(ci): upgrade golang to 1.19.2 and linter to 1.50.1 (#2526)
Lack of generics support is blocking various dependency upgrades,
so this unblocks that.

Temporarily disabled `checklocks` linter until it is fixed upstream.
2022-10-28 11:02:47 -07:00
atom
c5efed01f4 feat(cli): Support displaying storage values in base-2 [#2492] (#2502)
* Update display on repository summary

* Apply throughout app

* Situate units_test

* Update Command Line documentation

* Envar cleanup

* Rename to BytesString

* Restore envar string available for test

* Remove extraneous empty check and restore UIPreferences field for frontend

* PR: config bool cleanup and missed `BaseEnv`s

* Fix lint and test
2022-10-24 19:00:36 -07:00
Aaron Alpar
02ecd0d5a7 feat(repository): Allow clock drift to be specified on upgrade. (#2357)
* add max-clock-drift flag

* fixups

* module dependencies

* package fixup
2022-09-26 18:28:56 -07:00
Ali Dowair
883f273579 Output bad key in error when incorrectly parsed (#2438)
In the function that parses the tags passed to the create snapshot
command, if the tag had an incorrect format, an error message would
be returned which did not show the tag itself, making debugging such
error difficult. This commit includes the tag in the error message to
make debugging easier.
2022-09-25 21:37:29 -07:00
Jarek Kowalski
645e680a8f feat(general): reduce memory usage in maintenance, snapshot fix and verify (#2365) 2022-09-10 09:36:17 -07:00
Ricardo Pescuma Domenecci
31495392a1 feat(cli): Allow restore from snapshoted path (#2335)
* feat(cli): Allow restore from snapshoted path

* Find files in multiple snapshots

* Added --snapshot-time to restore

* Added restore by path test

* More timespec formats

* Test for snapshot list with a file in multiple snapshots

* Handle restore without target path

* Fix for tests

* Made changes requested in PR and rebased
2022-09-06 04:42:07 +00:00
Jarek Kowalski
cbb7d68fb6 feat(repository): implemented format.Manager - take 2 (#2349)
* implemented format blob cache abstraction

* moved upgrade lock logic to repo/format

* moved set parameters logic to repo/format

* moved change password functionality to repo/format

* mechanical changes

* mechanical changes to react to format manager interface

* get current repository format bytes instead of static

* implemented format.Manager which dynamically fetches and caches latest format blob

* repo changes to use format.Manager

* fixed failing unit test due to different timings

* reduced lock contention by using RWMutex

* serve immutable parts of format without any locks

* increase test timeout

* fixed handling of negative validDuration

The new rules are:

- validDuration < 0 - ignore initial cached file, refresh every 15min
- validDuration > 15min - refresh every 15 minutes
- validDuration > 0 && validDuration <= 15min - refresh using provided
  interval (mostly used for testing)
2022-09-02 18:55:01 -07:00
Jarek Kowalski
7bda16ab33 feat(repository): introduced fs.UTCTimestamp (#2343)
Fixes #2342
2022-09-02 10:35:59 -07:00
Niklas Hambüchen
2dd752b1df fix(cli): Fix /debug/pprof/heap returning 404 (#2339)
See https://github.com/kopia/kopia/issues/1903#issuecomment-1127172904
2022-08-23 08:55:25 +00:00
Shikhar Mall
11c7bf533c feat(cli): flag to allow placing the upgrade lock without doing anything else (#2329)
Co-authored-by: Shikhar Mall <small@kopia.io>
2022-08-19 13:48:08 -07:00
Ricardo Pescuma Domenecci
8b41543250 chore(cli): make ecc options visible but marked as experimental (#2322) 2022-08-19 15:04:40 +00:00
Shikhar Mall
e317cdba9f fix: drop the ability to set advance-notices on upgrade (#2312)
Co-authored-by: Shikhar Mall <small@kopia.io>
2022-08-19 07:35:56 -07:00
Ricardo Pescuma Domenecci
47aaa2dc40 feat(cli): Added ECC related options to repository create cli command (#2308)
* Encryptor pipeline

* Added ECC related options to repository create cli command

* Fix for lint errors

* Fixing comments from the PR

* Fixed lint errors

* Changes requested in PR

* Created e2e test
2022-08-13 08:49:22 -07:00
Ricardo Pescuma Domenecci
0724511283 feat(repository): Error correction for blobs (#2270)
* Initial implementation of ecc using Encryptor interface

* Created benchmark ecc command

* Fixing the order inside the wrapper

* Removed rs_bw because it is always worse

* Fixing naming and adding more comments

* Different approaches depending of file size/space overhead

* Fixes requested in PR

* Fixed lint errors

* Fixes requested in the PR

* Fixed import order

* Fixed more lint errors
2022-08-09 18:24:25 -07:00
Jarek Kowalski
51dcaa985d chore(ci): upgraded linter to 1.48.0 (#2294)
Mechanically fixed all issues, added `lint-fix` make target.
2022-08-09 06:07:54 +00:00
Jarek Kowalski
23299c3451 refactor(repository): ensure MutableParameters are never cached (#2284) 2022-08-06 18:11:32 -07:00
Ricardo Pescuma Domenecci
46697a69ae feat(cli): allow to profile benchmarks (#2281) 2022-08-06 00:54:55 +00:00
Jarek Kowalski
6160ee5668 refactor(repository): moved format blob management to separate package (#2245)
* refactor(repository): moved format blob management to separate package

This is completely mechanical, no behavior changes, only:

- moved types and functions to a new package
- adjusted visibility where needed
- added missing godoc
- renamed some identifiers to align with current usage
- mechanically converted some top-level functions into member functions
- fixed some mis-named variables

* refactor(repository): moved content.FormatingOptions to format.ContentFormat
2022-07-30 14:13:52 -07:00
Jarek Kowalski
30456d13e7 refactor(repository): refactored Crypter to an unexported interface (#2251) 2022-07-30 14:57:56 +00:00
Jarek Kowalski
b9be9632a2 feat(repository): added required features to the repository (#2220)
* feat(repository): added `required features` to the repository

This is intended for future compatibility to be able to reliably
stop old kopia client from being able to open a repository when
the old code does not understand new `required feature`.

Required features are checked on startup and periodically using the
same method as upgrade lock, where they will return errors during blob
operations.

* pr feedback
2022-07-29 09:31:17 -07:00
Jarek Kowalski
03da9b1f0e feat(cli): improved safety of v1->v2 index format upgrade (#2223)
When upgrading from legacy to epoch manager-based index, we will write
an intentionally-corrupted index blob, such that old clients won't be
able to understand it when they read the repository index using legacy
format.

The error message emitted by very old clients is not great, but it's
safer to do that rather than corrupt the repository.

Note that this additional safety has a delay of up to 15 minutes
which is the time required for old clients to stop relying on index list
cache in case of very long-running snapshots, server or KopiaUI.
2022-07-28 17:32:31 -07:00
Jarek Kowalski
56f3046d8a refactor(repository): introduce interface for reading FormattingOptions (#2235)
Instead of passing static content.FormattingOptions (and caching it)
we now introduce an interface to provide its values.

This will allow the values to dynamically change at runtime in the
future to support cases like live migration.
2022-07-28 17:27:04 -07:00
Shikhar Mall
26e6f59b2b feat(cli): New Upgrade CLI / Switch to Format Version 3 (upgrade coordination) (#1818)
* kopia format upgrade lock

* Update cli/command_repository_set_parameters_test.go

Co-authored-by: Ali Dowair <adowair@umich.edu>

* Update cli/command_repository_upgrade.go

Co-authored-by: Ali Dowair <adowair@umich.edu>

* Update cli/command_repository_upgrade.go

Co-authored-by: Ali Dowair <adowair@umich.edu>

* pr feedback

* pr feedback

* add a min drain time check

* env var for io-drain-timeout

* fix: add more doctext around upgrade phases

* build: wrap with EnvName

* add experimental warning

* protect upgrade cli behind env varible

* fix conflicts after relocating the upgrade lock

* generalize the command args

* drop certain features as per feedback

* sub-divide the upgrade command into begin and rollback

* Update cli/command_repository_upgrade.go

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>

* Update cli/command_repository_upgrade.go

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>

* missing return

* rename force flag to allow-unsafe-upgrade

Co-authored-by: Shikhar Mall <shikhar@kasten.io>
Co-authored-by: Ali Dowair <adowair@umich.edu>
Co-authored-by: Shikhar Mall <small@kopia.io>
Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2022-07-27 16:23:45 -07:00
Jarek Kowalski
1a82061e49 chore(ci): upgraded linter to 1.47.0, added 15s ReadHeaderTimeout in web server (#2206) 2022-07-18 22:47:36 -07:00
Jarek Kowalski
191b3e5461 feat(cli): BREAKING CHANGE ensure --checkpoint-interval is <=45min (#2196)
Also hide the flag, since it's not recommended to be tweaked anyway.

The value of <=45m is very important for safety of the garbage collection algorithms - too long an interval between checkpoints could mean that GC treats contents in the middle of being uploaded as unused, because they are not reachable from any snapshots or checkpoints.

Fixes #2193
2022-07-16 04:15:32 +00:00
Jarek Kowalski
ea257b1597 feat(cli): removed unnecessary logs from cli-logs (#2174)
- removed memory tracking since it's redundant with profiling
  and prometheus support.
- various cleanups to make sure default log is clean
2022-07-10 16:25:25 -07:00
Jarek Kowalski
700f542a3d fix(cli): fixed 'cache set' CLI regression due to kingpin change (#2173)
This was caused by a default `-1ns` which is no longer supported
in latest Kingpin.

The effect was that `kopia cache set` without
`--max-list-cache-duration` would fail. Unforutnately test was passing
that flag so it was missed.

This was likely caused by https://github.com/alecthomas/kingpin/pull/329
2022-07-10 13:26:41 -07:00
Jarek Kowalski
8515d050e5 test(infra): improved support for in-process testing (#2169)
* feat(infra): improved support for in-process testing

* support for killing of a running server using simulated Ctrl-C
* support for overriding os.Stdin
* migrated many tests from the exe runner to in-process runner

* added required indirection when defining Envar() so we can later override it in tests

* refactored CLI runners by moving environment overrides to CLITestEnv
2022-07-09 18:22:50 -07:00
Jarek Kowalski
04fe236a5f fix(cli): fixed snapshot sizes in the snapshot list (#2148)
This is caused by a fix where fs.Directory was incorrectly reporting
its size == total size of all files in all subdirectories and
`snapshot list` was relying on that.

Fixes #2144
2022-07-06 05:54:27 +00:00
Jarek Kowalski
0985b80488 feat(ui): support for deprecation of certain algorithms (#2122)
Some compression algorithms are not recommended because they
allocate disproportionate amounts of memory. They are still
possible to use, just marked as NOT RECOMMENDED in the UI.
2022-07-03 19:06:14 +00:00
Ali Dowair
98e10d52f1 Rename --sparse to --write-sparse-files (#2095)
This commit renames the sparse restore flag (`kopia snapshot restore`
and `kopia restore`) to conform more with the naming precedents in
the Kopia code. This is a breaking change.

The original motivation can be found here:
https://github.com/kopia/htmlui/pull/61#discussion_r899155054
2022-07-01 19:01:53 -07:00
Jarek Kowalski
70e24106ee refactor(general): unified logging.Logger with *zap.SugaredLogger (#2090)
- removed a bunch of hacks and should improve the logging
performance by avoiding interfaces and data translation. This will
allow using of de-sugared loggers in performance-critical
logging situations.

- this will also allow using features of ZAP more directly without
having to reimplement them.

- moved logging.Printf() to testlogging

- refactored `uitask` to store logs in a structural format and
present them as JSON only in the UI

- renamed printf_logger.go to printf.go so that fewer columns are used
in the logs
2022-06-26 05:11:52 +00:00
Jarek Kowalski
68b8afd43f feat(snapshots): improved performance when uploading huge files (#2064)
* feat(snapshots): improved performance when uploading huge files

This is controlled by an upload policy which specifies the size
threshold above which indvidual files are uploaded in parts
and concatenated.

This allows multiple threads to run splitting, hashing, compression
and encryption in parallel, which was previously only possible across
multiple files, but not when a single file was being uploaded.

The default is 2GiB for now, so this feature only kicks in for very
larger files. In the future we may lower this.

Benchmark involved uploading a single 42.1 GB file which was a VM disk
snapshot of fresh Ubuntu installation (fresh EXT4 partition with lots
of zero bytes) to a brand-new filesystem repository on local SSD of
M1 Pro Macbook Pro 2021.

* before: 59-63s (~700 MB/s)
* after: 15-17s  (~2.6 GB/s)

* additional test to ensure files are really e2e readable
2022-06-24 07:38:07 +00:00
Shlok Chaudhari
06c8de08de test(cli): add separate test case for days in --retention-period flag (#2057) 2022-06-16 11:10:23 -07:00