restic/src/cmds/restic/main.go

58 lines
1.2 KiB
Go
Raw Normal View History

2014-04-27 22:00:15 +00:00
package main
import (
2015-07-12 20:10:01 +00:00
"fmt"
"os"
"restic"
"restic/debug"
"runtime"
2016-09-17 10:36:05 +00:00
"github.com/spf13/cobra"
2016-09-01 20:17:37 +00:00
2016-09-17 10:36:05 +00:00
"restic/errors"
2014-04-27 22:00:15 +00:00
)
2016-09-17 10:36:05 +00:00
// cmdRoot is the base command when no other command has been specified.
var cmdRoot = &cobra.Command{
Use: "restic",
Short: "backup and restore files",
Long: `
restic is a backup program which allows saving multiple revisions of files and
directories in an encrypted repository stored on different backends.
`,
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRun: parseEnvironment,
}
2014-04-27 22:00:15 +00:00
func init() {
2014-11-16 21:50:20 +00:00
// set GOMAXPROCS to number of CPUs
if runtime.Version() < "go1.5" {
gomaxprocs := os.Getenv("GOMAXPROCS")
2016-09-27 20:35:08 +00:00
debug.Log("read GOMAXPROCS from env variable, value: %s", gomaxprocs)
if gomaxprocs == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}
}
2014-04-27 22:00:15 +00:00
}
func main() {
2016-09-27 20:35:08 +00:00
debug.Log("main %#v", os.Args)
2016-09-17 10:36:05 +00:00
err := cmdRoot.Execute()
switch {
case restic.IsAlreadyLocked(errors.Cause(err)):
fmt.Fprintf(os.Stderr, "%v\nthe `unlock` command can be used to remove stale locks\n", err)
2016-09-01 20:17:37 +00:00
case errors.IsFatal(errors.Cause(err)):
fmt.Fprintf(os.Stderr, "%v\n", err)
case err != nil:
2016-08-21 16:07:13 +00:00
fmt.Fprintf(os.Stderr, "%+v\n", err)
2016-01-17 15:59:03 +00:00
}
2015-07-19 15:57:18 +00:00
RunCleanupHandlers()
2014-09-23 20:39:12 +00:00
if err != nil {
2014-12-07 15:30:52 +00:00
os.Exit(1)
2014-04-27 22:00:15 +00:00
}
}