From 585a5e34165a8274d650db31fde36feb10f64c85 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 3 Oct 2018 14:05:53 +0200 Subject: [PATCH] Use `--host` for all commands, deprecate --hostname --- changelog/unreleased/issue-1967 | 7 +++++++ cmd/restic/cmd_backup.go | 16 ++++++++++------ cmd/restic/cmd_forget.go | 7 ++++--- cmd/restic/cmd_stats.go | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/issue-1967 diff --git a/changelog/unreleased/issue-1967 b/changelog/unreleased/issue-1967 new file mode 100644 index 000000000..4be67cf78 --- /dev/null +++ b/changelog/unreleased/issue-1967 @@ -0,0 +1,7 @@ +Enhancement: Use `--host` everywhere + +We now use the flag `--host` for all commands which need a host name, using +`--hostname` (e.g. for `restic backup`) still works, but will print a +deprecation warning. Also, add the short option `-H` where possible. + +https://github.com/restic/restic/issues/1967 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index a8de4bd4f..4dbae8dd5 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -34,13 +34,13 @@ The "backup" command creates a new snapshot and saves the files and directories given as the arguments. `, PreRun: func(cmd *cobra.Command, args []string) { - if backupOptions.Hostname == "" { + if backupOptions.Host == "" { hostname, err := os.Hostname() if err != nil { debug.Log("os.Hostname() returned err: %v", err) return } - backupOptions.Hostname = hostname + backupOptions.Host = hostname } }, DisableAutoGenTag: true, @@ -74,7 +74,7 @@ type BackupOptions struct { Stdin bool StdinFilename string Tags []string - Hostname string + Host string FilesFrom string TimeStamp string WithAtime bool @@ -96,7 +96,11 @@ func init() { f.BoolVar(&backupOptions.Stdin, "stdin", false, "read backup from stdin") f.StringVar(&backupOptions.StdinFilename, "stdin-filename", "stdin", "file name to use when reading from stdin") f.StringArrayVar(&backupOptions.Tags, "tag", nil, "add a `tag` for the new snapshot (can be specified multiple times)") - f.StringVar(&backupOptions.Hostname, "hostname", "", "set the `hostname` for the snapshot manually. To prevent an expensive rescan use the \"parent\" flag") + + f.StringVar(&backupOptions.Host, "host", "H", "set the `hostname` for the snapshot manually. To prevent an expensive rescan use the \"parent\" flag") + f.StringVar(&backupOptions.Host, "hostname", "", "set the `hostname` for the snapshot manually") + f.MarkDeprecated("hostname", "use --host") + f.StringVar(&backupOptions.FilesFrom, "files-from", "", "read the files to backup from file (can be combined with file args)") f.StringVar(&backupOptions.TimeStamp, "time", "", "time of the backup (ex. '2012-11-01 22:08:41') (default: now)") f.BoolVar(&backupOptions.WithAtime, "with-atime", false, "store the atime for all files and directories") @@ -346,7 +350,7 @@ func findParentSnapshot(ctx context.Context, repo restic.Repository, opts Backup // Find last snapshot to set it as parent, if not already set if !opts.Force && parentID == nil { - id, err := restic.FindLatestSnapshot(ctx, repo, targets, []restic.TagList{}, opts.Hostname) + id, err := restic.FindLatestSnapshot(ctx, repo, targets, []restic.TagList{}, opts.Host) if err == nil { parentID = &id } else if err != restic.ErrNoSnapshotFound { @@ -495,7 +499,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina Excludes: opts.Excludes, Tags: opts.Tags, Time: timeStamp, - Hostname: opts.Hostname, + Hostname: opts.Host, ParentSnapshot: *parentSnapshotID, } diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index 423a1e5e9..1f11fb53c 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -62,11 +62,12 @@ func init() { f.VarP(&forgetOptions.Within, "keep-within", "", "keep snapshots that were created within `duration` before the newest (e.g. 1y5m7d)") f.Var(&forgetOptions.KeepTags, "keep-tag", "keep snapshots with this `taglist` (can be specified multiple times)") - // Sadly the commonly used shortcut `H` is already used. f.StringVar(&forgetOptions.Host, "host", "", "only consider snapshots with the given `host`") - // Deprecated since 2017-03-07. - f.StringVar(&forgetOptions.Host, "hostname", "", "only consider snapshots with the given `hostname` (deprecated)") + f.StringVar(&forgetOptions.Host, "hostname", "", "only consider snapshots with the given `hostname`") + f.MarkDeprecated("hostname", "use --host") + f.Var(&forgetOptions.Tags, "tag", "only consider snapshots which include this `taglist` in the format `tag[,tag,...]` (can be specified multiple times)") + f.StringArrayVar(&forgetOptions.Paths, "path", nil, "only consider snapshots which include this (absolute) `path` (can be specified multiple times)") f.BoolVarP(&forgetOptions.Compact, "compact", "c", false, "use compact format") diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index d98ec0c6e..4ad57a613 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -48,7 +48,7 @@ func init() { cmdRoot.AddCommand(cmdStats) f := cmdStats.Flags() f.StringVar(&countMode, "mode", countModeRestoreSize, "counting mode: restore-size (default), files-by-contents, blobs-per-file, or raw-data") - f.StringVar(&snapshotByHost, "host", "", "filter latest snapshot by this hostname") + f.StringVar(&snapshotByHost, "host", "H", "filter latest snapshot by this hostname") } func runStats(gopts GlobalOptions, args []string) error {