Commit Graph

108 Commits

Author SHA1 Message Date
Jarek Kowalski
51ef01dad5 refactor(snapshots): extracted snapshot.FindPreviousManifests() (#4453) 2025-04-13 04:08:03 +00:00
Jarek Kowalski
51de24dcff refactor(snapshots): refactored uploader into separate package (#4450) 2025-03-14 15:48:31 -07: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
f73887f4d6 feat(cli): improved snapshot reports (#4244) 2024-11-15 22:09:07 -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
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
fcb8197f3f chore(ci): upgraded linter to 1.59.0 (#3883) 2024-05-29 20:31:57 -07:00
Jarek Kowalski
29cd545c33 chore(ci): upgrade linter to 1.56.2 (#3714) 2024-03-09 10:39:11 -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
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
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
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
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
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
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
7bda16ab33 feat(repository): introduced fs.UTCTimestamp (#2343)
Fixes #2342
2022-09-02 10:35:59 -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
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
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
basldfalksjdf
a78dacc0d1 feat(snapshots): add option to ignore empty snapshots being saved (#2036)
* Add policy to ignore empty snapshots being saved

* Update command_snapshot_create.go

* Update source_manager.go

* Update command_snapshot_create.go

* Update source_manager.go

* fixes

* Update source_manager.go

* Update command_snapshot_create.go

* fix

* fix

Co-authored-by: Mehak  Satija <mehaksatija@Mehaks-MacBook-Pro.local>
Co-authored-by: Mehak  Satija <mehaksatija@Mehaks-MBP.hitronhub.home>
2022-06-13 03:41:08 +00:00
ashmrtn
ef8828a072 refactor(snapshots): Remove remaining internal uses of Readdir (#1986)
* Remove remaining internal uses of Readdir

* Remove old helpers and interface functions.

* Update tests for updated fs.Directory interface

* Fix index out of range error in snapshot walker

Record one error if an error occurred and it's not limiting errors

* Use helper functions more; exit loops early

Follow up on reviewer comments and reduce code duplication, use more
targetted functions like Directory.Child, and exit directory iteration
early if possible.

* Remove fs.Entries type and unused functions

Leave some functions dealing with sorting and finding entries in fs
package. This retains tests for those functions while still allowing
mockfs to access them.

* Simplify function return
2022-06-04 06:36:25 -07:00
Jarek Kowalski
e67f84e0ba chore(general): updated linter to 1.44.0 (#1681) 2022-01-25 21:21:13 -08:00
Jarek Kowalski
e870fcc4aa cli: reduce number of index blob writes in 'snapshot create --all' (#1574) 2021-12-11 10:08:34 -08:00
Jarek Kowalski
525720db95 cli: added 'snapshot pin' command (#1528) 2021-11-20 20:53:25 -08:00
Jarek Kowalski
dcff6c285d Added support for logging policies (#1472)
* policy: introduced OptionalBool - refactoring

* policy: added logging policy

* testing: added support for symlinks and modtime to mockfs

* logging: exposed NullLogger instance

* upload: emit debug logs according to logging policies

* cli: logging policy support
2021-11-06 10:06:05 -07:00
Jarek Kowalski
51fdbf2048 nit: minor log output cleanups (#1380) 2021-10-13 06:07:18 -07:00
Jarek Kowalski
6c5bf42d23 cli: changed 'kopia snapshot verify --verify-files-percent' to float (#1210)
* cli: changed 'kopia snapshot verify --verify-files-percent' to float

* cli: added 'kopia content verify --download-percent'
2021-07-24 13:04:50 -07:00
Benedikt McMullin
317d5c3419 force-hash: Allow fractional percentages (#1209)
* force-hash: Allow fractional percentages

Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
2021-07-24 09:45:46 -07:00
Jarek Kowalski
30ca3e2e6c Upgraded linter to 1.40.1 (#1072)
* tools: upgraded linter to 1.40.1

* lint: fixed nolintlint vionlations

* lint: disabled tagliatele linter

* lint: fixed remaining warnings
2021-05-15 12:12:34 -07:00
Jarek Kowalski
a461d767f7 cli: plumbed through 'textOutput' which controls stdout/stderr writers (#1053)
This is mostly for testability.
2021-05-06 20:26:35 -07:00
Jarek Kowalski
d2288c443f cli: major refactoring (#1046)
cli: major refactoring of how CLI commands are registered

The goal is to eliminate flags as global variables to allow for better
testing. Each command and subcommand and most sets of flags are now
their own struct with 'setup()' methods that attached the flags or
subcommand to the provided parent.

This change is 94.3% mechanical, but is fully organic and hand-made.

* introduced cli.appServices interface which provides the environment in which commands run
* remove auto-maintenance global flag
* removed globals in memory_tracking.go
* removed globals from cli_progress.go
* removed globals from the update_check.go
* moved configPath into TheApp
* removed remaining globals from config.go
* refactored logfile to get rid of global variables
* removed 'app' global variable
* linter fixes
* fixed password_*.go build
* fixed BSD build
2021-05-03 10:28:00 -07:00
Sirish Bathina
dd41296f2a Tagging of kopia snapshots and listing of snapshots by tag (#1030) 2021-04-30 06:16:19 -07:00
Jarek Kowalski
f4347886b8 logging: simplified log levels (#954)
Removed Warning, Notify and Fatal:

* `Warning` => `Error` or `Info`
* `Notify` => `Info`
* `Fatal` was never used.

Note that --log-level=warning is still supported for backwards
compatibility, but it is the same as --log-level=error.

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-04-09 07:27:35 -07:00
Jarek Kowalski
74833cefcb cli: added standard --json flags to several commands (#910)
* cli: added standard --json flags to several commands

Fixes #272

* Update flag description

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-03-25 17:55:18 -07:00
Pavan Navarathna
3e76169921 Support for stdin streams (#862)
* Add StreamingFile interface
* unit test for virtualfs
* CLI: Snapshot create support for stdin sources
* Uploader support for fs.StreamingFile
* End to end test for stdin source snapshot
* upload test to improve coverage
2021-03-04 15:34:05 -08:00
Jarek Kowalski
23273af1cd snapshot: reworked error handling and added fail-fast option (#840)
Fixes #690

This is a breaking change for folks who are expecting snapshots to fail
quickly without writing a snapshot manifest in case of an error.

Before this change, any source read failure would cause the entire
snapshot to fail (and not write a snapshot manifest as a result),
unless `ignoreFileErrors` or `ignoreDirectoryErrors` was set.

The new behavior is to continue snapshotting remaining files and
directories (this can be disabled by passing `--fail-fast` flag or
setting `KOPIA_SNAPSHOT_FAIL_FAST=1` environment variable) and defer
returning an error until the very end.

After snapshotting we will always attempt to write the snapshot manifest
(except when the root of the snapshot itself cannot be opened). In case
of a fail-fast error, the manifest will be marked as 'partial' and
the directory tree will contain only partial set of files.

In case of any errors, the manifest (and each directory object) will
list the number if failures and no more than 10 examples of failed
files/directories along with their respective errors.

Once the snapshot is complete we will return non-zero exit code to the
operating system if there were any fatal errors during snapshotting.

With this change we are repurposing `ignoreFileErrors` and
`ignoreDirectoryErrors` to designate some errors as non-fatal.
Non-fatal errors are reported as warnings in the logs and will not
cause a non-zero exit code to be returned.
2021-02-17 10:29:01 -08:00
Pavan Navarathna
c964e244f0 Support for ignoring sources when using snapshot create --all (#804)
* Add manual field to SchedulingPolicy
* CLI: Set and show for policy with manual field
* CLI: Edit policy support for manual field
* Check manual when creating snapshot for all source
* End to end test for snapshot create all
* Add UI option for setting Manual field
2021-02-10 21:59:06 -08:00
Jarek Kowalski
fa7976599c repo: refactored repository interfaces (#780)
- `repo.Repository` is now read-only and only has methods that can be supported over kopia server
- `repo.RepositoryWriter` has read-write methods that can be supported over kopia server
- `repo.DirectRepository` is read-only and contains all methods of `repo.Repository` plus some low-level methods for data inspection
- `repo.DirectRepositoryWriter` contains write methods for `repo.DirectRepository`

- `repo.Reader` removed and merged with `repo.Repository`
- `repo.Writer` became `repo.RepositoryWriter`
- `*repo.DirectRepository` struct became `repo.DirectRepository`
  interface

Getting `{Direct}RepositoryWriter` requires using `NewWriter()` or `NewDirectWriter()` on a read-only repository and multiple simultaneous writers are supported at the same time, each writing to their own indexes and pack blobs.

`repo.Open` returns `repo.Repository` (which is also `repo.RepositoryWriter`).

* content: removed implicit flush on content manager close
* repo: added tests for WriteSession() and implicit flush behavior
* invalidate manifest manager after write session

* cli: disable maintenance in 'kopia server start'
  Server will close the repository before completing.

* repo: unconditionally close RepositoryWriter in {Direct,}WriteSession
* repo: added panic in case somebody tries to create RepositoryWriter after closing repository
  - used atomic to manage SharedManager.closed

* removed stale example
* linter: fixed spurious failures

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-01-20 11:41:47 -08:00
Jarek Kowalski
5e8e175cfa repo: refactored read/write methods of repo.Repository (#749)
Reader methods go to repo.Reader and write methods go to repo.Writer
Switched usage to new interfaces based on linter errors.
2021-01-04 21:33:12 -08:00
Jarek Kowalski
e03971fc59 Upgraded linter to v1.33.0 (#734)
* linter: upgraded to 1.33, disabled some linters

* lint: fixed 'errorlint' errors

This ensures that all error comparisons use errors.Is() or errors.As().
We will be wrapping more errors going forward so it's important that
error checks are not strict everywhere.

Verified that there are no exceptions for errorlint linter which
guarantees that.

* lint: fixed or suppressed wrapcheck errors

* lint: nolintlint and misc cleanups

Co-authored-by: Julio López <julio+gh@kasten.io>
2020-12-21 22:39:22 -08:00
Jarek Kowalski
eecd9d13c9 actions: Added --enable-actions flag (#737)
This can be specified at `repo create` or `repo connect` to enable
actions. By default actions are disabled to avoid security risks
associated with executing code.

Alternatively during `snapshot create` one can specify
`--force-enable-actions` or `--force-disable-actions`
2020-12-21 18:05:25 -08:00
Jarek Kowalski
4fd0bcf7dc cli: 'snapshot create' switched all stderr output to use logger (#663)
This allows 'kopia snap create --all --log-level=warning --no-progress'
to produce no console output unless an error is encountered.
2020-10-05 17:28:00 -07:00
Jarek Kowalski
29ce1819cb Added support for setting and changing repository client options (description, read-only, hostname, username) (#589)
* repo: refactored client-specific options (hostname,username,description,readonly) into new struct that is JSON-compatible with current config

* cli: added 'repository set-client' to configure parameters of connected repository

* cli: cleaned up 'repository status' output
2020-09-04 13:57:15 -07:00
Jarek Kowalski
1a8fcb086c Added endurance test which tests kopia over long time scale (#558)
Globally replaced all use of time with internal 'clock' package
which provides indirection to time.Now()

Added support for faking clock in Kopia via KOPIA_FAKE_CLOCK_ENDPOINT

logfile: squelch annoying log message

testenv: added faketimeserver which serves time over HTTP

testing: added endurance test which tests kopia over long time scale

This creates kopia repository and simulates usage of Kopia over multiple
months (using accelerated fake time) to trigger effects that are only
visible after long time passage (maintenance, compactions, expirations).

The test is not used part of any test suite yet but will run in
post-submit mode only, preferably 24/7.

testing: refactored internal/clock to only support injection when
'testing' build tag is present
2020-08-26 23:03:46 -07:00
Jarek Kowalski
9de7348a75 cli: auto-upgrade the repository to 0.6.0 (#512)
On first 'kopia snapshot' or 'kopia server' use where the 'maintenance'
manifest cannot be found, we create a default one and display usage
note.
2020-08-04 23:53:18 -07:00
Julio López
e493177236 Remove legacy flags from snapshot create command (#441)
Remove `--hostname` and `--username` flags
2020-05-18 22:48:18 -07:00
Jarek Kowalski
1f1682b2cc Snapshot checkpointing (#410)
* snapshot: support for periodic checkpointing of snapshots in progress

For each snapshot that takes longer than 45 minutes, we trigger
internal cancellation, save the manifest and restart the snapshot
at which point all files will be cached.

This helps ensure the property that no file or directory objects
in the repository remain unreachable from a snapshot root for more than
one hour, which is important from GC perspective.

* nit: unified spelling 'cancelled' => 'canceled'
2020-04-07 17:54:21 -07:00
Julio López
3924fb247a Minor cleanup for snapshot time override (#392)
* Simplify cli.parseTimestamp
* nit: move duration var closer to where it is used
2020-03-27 00:19:16 -07:00