2014-04-27 22:00:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-12 20:10:01 +00:00
|
|
|
"fmt"
|
2016-08-03 18:29:08 +00:00
|
|
|
"os"
|
2016-02-14 14:29:28 +00:00
|
|
|
"restic"
|
|
|
|
"restic/debug"
|
2016-08-03 18:29:08 +00:00
|
|
|
"runtime"
|
2016-08-21 15:46:23 +00:00
|
|
|
|
2016-09-01 20:17:37 +00:00
|
|
|
"restic/errors"
|
|
|
|
|
2016-08-21 15:46:23 +00:00
|
|
|
"github.com/jessevdk/go-flags"
|
2014-04-27 22:00:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2014-11-16 21:50:20 +00:00
|
|
|
// set GOMAXPROCS to number of CPUs
|
2016-08-03 18:29:08 +00:00
|
|
|
if runtime.Version() < "go1.5" {
|
|
|
|
gomaxprocs := os.Getenv("GOMAXPROCS")
|
|
|
|
debug.Log("restic", "read GOMAXPROCS from env variable, value: %s", gomaxprocs)
|
|
|
|
if gomaxprocs == "" {
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 22:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2014-11-23 15:48:00 +00:00
|
|
|
// defer profile.Start(profile.MemProfileRate(100000), profile.ProfilePath(".")).Stop()
|
2015-02-21 23:09:57 +00:00
|
|
|
// defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
|
2015-06-21 11:02:56 +00:00
|
|
|
globalOpts.Repo = os.Getenv("RESTIC_REPOSITORY")
|
2014-04-27 22:00:15 +00:00
|
|
|
|
2015-01-14 21:08:48 +00:00
|
|
|
debug.Log("restic", "main %#v", os.Args)
|
|
|
|
|
2014-12-07 15:30:52 +00:00
|
|
|
_, err := parser.Parse()
|
2014-04-27 22:00:15 +00:00
|
|
|
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
|
2016-01-17 15:59:03 +00:00
|
|
|
parser.WriteHelp(os.Stdout)
|
2014-04-27 22:00:15 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2016-08-28 20:19:48 +00:00
|
|
|
debug.Log("main", "command returned error: %#v", err)
|
|
|
|
|
|
|
|
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)):
|
2016-08-28 20:19:48 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|