Commit Graph

786 Commits

Author SHA1 Message Date
Julio Lopez
6650223291 refactor(general): cleanup observabilityFlags (#4852)
- nit: rename function to repositoryAction.
  It always calls the action with a repository
- move allocator stats functionality to observability
- rename observability functions to start/stop. They
  start and stop more than just the metrics services.
- rename field to c.enablePProfEndpoint for clarity.
- add observability run function to make it explicit
  where start and stop are called.
2025-09-28 23:59:27 -07:00
Julio Lopez
a0a4a7ba18 refactor(cli): ensure auto-maintenance errors are propagated (#4851)
Ensure auto-maintenance errors are propagated.
This enables sending notifications for failed "auto-maintenances".

Preserve action callback error when closing the repository fails.
2025-09-28 23:55:15 -07:00
Jarek Kowalski
0f7253eb66 feat(general): rewrote content logs to always be JSON-based and reorganized log structure (#4822)
This is a breaking change to users who might be using Kopia as a library.

### Log Format

```json
{"t":"<timestamp-rfc-3389-microseconds>", "span:T1":"V1", "span:T2":"V2", "n":"<source>", "m":"<message>", /*parameters*/}
```

Where each record is associated with one or more spans that describe its scope:

* `"span:client": "<hash-of-username@hostname>"`
* `"span:repo": "<random>"` - random identifier of a repository connection (from `repo.Open`)
* `"span:maintenance": "<random>"` - random identifier of a maintenance session
* `"span:upload": "<hash-of-username@host:/path>"` - uniquely identifies upload session of a given directory
* `"span:checkpoint": "<random>"` - encapsulates each checkpoint operation during Upload
* `"span:server-session": "<random>"` -single client connection to the server
* `"span:flush": "<random>"` - encapsulates each Flush session
* `"span:maintenance": "<random>"` - encapsulates each maintenance operation
* `"span:loadIndex" : "<random>"` - encapsulates index loading operation
* `"span:emr" : "<random>"` - encapsulates epoch manager refresh
* `"span:writePack": "<pack-blob-ID>"` - encapsulates pack blob preparation and writing

(plus additional minor spans for various phases of the maintenance).

Notable points:

- Used internal zero allocation JSON writer for reduced memory usage.
- renamed `--disable-internal-log` to `--disable-repository-log` (controls saving blobs to repository)
- added `--disable-content-log` (controls writing of `content-log` files)
- all storage operations are also logged in a structural way and associated with the corresponding spans.
- all content IDs are logged in a truncated format (since first N bytes that are usually enough to be unique) to improve compressibility of logs (blob IDs are frequently repeated but content IDs usually appear just once).

This format should make it possible to recreate the journey of any single content throughout pack blobs, indexes and compaction events.
2025-09-27 17:11:13 -07:00
Julio Lopez
6e5c8ef4e7 chore(general): minor cleanups (#4842)
* Remove unused return value from ListIndexBlobInfos
* Unexport index.Builder.buildStable
* Remove unnecessary OneUseBuilder.BuildStable
* Remove unnecessary `BuilderCreator` interface,
  use a function type instead.
* Cleanup comment
2025-09-24 12:11:22 -07:00
Julio Lopez
aaae7e8004 fix(cli): enable quick maintenance by default on repo creation (#4840)
Avoid disabling quick maintenance on repo creation when the
epoch manager is available.
2025-09-23 17:27:25 -07:00
Julio Lopez
fb7ecee534 refactor(general): move content verify functionality to the content package (#4827)
Move general functionality from the `content verify` CLI
command implementation to helpers in the content package.

The primary motivation is to allow reusing the content
verification functionality during maintenance.

A separate followup change also extends content
verification to include additional stats useful for
debugging repository corruptions.

Overview of the changes:
- Relocation of the content verification functionality
  to the content package. The entry point is
  content.WriteManager.VerifyContents.
  This is primarily code movement with no functional changes.
- Addition of unit tests for the content verification functionality
  by exercising content.WriteManager.VerifyContents.
- Minor functional change: changing the logging level from
  Error to Warn for the "inner loop" error messages. This allows
  filtering out these messages if needed, while still observing the
  error message that is logged for the overall operation.
2025-09-17 21:44:25 -07:00
Julio Lopez
24af54e55e refactor(cil): rename flag to --dangerous-commands (#4773) 2025-09-03 12:35:46 -07:00
Julio Lopez
9a42e9b8a5 refactor(general): miscellaneous cleanups (#4774)
Nits and cleanups:
- clarify log message to indicate the effect of advancing the deletion watermark;
- add omitzero JSON tag to appropriate fields in snapshot.Manifest struct;
- use maps.Clone instead of explicit loop;
- rename function to IterateUnreferencedPacks for clarity;
- use atomic.Int32 type;
- move a continue check to the beginning of the loop, no actual
  work / side effects were performed before the check;
- reduce type requirement in blob.ReadBlobMap
2025-08-20 17:49:00 -07:00
Julio Lopez
c7678a24cd fix(cli): additional safeguard dangerous commands (#4767) 2025-08-17 13:06:03 -07:00
Julio Lopez
194acc15e5 refactor(cli): deprecate dangerous repo repair sub-command (#4766) 2025-08-16 20:41:29 -07:00
Julio Lopez
6142059575 refactor(cli): reword message for dangerous commands (#4765) 2025-08-16 20:03:31 -07:00
Julio Lopez
70032f8498 refactor(cli): remove deprecated no-op flags (#4764)
Removes the following flags:
--caching: no-op
--list-caching: no-op
--enable-jaeger-collector: errors out when specified.

Also removes no-longer-used `deprecatedFlag` function.
2025-08-16 19:44:36 -07:00
Julio Lopez
3ae1c0e225 feat(providers): Azure Federated Identity support (#4728)
Add authentication support for Azure Federated Identity (AFI)

Authored-by: @alisonb-veeam
Authored-by: Alison Burgess <a.burgess@veeam.com>
2025-07-19 12:24:03 -07:00
Julio Lopez
3a38279bcd fix(providers): Azure client cert env var (#4726) 2025-07-17 21:47:57 -07:00
Julio Lopez
692c1f465b refactor(providers): rename Options.ClientCertificate for clarity (#4724)
* refactor(providers): rename Options.ClientCertificate for clarity
* rename AZURE_STORAGE_CLIENT_CERTIFICATE environment variable
2025-07-17 00:13:05 -07:00
Ankit Jain
35089a4894 feat(restore): added support for deleting extra files in restore path (#4725) 2025-07-17 07:10:32 +00:00
Julio Lopez
b6ad91dcd3 refactor(general): rename variable to humanReadable for consistency (#4709) 2025-07-01 20:42:10 -07:00
Kian Kasad
f40fe88254 feat(cli): human-readable sizes for kopia ls (#4696) 2025-07-01 18:46:26 -07:00
Nick
ed304e6c12 feat(snapshots): Add periodic JSON progress output to snapshot verify (#4645)
- Add read stats to snapshot verifier output
- Add periodic JSON progress output.
- Refactor the use of directory summary.
- Use stats mutex for all stats.
- Add processedBytes to the snapshot verify output
- Output more frequently, when bytes processed changes
2025-06-24 15:15:59 -07:00
Nick
b2b051417f Add JSON output flag for snapshot verify (#4644) 2025-06-24 13:20:09 -07:00
Nathan Baulch
19d92613a6 chore(general): typos (#4659) 2025-06-10 17:24:14 -07:00
Kian Kasad
e5e64e936e fix(cli): fix path printed by "kopia snapshot fix" commands (#4638)
The `dirRelativePath` variable is actually the path to the file being
checked, but was treated as if it was the path to the parent directory,
causing the filename to be duplicated in log messages.
2025-06-04 22:15:53 -07:00
Julio Lopez
d91a5a8f94 chore(general): enable forcetypeassert linter (#4624)
- enable `forcetypeassert` linter in non-test files
- add `//nolint` annotations
- add `testutil.EnsureType` helper for type assertions
- enable `forcetypeassert` linter in test files
2025-05-31 23:17:38 -07:00
Julio Lopez
ab1f62e3ad refactor(general): misc cleanups (#4615)
- nit: rename var to packCountByPrefix
- leverage impossible package
- use maps.Clone
- unexport indirectObjectID
- unexport compressed
- rename function to flushBufferLocked
- add checklocks annotations to functions that must be called under w.mu
2025-05-29 08:26:55 -07:00
Julio Lopez
3d4c5f8f9e refactor(general): s/interface{}/any/ (#4614) 2025-05-29 06:07:49 +00:00
Jarek Kowalski
1ee24977ce fix(notifications): fixed notification severities on snapshot creation (#4604) 2025-05-25 16:25:35 -07:00
Donatas Abraitis
67d8399127 fix(cli): Fix crash when doing kopia policy show <path> (#4560)
```
~# ./kopia policy show /home/donatas/tests
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x18b7b84]

goroutine 1 [running]:
github.com/kopia/kopia/cli.appendOSSnapshotPolicyRows({0xc005759008, 0x26, 0x55}, 0xc005754600?, 0xc005764008)
	/home/donatas/projects/kopia/cli/command_policy_show.go:490 +0x44
github.com/kopia/kopia/cli.printPolicy(0xc0000f5d48, 0xc005754600, 0xc005764008)
	/home/donatas/projects/kopia/cli/command_policy_show.go:135 +0x5e5
github.com/kopia/kopia/cli.(*commandPolicyShow).run(0xc0000f5d10, {0x2311ef8, 0xc0002e5320}, {0x7fb83829f3d0, 0xc0052eeb00})
	/home/donatas/projects/kopia/cli/command_policy_show.go:46 +0x18d
github.com/kopia/kopia/cli.(*App).repositoryReaderAction.func1({0x2311ef8?, 0xc0002e5320?}, {0x7fb83829f3d0?, 0xc0052eeb00?})
	/home/donatas/projects/kopia/cli/app.go:477 +0x2b
github.com/kopia/kopia/cli.(*App).repositoryReaderAction.(*App).maybeRepositoryAction.func2({0x2311ef8, 0xc0002e5320})
	/home/donatas/projects/kopia/cli/app.go:571 +0xbd
github.com/kopia/kopia/cli.(*App).repositoryReaderAction.(*App).maybeRepositoryAction.(*App).baseActionWithContext.func3.1.1()
	/home/donatas/projects/kopia/cli/app.go:554 +0x6e
github.com/kopia/kopia/cli.(*profileFlags).withProfiling(0x0?, 0xc0004a09c0?)
	/home/donatas/projects/kopia/cli/profile.go:45 +0x2b9
github.com/kopia/kopia/cli.(*App).repositoryReaderAction.(*App).maybeRepositoryAction.(*App).baseActionWithContext.func3.1({0x2311ef8?, 0xc0002e5320?})
	/home/donatas/projects/kopia/cli/app.go:549 +0x50
github.com/kopia/kopia/cli.(*App).runAppWithContext.func1(0xc0000f48d0?, 0xc0000f4808, 0xc0000efd30, {0x2311ef8, 0xc0002e52f0})
	/home/donatas/projects/kopia/cli/app.go:521 +0x186
github.com/kopia/kopia/cli.(*App).runAppWithContext(0xc0000f4808, 0xc0002b88f0, 0xc0000efd30)
	/home/donatas/projects/kopia/cli/app.go:522 +0x1a9
github.com/kopia/kopia/cli.(*App).repositoryReaderAction.(*App).maybeRepositoryAction.(*App).baseActionWithContext.func3(0x22e2801?)
	/home/donatas/projects/kopia/cli/app.go:548 +0x3c
github.com/alecthomas/kingpin/v2.(*actionMixin).applyActions(...)
	/home/donatas/go/pkg/mod/github.com/alecthomas/kingpin/v2@v2.4.0/actions.go:28
github.com/alecthomas/kingpin/v2.(*Application).applyActions(0xc0001b8500?, 0xc000453050)
	/home/donatas/go/pkg/mod/github.com/alecthomas/kingpin/v2@v2.4.0/app.go:568 +0xd0
github.com/alecthomas/kingpin/v2.(*Application).execute(0xc0001b8500, 0xc000453050, {0xc0004b6d80, 0x2, 0x2})
	/home/donatas/go/pkg/mod/github.com/alecthomas/kingpin/v2@v2.4.0/app.go:398 +0x65
github.com/alecthomas/kingpin/v2.(*Application).Parse(0xc0001b8500, {0xc00014e090?, 0xc0001b8500?, 0x22e8c80?})
	/home/donatas/go/pkg/mod/github.com/alecthomas/kingpin/v2@v2.4.0/app.go:230 +0x14a
main.main()
	/home/donatas/projects/kopia/main.go:77 +0x1cc
```

This is happening if we apply this before:

```
~# ./kopia policy set --inherit=false --clear-ignore /home/donatas/tests
```

Default value for `p.OSSnapshotPolicy.VolumeShadowCopy.Enable` is nil, so it's not set
which is inherited from a global one and is 0 (never).

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2025-05-12 23:34:28 +00:00
Julio Lopez
5c11822d16 chore(cli): rename function to setListBlobsParallelismFromFlags (#4564) 2025-05-09 23:01:18 -07:00
Rohit-BM18
12409c7279 feat(cli): --stats-only flag for the diff command (#4557)
Adds a `--stats-only` flag to the `diff` command to reduce
output verbosity.
When `kopia diff` is invoked with the `--stats-only` flag it
only outputs the aggregate statistics of changes.
2025-05-05 20:59:52 -07:00
Julio Lopez
14bcbcb07e fix(cli): add flag for rclone's startup timeout (#4543)
- add flag for rclone startup timeout
- rename const
2025-05-01 15:37:22 -07:00
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