2014-04-28 00:00:15 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-12 22:10:01 +02:00
|
|
|
"fmt"
|
2016-08-03 20:29:08 +02:00
|
|
|
"os"
|
2016-02-14 15:29:28 +01:00
|
|
|
"restic"
|
|
|
|
"restic/debug"
|
2016-08-03 20:29:08 +02:00
|
|
|
"runtime"
|
2016-08-21 17:46:23 +02:00
|
|
|
|
|
|
|
"github.com/jessevdk/go-flags"
|
2016-08-21 18:07:13 +02:00
|
|
|
"github.com/pkg/errors"
|
2014-04-28 00:00:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2014-11-16 22:50:20 +01:00
|
|
|
// set GOMAXPROCS to number of CPUs
|
2016-08-03 20:29:08 +02: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-28 00:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2014-11-23 16:48:00 +01:00
|
|
|
// defer profile.Start(profile.MemProfileRate(100000), profile.ProfilePath(".")).Stop()
|
2015-02-22 00:09:57 +01:00
|
|
|
// defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
|
2015-06-21 13:02:56 +02:00
|
|
|
globalOpts.Repo = os.Getenv("RESTIC_REPOSITORY")
|
|
|
|
globalOpts.password = os.Getenv("RESTIC_PASSWORD")
|
2014-04-28 00:00:15 +02:00
|
|
|
|
2015-01-14 22:08:48 +01:00
|
|
|
debug.Log("restic", "main %#v", os.Args)
|
|
|
|
|
2014-12-07 16:30:52 +01:00
|
|
|
_, err := parser.Parse()
|
2014-04-28 00:00:15 +02:00
|
|
|
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
|
2016-01-17 16:59:03 +01:00
|
|
|
parser.WriteHelp(os.Stdout)
|
2014-04-28 00:00:15 +02:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2016-01-17 16:59:03 +01:00
|
|
|
if err != nil {
|
2016-08-21 18:07:13 +02:00
|
|
|
debug.Log("main", "command returned error: %#v", err)
|
|
|
|
fmt.Fprintf(os.Stderr, "%+v\n", err)
|
2016-01-17 16:59:03 +01:00
|
|
|
}
|
|
|
|
|
2016-08-21 18:07:13 +02:00
|
|
|
if restic.IsAlreadyLocked(errors.Cause(err)) {
|
2015-07-12 22:10:01 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n")
|
|
|
|
}
|
|
|
|
|
2015-07-19 17:57:18 +02:00
|
|
|
RunCleanupHandlers()
|
|
|
|
|
2014-09-23 22:39:12 +02:00
|
|
|
if err != nil {
|
2014-12-07 16:30:52 +01:00
|
|
|
os.Exit(1)
|
2014-04-28 00:00:15 +02:00
|
|
|
}
|
|
|
|
}
|