mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
rewrite: address most review comments
This commit is contained in:
parent
b922774343
commit
82592b88b5
@ -1,3 +1,7 @@
|
|||||||
Change: Implement rewrite command
|
Enhancement: Implement rewrite command
|
||||||
|
|
||||||
TODO: write here
|
We've added a new command which allows to rewrite existing snapshots to remove
|
||||||
|
unwanted files.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/14
|
||||||
|
https://github.com/restic/restic/pull/2731
|
||||||
|
@ -14,23 +14,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var cmdRewrite = &cobra.Command{
|
var cmdRewrite = &cobra.Command{
|
||||||
Use: "rewrite [f] [all|snapshotID ...]",
|
Use: "rewrite [flags] [all|snapshotID ...]",
|
||||||
Short: "Modify existing snapshots by deleting files",
|
Short: "Rewrite existing snapshots",
|
||||||
Long: `
|
Long: `
|
||||||
The "rewrite" command excludes files from existing snapshots.
|
The "rewrite" command excludes files from existing snapshots.
|
||||||
|
|
||||||
By default 'rewrite' will create new snapshot that will contains same data as
|
By default 'rewrite' will create new snapshots that will contains same data as
|
||||||
source snapshot except excluded data. All metadata (time, host, tags) will be preserved.
|
the source snapshots but without excluded files. All metadata (time, host, tags)
|
||||||
Special tag 'rewrite' will be added to new snapshot to distinguish it from source
|
will be preserved. The special tag 'rewrite' will be added to new snapshots to
|
||||||
(unless --inplace is used)
|
distinguish it from the source (unless --inplace is used).
|
||||||
|
|
||||||
If --inplace option is used, old snapshot will be removed from repository.
|
If --inplace option is used, old snapshot will be removed from repository.
|
||||||
|
|
||||||
Snapshots to rewrite are specified using --host, --tag, --path or by providing list of snapshotID.
|
Snapshots to rewrite are specified using --host, --tag, --path or by providing
|
||||||
Alternatively it's possible to use special 'all' snapshot that will match all snapshots
|
a list of snapshot ids. Alternatively it's possible to use special snapshot id 'all'
|
||||||
|
that will match all snapshots.
|
||||||
|
|
||||||
Please note, that this command only modifies snapshot objects. In order to delete
|
Please note, that this command only creates new snapshots. In order to delete
|
||||||
data from repository use 'prune' command
|
data from the repository use 'prune' command.
|
||||||
|
|
||||||
EXIT STATUS
|
EXIT STATUS
|
||||||
===========
|
===========
|
||||||
@ -43,9 +44,8 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// RewriteOptions collects all options for the ls command.
|
// RewriteOptions collects all options for the rewrite command.
|
||||||
type RewriteOptions struct {
|
type RewriteOptions struct {
|
||||||
// TagOptions bundles all options for the 'tag' command.
|
|
||||||
Hosts []string
|
Hosts []string
|
||||||
Paths []string
|
Paths []string
|
||||||
Tags restic.TagLists
|
Tags restic.TagLists
|
||||||
@ -214,10 +214,6 @@ func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *resti
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
err = repo.Flush(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return true, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Inplace {
|
if opts.Inplace {
|
||||||
h := restic.Handle{Type: restic.SnapshotFile, Name: sn.ID().String()}
|
h := restic.Handle{Type: restic.SnapshotFile, Name: sn.ID().String()}
|
||||||
@ -250,7 +246,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !gopts.NoLock && !opts.DryRun {
|
if !opts.DryRun {
|
||||||
Verbosef("create exclusive lock for repository\n")
|
Verbosef("create exclusive lock for repository\n")
|
||||||
var lock *restic.Lock
|
var lock *restic.Lock
|
||||||
lock, ctx, err = lockRepoExclusive(ctx, repo)
|
lock, ctx, err = lockRepoExclusive(ctx, repo)
|
||||||
|
Loading…
Reference in New Issue
Block a user