Commit Graph

696 Commits

Author SHA1 Message Date
NickIAm
3da0473219 fix(cli): restore objects with I prefix fails (#3062)
* Fix restoring objects with I prefix
set default of snapshot-time to 'latest' as noted in the help output

* Change test of restore to check it works without a time given
This is because --snapshot-time defaults to "latest" now.
2024-03-26 21:03:46 -07:00
Jarek Kowalski
7278f570e2 chore(ci): upgraded linter to 1.57.1 (#3753) 2024-03-25 22:20:38 -07:00
Nick
8c081add53 chore(server): Disable legacy API by default (#3730) 2024-03-13 11:11:09 -07:00
Sirish Bathina
ddcdfdb55a changes for switching key derivation (#3725) 2024-03-13 00:34:46 +00:00
Jarek Kowalski
29cd545c33 chore(ci): upgrade linter to 1.56.2 (#3714) 2024-03-09 10:39:11 -08:00
Jarek Kowalski
ba54dc3db2 build(deps): upgrade Prometheus and reacted to breaking change (#3705) 2024-03-04 20:59:59 -08:00
Jarek Kowalski
524ffaf4b8 refactor(repository): added context to potentially blocking repository methods (#3654)
Primarily for wiring a context.Context to a call to content.Manager.refresh,
which was using a detached context.
2024-02-20 14:48:23 -08:00
Julio López
cd776d8534 refactor(cli): minor cleanups in server start (#3637)
* refactor(cli): discard content when server reads stdin
* nit: use log.Info
2024-02-07 17:40:27 -08:00
Julio López
4bec8e9bf8 refactor(cli): server shutdown (#3608)
* refactor(cli): add shutdownHTTPServer helper
* nit: reword comment to clarify

---------

Authored-by: Aaron Alpar <aaron.alpar@veeam.com>
2024-02-07 05:57:31 +00:00
Julio López
ed9d0c281e refactor(cli): miscellaneous code simplifications (#3607)
* refactor(cli): code simplification in onTerminate callback function
* refactor(test): quote strings, via %q, in assertion failure message

---------

Authored-by: Aaron Alpar <aaron.alpar@veeam.com>
2024-02-06 21:37:51 -08:00
Aaron Alpar
cb455c699a fix(snapshots): Fixup for #3624. Shadow copy seems to extend time for snapshots. (#3625)
* fixup for ticket #3624

* skip, now broken, test

* lint fixup.  how did this get into the repository in the first place?!

* elide shadow copy tests until fixup.  do not allow release

* fixup for shadow copy mode from @small

* Update cli/command_policy_set_os_snapshot_test.go

* restore old tests

* fixup typo

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2024-02-07 00:28:20 +00:00
Maxim Khitrov
f62ef51700 feat(snapshots): Implement volume shadow copy support on Windows (#3543)
* Implement volume shadow copy support on Windows

* Update go-vss version

* Fix unused variables

* Rename upload_actions*.go files

* Move vss settings to a separate policy section

* Handle existing shadow copy root

* Fix tests

* Fix lint issues

* Add cli policy test

* Add OS snapshot integration test

* Add GitHub Actions VSS test

* Fix "Incorrect function" error for root VSS snapshots

* Rename err to finalErr in createOSSnapshot

* Add OSSnapshotMode test

* Do not modify paths starting with \\?\ on Windows

* Allow warning messages in logfile tests

* Fix ignorefs not wrapping OS snapshot directory

* Retry VSS creation if another op was in progress

---------

Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
2024-02-03 21:44:41 -08:00
Jarek Kowalski
a8e4d50600 build(deps): upgraded linter to v1.55.2, fixed warnings (#3611)
* build(deps): upgraded linter to v1.55.2, fixed warnings

* removed unsafe hacks with better equivalents

* test fixes
2024-02-02 23:34:34 -08:00
Jarek Kowalski
c478141bbf refactor(repository): refactor internal/repolog package to support writing metrics in the future (#3610)
* renamed internal/repolog to internal/repodiag

* refactored initialization

* additional tests

* linter fixes
2024-02-02 22:19:24 -08:00
Julio Lopez
c56d330383 feat(cli): handle SIGTERM (#3562)
* refactor(test): allow signaling sub-process from testenv.CLIExeRunner
* test(cli): add test for handling SIGTERM
* feat(general): catch and process SIGTERM for termination
* refactor(cli): rename function cli.App.onTerminate
  Renames function from onCtrlC to a more generic onTerminate
2024-01-11 18:02:31 -08:00
André Schröder
7bfe8cb6db fix(cli): print errors during processing in red (#3514)
My backup had a fatal error. The end of the log looked like this:

```
Created snapshot with root k5ab05dd5a8aaf9da8a6a822abd0afabb and ID 04caa6e10f4e2866a74492a4162ea943 in 2m44s
WARN Ignored 943 error(s) while snapshotting root@tower:/.
 ERROR Found 1 fatal error(s) while snapshotting root@tower:/.
```

Note that "WARN" is yellow and "ERROR" is red.

Since I got a fatal error, I wanted to check what the fatal error was.
Because "ERROR" in the lines above is red, I expected the fatal error in
the kopia log to also be red, but it was yellow like the non-fatal
errors. This was unexpected to me.

Also note that I have lots of "! Ignored error when processing" in the
kopia log because I also backup Docker containers, so right now it is
not easy to find the fatal error among the non-fatal errors.
2023-12-18 09:50:33 -08:00
Mike McKay-Dirden
d4a380f7c1 feat(repository): Add Azure PIT support (#3407) 2023-11-28 14:52:49 -08:00
Aaron Alpar
fd55f5498d chore(general): correct spelling 2023-11-28 20:42:25 +00:00
Mike McKay-Dirden
fde0dfd3d3 fix(cli): Don't return error when parameters unchanged (#3411)
* don't return error when permissions unchanged
* remove logging since it only happens for a couple edge cases
2023-11-01 11:00:01 -07:00
Jarek Kowalski
7ee30b76bb fix(repository): fixed handling of content.Info (#3356)
* fix(repository): fixed handling of content.Info

Previously content.Info was an interface which was implemented by:

* index.InfoStruct
* index.indexEntryInfoV1
* index.indexEntryInfoV2

The last 2 implementations were relying on memory-mapped files
which in rare cases could be closed while Kopia was still processing
them leading to #2599.

This changes fixes the bug and strictly separates content.Info (which
is now always a struct) from the other two (which were renamed as
index.InfoReader and only used inside repo/content/...).

In addition to being safer, this _should_ reduce memory allocations.

* reduce the size of content.Info with proper alignment.

* pr feedback

* renamed index.InfoStruct to index.Info
2023-10-14 10:34:15 -07:00
Jarek Kowalski
c8d1b221e2 refactor(repository): added fs.DirectoryIterator (#3365)
* refactor(repository): added fs.DirectoryIterator

This significantly reduces number of small allocations while
taking snapshots of lots of files, which leads to faster snapshots.

```
$ runbench --kopia-exe ~/go/bin/kopia \
   --compare-to-exe ~/go/bin/kopia-baseline --min-duration 30s \
   ./snapshot-linux-parallel-4.sh
DIFF duration: current:5.1 baseline:5.8 change:-13.0 %
DIFF repo_size: current:1081614127.6 baseline:1081615302.8 change:-0.0 %
DIFF num_files: current:60.0 baseline:60.0 change:0%
DIFF avg_heap_objects: current:4802666.0 baseline:4905741.8 change:-2.1 %
DIFF avg_heap_bytes: current:737397275.2 baseline:715263289.6 change:+3.1 %
DIFF avg_ram: current:215.0 baseline:211.5 change:+1.6 %
DIFF max_ram: current:294.8 baseline:311.4 change:-5.3 %
DIFF avg_cpu: current:167.3 baseline:145.3 change:+15.1 %
DIFF max_cpu: current:227.2 baseline:251.0 change:-9.5 %
```

* changed `Next()` API

* mechanical move of the iterator to its own file

* clarified comment

* pr feedback

* mechanical move of all localfs dependencies on os.FileInfo to a separate file

* Update fs/entry.go

Co-authored-by: ashmrtn <3891298+ashmrtn@users.noreply.github.com>

* Update fs/entry_dir_iterator.go

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

* doc: clarified valid results from Next()

---------

Co-authored-by: ashmrtn <3891298+ashmrtn@users.noreply.github.com>
Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2023-10-05 02:45:44 +00:00
PhracturedBlue
66027721e0 feat(server): improve scheduler algorithm to run missed snapshots (#3323)
* Improve RunMissed algorithm to work better with Cron and to give more predictable results for time-of-day rules

* Add a RunMissed test for multiple times-of-day

* add variable to improve code-readability

* Fix test after rebase
2023-10-04 19:31:28 -07:00
Christoph Anderson
b0181162b6 fix(cli): Fixing help text when editing policies externally (#3357)
* Fix policy target name in help text
---------

Co-authored-by: lupusA <lupuapps@gmail.com>
2023-09-26 18:31:47 -07:00
PhracturedBlue
bcb07da5f3 fix(cli): Convert --run-missed from bool to Enum (#3337) 2023-09-22 10:18:19 -07:00
PhracturedBlue
0f608ff18c test(cli): Attempt to fix socket-activated tests (#3318) 2023-09-18 21:47:39 -07:00
PhracturedBlue
42fab43a98 feat(cli): Added option to allow running missed snapshots on Kopia start (#3311) 2023-09-17 16:37:11 +00:00
Jarek Kowalski
af1550ad81 feat(server): reduce server refreshes of the repository (#3265)
* feat(server): reduce server refreshes of the repository

Previously each source would refresh itself from the repository
very frequently to determine the upcoming snapshot time. This change
refactors source manager so it does not own the repository connection
on its own but instead delegates all policy reads through the server.

Also introduces a new server scheduler that is responsible for
centrally managing the snapshot schedule and triggering snapshots
when they are due.

* Update cli/command_server_start.go

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

* Update internal/server/server.go

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

* Update internal/server/server_maintenance.go

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

* pr feedback

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2023-09-15 12:08:35 -07:00
PhracturedBlue
741fbd4442 feat(server): Add socket-activation support (#3283) 2023-09-10 19:46:28 -07:00
Jarek Kowalski
aa064bb442 fix(providers): fixed list/get caching with rclone providers (#3284)
Added improved providervalidation logic which tests for read-after-write
property between connections. The new test was failing before the change
and is now passing for Google Drive, OneDrive and DropBox.
2023-09-09 13:07:53 -07:00
Jarek Kowalski
06af162394 fix(cli): added output to indicate completion of snapshot verification (#3275) 2023-09-06 19:53:16 -07:00
Jarek Kowalski
b352305c9d feat(cli): added '--otlp-trace' flag that replaces Jaeger tracing with OTLP over gRPC (#3264)
Jaeger exporter support is now deprecated upstream, so we need to move
to OTLP. Fortunately Jaeger supports OTLP out of the box.
See https://www.jaegertracing.io/docs/1.48/deployment/

To configure the exporter, use environment variables as described in
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options
2023-09-04 19:48:28 -07:00
Jarek Kowalski
044db7593b feat(repository): apply retention policies server-side (#3249)
* feat(repository): apply retention policies server-side

This allows append-only snapshots where the client can never delete
arbitrary manifests and policies are maintained on the server.

The client only needs permissions to create snapshots in a given, which
automatically gives them permission to invoke the server-side method
for their own snapshots only.

* Update cli/command_acl_add.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/api_manifest.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/api_manifest.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/grpc_session.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

---------

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>
2023-09-02 18:23:21 -07:00
Jarek Kowalski
80423cf5f6 feat(server): fixed server logging file & console (#3262)
Previously some logs from a running server were only kept in memory
(including storage activity logs) which was confusing to many folks.

This changes the behavior so that logs are sent to their regular
(console/file) file locations in addition to the UI tasks.

Old behavior can be restored by adding `--no-persistent-logs` to
server.
2023-09-02 18:10:18 -07:00
Jarek Kowalski
fe55dcb6a2 feat(repository): added hard size limit to the on-disk cache (#3238)
* test(providers): added capacity limits to blobtesting.mapStorage

* refactor(general): added mutex map which dynamically allocates and releases named mutexes

* refactor(repository): refactored cache cleanup and limit enforcement

* refactor(repository): plumb through cache size limits in the repository

* feat(cli): added CLI options to set cache size limits

* unified flag setting and field naming

* Update cli/command_cache_set.go

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

* pr feedback

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2023-08-24 09:38:56 -07:00
PhracturedBlue
9237b29023 feat(server): add server support for unix domain sockets (#3216)
* Add server support for unix domain sockets

* Ensure socket path < 104 bytes for UDS test
2023-08-20 17:17:20 -07:00
Wenkai Yin(尹文开)
ad0b370c49 feat(providers): support for auth with Azure AD (#3131)
Add support for auth with Azure AD

Ref #2800

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2023-08-14 21:05:34 -07:00
Julio Lopez
22cba7003d refactor(cli): minor nits for observability flags (#3209)
Create directory in `.startMetrics` function.
Store file name prefix for metrics instead of final name.
2023-08-10 23:30:07 -07:00
Julio Lopez
8b8d4a574b feat(cli): save observability metric before exiting the process (#3201)
Objective: to facilitate capturing metrics for relatively short-lived kopia
executions.

Motivation: Currently, kopia allows a. exposing metrics via a Prometheus
exporter; and b. pushing metrics to a Prometheus gateway. In certain
scenarios, such as short lived executions, it is not possible to reliably
scrape the metrics from the exporter endpoint. And, while the pusher
approach would work, it requires starting a separate push gateway.

This change allows saving the metrics to a local file before kopia exists
by specifying the metrics output directory. For example,

`kopia --metrics-directory /tmp/kopia-metrics/ snapshot create ....`

In this case, after kopia exists, the `/tmp/kopia-metrics/` directory will
contain a file with a named of the form:
`<date>-<time>-<command_subcommand>.prom`
2023-08-10 00:40:45 +00:00
Julio Lopez
9f33f70eaa refactor(cli): break down observability.startMetrics() (#3196)
Motivation: reduce the function complexity for the linter, so additional
functionality can be added to `startMetrics()`

No functional changes.

Changes and transformations:
- Break down observability.startMetrics() into: maybeStartListener().
  maybeStartMetricsPusher() and maybeStartTraceExporter().
- Inline observabilityFlags.getExporter in maybeStartTraceExporter.
- Only create resource when exporter is non-nil.
- Simplify maybeStartListener: reduce indentation by returning early.
- Simplify maybeStartMetricsPusher: reduce indentation by returning early.
2023-08-06 11:44:31 -07:00
Julio Lopez
8246c2f177 chore(cli): correct typo in blob stats command (#3194) 2023-08-03 17:32:51 -07:00
NickIAm
a9c5a993c8 fix(cli): prevent duplicate snapshots when --all and a source path are given (#3067)
Adds a check for snapshot create when --all and a source path are
given simultaneously. Returns an error in this case since it would
otherwise create a  duplicate snapshot for the specified source path.

---

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2023-08-03 17:36:10 +00:00
Shikhar Mall
e1c44f7b2b feat(cli): new storage config input from file when creating a repo (#2756)
* feat(cli): new storage config input from file when creating a repo

* feat(cli): allow token from stdin

* fix(cli): improve code coverage

---------

Co-authored-by: Shikhar Mall <small@kopia.io>
2023-07-27 14:41:23 -07:00
Julio Lopez
d97679608e fix(cli): preserve error exit code when '--json' output is specified (#3163)
Changes kopia's behavior to match the exit code that would
have been returned when the `--json` flag was not specified.

`kopia snapshot create my/path --json` terminates with a 0
status code in cases where
`kopia snapshot create my/path` terminates with a
 non-zero exit code.

One such case is when there are permissions errors reading
files or directories to snapshot.

Adds end-to-end tests for snapshot create with '--json' flag
2023-07-20 06:39:40 -07:00
Jarek Kowalski
cb98abbc2c feat(snapshots): added ability to use cron expressions to schedule snapshots (#3149)
* feat(snapshots): added ability to use cron expressions to schedule snapshots

We use `github.com/hashicorp/cronexpr` to parse and evaluate expressions,
as documented in https://github.com/hashicorp/cronexpr#implementation

* upgrade ui

* pr feedback
2023-07-19 19:26:17 -07:00
Julio Lopez
c017d264b2 style(general): minor followups to #3041 (#3141)
* explicitly pass username and hostname instead of repo writer
* nit: name return values
2023-07-11 18:56:46 -07:00
Maxim Schuwalow
851fe6c193 feat(cli): add --override-source parameter to allow overriding source when snapshotting (#3041) 2023-07-11 17:34:30 -07:00
PhracturedBlue
42aad38540 feat(repository): Implement retention time extension on S3 buckets using Object Locks (#2179)
* Implement ability to extend retention time on S3 buckets using Object Locks
    * Move object-lock extension to maintenance.Params.
    * Use a default function for unsupported extensions instead of duplicating code
    * Fix potential lockup during object-lock extension
    * Fix race condition.  Add more code coverage
    * rebase to V3
* Add checks to prevent user from setting Retention Period  < Full Maintenance Interval

---------

Co-authored-by: Ashlie Martinez <ashmrtnz@alcion.ai>
2023-07-03 16:20:02 -07:00
Jarek Kowalski
cbc66f936d chore(ci): upgraded linter to 1.53.3 (#3079)
* chore(ci): upgraded linter to 1.53.3

This flagged a bunch of unused parameters, so the PR is larger than
usual, but 99% mechanical.

* separate lint CI task

* run Lint in separate CI
2023-06-18 13:26:01 -07:00
Jarek Kowalski
32193f72ea build(deps): update all golang dependencies (#3066) 2023-06-13 19:40:03 -07:00
Chetan Goti
0c28ffd265 docs(site): add more details for --prefix flag (#2961) 2023-04-21 00:12:50 -07:00