Commit Graph

756 Commits

Author SHA1 Message Date
Julio Lopez
1c5c4e2568 refactor(cli): cleanup cli.repositoryAccessMode (#4541)
Remove `repositoryAccessMode.mustBeConnected`
It is always true.

Rename `repositoryAccessMode.disableMaintenance`
to `allowMaintenance`.
This explicitly conveys when maintenance is allowed
to run. It is related to accessing a repository in
'read-only' mode.
2025-05-01 15:35:11 -07:00
Julio Lopez
2d9b7f1e33 feat(providers): Azure Blob client certificate authentication (#4535)
Allow the use of a client certificate when authenticating
to an Azure Blob storage provider.

Tests included.

Credit: @DeepikaDixit

Authored-by: Deepika Dixit <DeepikaDixit@users.noreply.github.com>
2025-04-29 23:47:41 -07:00
Julio Lopez
8098f49c90 chore(ci): remove exclusion for unused ctx parameters (#4530)
Remove unused-parameter exclusion for `ctx` in revive linter.

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-26 23:11:36 -07:00
Matthieu MOREL
8a176255c0 fix(general): enable wsl for all go files (#4524)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-26 13:01:20 -07:00
blenderfreaky
f12fafb516 docs(cli): clarify documentation regarding per-user and per-host (#4512)
Ref: #4341

---------
Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2025-04-23 23:37:15 -07:00
Julio López
09b88d3860 chore(general): minor cleanups and other nits (#4507)
* use uint8 for clarity
* unexport writeContentAsyncAndVerify
* fix typo in test function name
* remove commented interface functions
* use atomic.Int32
* cleanups in socket server activation test
* leverage stdlib's maps and slices packages
  replace uses of `golang.org/x/exp/maps`
* nit: leverage `maps.Values`
2025-04-16 23:25:01 -07:00
Matthieu MOREL
675e958877 chore(ci): bump golangci-lint to v2.1.2 (#4500)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-15 22:49:13 -07:00
Jarek Kowalski
51ef01dad5 refactor(snapshots): extracted snapshot.FindPreviousManifests() (#4453) 2025-04-13 04:08:03 +00:00
Julio López
ad33441fbc chore(cli): add details to persistent password error message (#4480)
Extends error message with a generic, OS-independent hint about
what the source of the error may be and a potential solution.

Also, modifies error message to avoid duplicate messages.

- kopia/kopia#4449
2025-03-31 21:10:21 -07:00
Julio López
8f32be2a00 fix(cli): add newline after policy export output (#4476)
- #4341
- #4020
2025-03-29 22:46:28 -07:00
Jarek Kowalski
51de24dcff refactor(snapshots): refactored uploader into separate package (#4450) 2025-03-14 15:48:31 -07:00
Rohit-BM18
9b68189d29 feat(cli): compute snapshot diff stats (#4444)
Added functionality to calculate aggregate statistics when
comparing what's changed between snapshots using kopia diff

Statistics collected during snapshot diff computation includes:

- files added/removed/modified
- dirs added/removed/modified
- files/dirs with metadata changes but same underlying content (OID)

Testing approach:

Added a test for verifying stats collected when comparing two directories with the same objectID but metadata changes across snapshots (dir mode, dir mod time, dir owner, etc), expectation is all the appropriate dir stats fields are updated.
Added another test for verifying stats collected when comparing two directories with similar file contents but the metadata for the files have changed between snapshots but content remains unchanged. Expectation is all the relevant file level stats fields are updated.
Existing tests have been updated due to stats now being printed in addition to previous output.
2025-03-07 12:41:14 +00:00
Julio López
8f632e4e1f refactor(cli): diff test (#4422)
- Use a single struct and implementation for common functionality
- set type in Mode() for directories
- nit: fix typo
2025-02-21 21:57:22 -08:00
Jarek Kowalski
e6e2870319 feat(notifications): tweak snapshot report template (#4338)
* feat(notifications): tweak snapshot report template

* test fix
2025-01-09 18:45:51 -08:00
Janne Johansson
a4d725e754 Update command_benchmark_compression.go (#4339)
make sure MB-or-GB is not separated from /s in table.
2025-01-09 17:44:24 -08:00
Jarek Kowalski
ef01650665 feat(server): emit notifications as JSON to stderr when running under KopiaUI (#4322)
* feat(server): emit notifications as JSON to stderr when running under KopiaUI

* added tests
2024-12-30 15:06:11 -08:00
Jarek Kowalski
d6b9254a4c feat(notifications): emit snapshot report notifications in the UI/server (#4323)
* feat(notifications): emit snapshot report notifications in the UI/server

* added test

* fixed data race
2024-12-30 10:59:11 -08:00
Jarek Kowalski
c1757a0c67 feat(general): misc notifications improvements (#4319)
* feat(general): various notifications improvements

* added API to test notification profiles
* added --http-header to webhook notification configuration
* refactored configuration to always apply defaults before persisting options in the repository
* added 'notification profile show --profile-name=X' command

* more tests

* more test coverage

* report notification code coverage
2024-12-29 09:50:20 -08:00
Jarek Kowalski
b60cac4860 fix(cli): fixed v0.18.0 failures using v0.17.0-generated config (#4255)
This was caused by the client using key derivation algorithm
from a config file (which did not have it when it was generated
using old version of Kopia).

Fixes #4254
2024-11-17 10:15:00 -08:00
Jarek Kowalski
9cb940334d feat(cli): added --send-snapshot-report flag to 'snapshot create' (#4252) 2024-11-16 11:51:08 -08:00
Jarek Kowalski
eb1cf64c27 chore(ci): upgraded linter to 1.62.0 (#4250) 2024-11-16 07:16:50 -08:00
Jarek Kowalski
f73887f4d6 feat(cli): improved snapshot reports (#4244) 2024-11-15 22:09:07 -08:00
Jarek Kowalski
b874bb8b9b feat(cli): send general error notifications only if the standard output is not a terminal (#4245) 2024-11-15 18:00:09 -08:00
Jarek Kowalski
afb85cbb34 feat(cli): send error notifications and snapshot reports (#4233)
* feat(cli): send error notifications and snapshot reports

Notifications will be sent to all configured notification profiles
according to their severity levels.

The following events will trigger notifications:

- Snapshot is created (CLI only, severity >= report)
- Server Maintenance error occurs (CLI, server and UI, severity >= error)
- Any other CLI error occurs (CLI only, severity >= error).

A flag `--no-error-notifications` can be used to disable error notifications.

* added template tests

* improved time formatting in templates

* plumb through notifytemplate.Options

* more testing for formatting options

* fixed default date format to RFC1123
2024-11-11 17:53:50 -08:00
Eugene Sumin
f0541ab67e feat(cli): introduce adaptive estimation mechanism (#4218)
* Add rough estimation mechanism

* Extract data size estimation scan to standalone function

* Introduce estimation type flag

* Change signature of EstimatedDataSize

* Extract estimation logic and test it

* Adjust err handling in GetVolumeSizeInfo

* Make GetVolumeSizeInfo reusable

* Fix type issue for windows platform

* Use adaptive estimation with threshold
2024-11-04 17:31:09 -08:00
Julio López
9aadd9114c fix(cli): avoid memory bloat in benchmark encryption command (#4213)
Avoid memory bloat in `benchmark encryption` and `benchmark crypto` commands

Reuse the output buffer by resetting it between iterations.

Fixes #4210
2024-10-30 09:18:12 -07:00
Julio López
0e91261c3e fix(cli): allow running quick maintenance with epoch manager (#4198)
* allow running quick maintenance with epoch manager
* run full maintenance to cleanup logs
* separate logs maintenance set params test
2024-10-28 16:04:29 -07:00
blenderfreaky
a9e178edff feat(cli): add policy import/export commands to im-/export policies from/to json (#4020)
* feat(cli): add policy export command

* feat(cli): add policy import command

* chore(cli): remove unused policyTargetFlags in commandPolicyImport

* feat(cli): allow limiting which policies to import

* docs(cli): document policy import and export commands

* feat(cli): add policy import/export commands

* fix(cli): apply suggestions

* fix(general): unintentional commit

* feat(cli: add policy export tests

* feat(cli): add policy import tests

* feat(cli): add deleteOtherPolicies option for policy import

* docs(cli): stdin/stdout in policy import/export and --delete-other-policies flag

* chore(cli): fix linter issues

* fix(cli): fix newly introduced errors

* fix(cli): fix failing windows tests

* chore(cli): more test coverage for policy import/export

* fixed windows test

---------

Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
2024-10-28 01:36:12 +00:00
Julio López
c90495d809 fix(cli): hashing benchmark repeat (#4199)
Ref:
- #4181
2024-10-25 00:18:33 -07:00
Prasad Ghangal
3bf947d746 feat(repository): Metadata compression config support for directory and indirect content (#4080)
* Configure compressor for k and x prefixed content

Adds metadata compression setting to policy
Add support to configure compressor for k and x prefixed content
Set zstd-fastest as the default compressor for metadata in the policy
Adds support to set and show metadata compression to kopia policy commands
Adds metadata compression config to dir writer

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

* Pass concatenate options with ConcatenateOptions struct

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

* Move content compression handling to caller

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

* Move handling manifests to manifest pkg

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

* Correct const in server_test

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

* Remove unnecessary whitespace

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

* Disable metadata compression for < V2 format

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>

---------

Signed-off-by: Prasad Ghangal <prasad.ganghal@veeam.com>
2024-10-23 23:28:23 -07:00
Julio López
723583552a refactor(server): handle ErrServerClosed where it occurs (#4165)
Checks whether any of the `httpServer.Serve*()` calls returns
`ErrServerClosed`.

Handles `ErrServerClosed` inside the `startServerWithOptionalTLS` function
instead of propagating it up.  This means that `startServerWithOptionalTLS`
returns a nil error when the HTTP server is closed, so the caller does not need
to check for `ErrServerClosed`

No functional changes otherwise.
2024-10-15 21:40:19 -07:00
Julio López
2ca59394c1 refactor(cli): do not run auto-maintenance after a command fails (#4168) 2024-10-14 10:17:11 -07:00
Julio López
eb2ea5dddd test(server): speedup cert key generation in server tests (#4166)
Use shorter key size to speed up cert generation in TestServerStartInsecure.

Refactor: add const for default server-control username.
2024-10-10 10:22:34 -07:00
Jarek Kowalski
c0bd372d29 feat(cli): support for defining notification profiles and templates via CLI (#4034)
* feat(cli): support for defining notification profiles via CLI

Profile management:

```
$ kopia notification profile configure email \
    --profile-name=X \
    --smtp-server=smtp.gmail.com \
    --smtp-port=587 \
    --smtp-username=X \
    --smtp-password=X \
    --mail-from=X \
    --mail-to=X \
    --format=html|txt \
    [--send-test-notification]

$ kopia notification profile configure pushover --profile-name=X \
    --user-key=X \
    --app-token=X \
    --format=html|txt \
    [--send-test-notification]

$ kopia notification profile configure webhook --profile-name=X \
    --endpooint=http://some-address:port/path \
    --method=POST|PUT \
    --format=html|txt \
    [--send-test-notification]

$ kopia notification profile test --profile-name=X

$ kopia notification profile delete --profile-name=X

$ kopia notification profile list
```

Template management:

```
$ kopia notification template show X

$ kopia notification template set X \
   --from-stdin | --from-file=X | --editor

$ kopia notification template remove X

$ kopia notification template list

```

Implements #1958

* additional refactoring for testability, various naming tweaks
2024-10-06 16:28:39 +00:00
Julio López
63f227386f refactor(general): levarage stdlib's context.WithoutCancel(ctx) (#4159)
Removes `internal/ctxutil` package with equivalent implementation
2024-10-06 09:05:26 -07:00
Julio López
961a39039b refactor(general): use errors.New where appropriate (#4160)
Replaces 'errors.Errorf\("([^"]+)"\)' => 'errors.New("\1")'
2024-10-05 19:05:00 -07:00
Mike McKay-Dirden
1bceb7155e feat(providers): GCS immutability (#4134)
- Allow blob `Put/ExtendBlobRetention`
- PITR support
- PITR/versioning tests
2024-09-26 21:46:25 -07:00
Nick
d57d3030cd Snapshot verify takes snapshot ID arguments (#4121)
Snapshot verify can now accept a list of one or more snapshot IDs (manifest IDs) to be used as the subject(s) of the snapshot verify operation.

Added a unit test that ensures only the requested snapshots are verified when their IDs are provided.

Now in addition to the existing --source, --file-id, and --directory-id flags, which work the same, the user can provide snapshot IDs as args:

kopia snapshot verify <snapID> <snapID> <snapID>
2024-09-20 14:42:53 -07:00
Jarek Kowalski
8690f7a198 feat(cli): added option to configure maintenance listing parallelism (#4085)
Ref: #4038
2024-09-05 15:12:18 -07:00
Jarek Kowalski
ac446a2d16 chore(ci): upgraded linter to 1.60.3 (#4086)
* silenced several 'gosec' findings
2024-09-03 21:29:56 -07:00
Julio López
5dbc8a478a refactor(general): minor cleanups (#4003)
Followups to #3655

* wrap fs.Reader
* nit: remove unnecessary intermediate variable
* nit: rename local variable
* cleanup: move restore.Progress interface to cli pkg
* move cliRestoreProgress to a separate file
* refactor(general): replace switch with if/else for clarity
  Removes a tautology for `err == nil`, which was guaranteed
  to be true in the second case statement for the switch.
  Replacing the switch statement with and if/else block is clearer.
* initialize restoreProgress in restore command
* fix: use error.Wrapf with format string and args


Simplify SetCounters signature:

Pass arguments in a `restore.Stats` struct.
  `SetCounters(s restore.Stats)`
Simplifies call sites and implementation.
In this case it makes sense to pass all the values
using the restore.Stats struct as it simplifies
the calls.
However, this pattern should be avoided in general
as it essentially makes all the arguments "optional".
This makes it easy to miss setting a value and simply
passing 0 (the default value), thus it becomes error
prone.
In this particular case, the struct is being passed
through verbatim, thus eliminating the risk of
missing a value, at least in the current state of
the code.
2024-08-27 09:42:58 -07:00
Julio López
d37de8316e refactor(general): generalize units package (#4075)
Generalize a couple of functions in the units package using generics.
This allows removing duplicate code and simplifying callers by removing unnecessary integer conversions.

Additional cleanups:

- make "/s" part of the Printf format string ;
- simplify setSizeMBParameter;
- generalize cli.maybeHumanReadable*` helpers;
- remove unneeded receiver in commandRepositorySetParameters helpers.
2024-08-26 17:26:32 -07:00
Julio López
948162dce5 refactor(general): minor miscellaneous cleanups (#4074)
Cleanups:

- use non-format variants of Log/Print with no additional args;
- fold in Fprintf call with no args into the following one;
- add missing arg placeholder in format strings;
- use require.Positive instead of Greater(..., 0);
- rename function to fillWithZeros to avoid collision with builtin clear;
- define type for context key to avoid collisions.
2024-08-25 22:10:46 -07:00
Julio López
9c5fc842a1 feat(cli): add server user set-password-hash command (#3974)
Objectives:
- Facilitate the generation of valid password hashes that can be used with
  the `server user --user-password` CLI command.
- Encapsulate implementation details of password hashing in
  the `user` package.

Adds a new `server user hash-password` CLI command to generate the
hash from a supplied password.

Modifies the `server user set/add --user-password-hash` CLI command
to accept the password hash generated using the `hash-password`
command.

Adds `GetNewProfile(ctx, rep, username)` helper to move implementation
details to the `user` package.

Includes CLI and unit tests.

Cleans up and removes unused functions.
2024-07-11 19:29:06 -07:00
Julio López
ae9f1c734b fix(server): ensure repo disconnection on server start exit (#3980)
Ensure repository disconnection at the end of the `server start` CLI command.
This was caught as a result of fixing the test below.

Fix `TestServerStartInsecure`:
Remove `--password=xxx` parameter, which causes a server start failure
due to incorrect repo password, and not for the case being checked,
which is the lack of the `--insecure` parameter.

Update test comments accordingly.
2024-07-11 18:51:12 -07:00
Julio López
c262998173 chore(general): misc cleanups (#3982)
* chore(general): remove unused `Behavior` type
* chore(test): leverage `testutil.ServerParameters` in server test
2024-07-11 17:18:44 -07:00
Julio López
1f9f9a1846 chore(general): use non-formatting log variants when there is no formatting (#3931)
Use non-formatting logging functions for message without formatting.
For example, `log.Info("message")` instead of `log.Infof("message")`

Configure linter for printf-like functions
2024-06-18 23:13:17 -07:00
Jarek Kowalski
e36fa78385 feat(snapshots): added support for per-directory splitter overrides (#3887)
This is useful when backing up directories that have giant files aligned
at MiB boundary, such as VM disk backups, etc.
2024-06-07 13:42:15 -07:00
Jarek Kowalski
fcb8197f3f chore(ci): upgraded linter to 1.59.0 (#3883) 2024-05-29 20:31:57 -07:00
Eugene Sumin
2b92388286 refactor(general): Increase restore progress granularity (#3655)
When restoring huge file(s), the progress reporting is done in a bit
weird way:

```
kopia_test % kopia snapshot restore ka2084d263182164b6cf3456668e6b6da /Users/eugen.sumin/kopia_test/2
Restoring to local filesystem (/Users/eugen.sumin/kopia_test/2) with parallelism=8...
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.6 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.6 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.6 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.5 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.5 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.5 MB/s (100.0%) remaining 0s.
Restored 5 files, 1 directories and 0 symbolic links (5.4 GB).
```
In fact, the amount of restored data is dumped when particular file
completely restored.

This PR contains the least invasive change, which allows us to see
progress update while file is downloaded from object storage.
```
Restoring to local filesystem (/Users/eugen.sumin/kopia_test/55) with parallelism=8...
Processed 2 (3.1 MB) of 5 (1.8 GB).
Processed 4 (459.6 MB) of 5 (1.8 GB) 270.3 MB/s (25.2%) remaining 4s.
Processed 4 (468.7 MB) of 5 (1.8 GB) 269 MB/s (25.7%) remaining 4s.
Processed 4 (741.6 MB) of 5 (1.8 GB) 269 MB/s (40.6%) remaining 3s.
Processed 4 (1.1 GB) of 5 (1.8 GB) 280 MB/s (57.6%) remaining 2s.
Processed 5 (1.4 GB) of 5 (1.8 GB) 291.1 MB/s (75.2%) remaining 1s.
Processed 5 (1.4 GB) of 5 (1.8 GB) 289.8 MB/s (75.6%) remaining 1s.
Processed 5 (1.6 GB) of 5 (1.8 GB) 270.2 MB/s (85.3%) remaining 0s.
Processed 5 (1.7 GB) of 5 (1.8 GB) 256.3 MB/s (95.0%) remaining 0s.
Processed 6 (1.8 GB) of 5 (1.8 GB) 251 MB/s (100.0%) remaining 0s.
Processed 6 (1.8 GB) of 5 (1.8 GB) 251 MB/s (100.0%) remaining 0s.
Restored 5 files, 1 directories and 0 symbolic links (1.8 GB).
```

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2024-05-10 09:47:13 -07:00