Beispiel #1
0
func main() {
	// defer profile.Start(profile.MemProfileRate(100000), profile.ProfilePath(".")).Stop()
	// defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
	globalOpts.Repo = os.Getenv("RESTIC_REPOSITORY")
	globalOpts.password = os.Getenv("RESTIC_PASSWORD")

	debug.Log("restic", "main %#v", os.Args)

	_, err := parser.Parse()
	if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
		parser.WriteHelp(os.Stdout)
		os.Exit(0)
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
	}

	if restic.IsAlreadyLocked(err) {
		fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n")
	}

	RunCleanupHandlers()

	if err != nil {
		os.Exit(1)
	}
}
Beispiel #2
0
func lockRepository(repo *repository.Repository, exclusive bool) (*restic.Lock, error) {
	lockFn := restic.NewLock
	if exclusive {
		lockFn = restic.NewExclusiveLock
	}

	lock, err := lockFn(repo)
	if err != nil {
		if restic.IsAlreadyLocked(err) {
			tpe := ""
			if exclusive {
				tpe = " exclusive"
			}
			fmt.Fprintf(os.Stderr, "unable to acquire%s lock for operation:\n", tpe)
			fmt.Fprintln(os.Stderr, err)
			fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n")
			os.Exit(1)
		}

		return nil, err
	}

	globalLocks = append(globalLocks, lock)

	return lock, err
}
Beispiel #3
0
func TestExclusiveLockOnLockedRepo(t *testing.T) {
	repo := SetupRepo()
	defer TeardownRepo(repo)

	elock, err := restic.NewLock(repo)
	OK(t, err)

	lock, err := restic.NewExclusiveLock(repo)
	Assert(t, err != nil,
		"create normal lock with exclusively locked repo didn't return an error")
	Assert(t, restic.IsAlreadyLocked(err),
		"create normal lock with exclusively locked repo didn't return the correct error")

	OK(t, lock.Unlock())
	OK(t, elock.Unlock())
}