예제 #1
0
파일: global.go 프로젝트: JaCoB1123/restic
// Create the backend specified by URI.
func create(u string) (backend.Backend, error) {
	// check if the url is a directory that exists
	fi, err := os.Stat(u)
	if err == nil && fi.IsDir() {
		return local.Create(u)
	}

	url, err := url.Parse(u)
	if err != nil {
		return nil, err
	}

	if url.Scheme == "" {
		return local.Create(url.Path)
	}

	if len(url.Path) < 1 {
		return nil, fmt.Errorf("unable to parse url %v", url)
	}

	if url.Scheme == "s3" {
		return s3.Open(url.Host, url.Path[1:])
	}

	args := []string{url.Host}
	if url.User != nil && url.User.Username() != "" {
		args = append(args, "-l")
		args = append(args, url.User.Username())
	}
	args = append(args, "-s")
	args = append(args, "sftp")
	return sftp.Create(url.Path[1:], "ssh", args...)
}
예제 #2
0
파일: local_test.go 프로젝트: rawtaz/restic
func TestLocalBackendCreationFailures(t *testing.T) {
	b := setupLocalBackend(t)
	defer teardownLocalBackend(t, b)

	// test failure to create a new repository at the same location
	b2, err := local.Create(b.Location())
	Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))

	// test failure to create a new repository at the same location without a config file
	b2, err = local.Create(b.Location())
	Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
}
예제 #3
0
파일: global.go 프로젝트: aut0/restic
// Create the backend specified by URI.
func create(s string) (backend.Backend, error) {
	debug.Log("open", "parsing location %v", s)
	loc, err := location.Parse(s)
	if err != nil {
		return nil, err
	}

	switch loc.Scheme {
	case "local":
		debug.Log("open", "create local repository at %#v", loc.Config)
		return local.Create(loc.Config.(string))
	case "sftp":
		debug.Log("open", "create sftp repository at %#v", loc.Config)
		return sftp.CreateWithConfig(loc.Config.(sftp.Config))
	case "s3":
		cfg := loc.Config.(s3.Config)
		if cfg.KeyID == "" {
			cfg.KeyID = os.Getenv("AWS_ACCESS_KEY_ID")

		}
		if cfg.Secret == "" {
			cfg.Secret = os.Getenv("AWS_SECRET_ACCESS_KEY")
		}

		debug.Log("open", "create s3 repository at %#v", loc.Config)
		return s3.Open(cfg)
	}

	debug.Log("open", "invalid repository scheme: %v", s)
	return nil, fmt.Errorf("invalid scheme %q", loc.Scheme)
}
예제 #4
0
파일: local_test.go 프로젝트: rawtaz/restic
func setupLocalBackend(t *testing.T) *local.Local {
	tempdir, err := ioutil.TempDir("", "restic-test-")
	OK(t, err)

	b, err := local.Create(tempdir)
	OK(t, err)

	t.Logf("created local backend at %s", tempdir)

	return b
}
예제 #5
0
파일: backend.go 프로젝트: rawtaz/restic
func SetupRepo(t testing.TB) *repository.Repository {
	tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
	OK(t, err)

	// create repository below temp dir
	b, err := local.Create(filepath.Join(tempdir, "repo"))
	OK(t, err)

	repo := repository.New(b)
	OK(t, repo.Init(TestPassword))
	return repo
}
예제 #6
0
파일: local_test.go 프로젝트: marete/restic
func TestLocalBackendCreationFailures(t *testing.T) {
	b := setupLocalBackend(t)
	defer teardownLocalBackend(t, b)

	// create a fake config file
	blob, err := b.Create()
	OK(t, err)
	fmt.Fprintf(blob, "config\n")
	OK(t, blob.Finalize(backend.Config, ""))

	// test failure to create a new repository at the same location
	b2, err := local.Create(b.Location())
	Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
}
예제 #7
0
파일: backend.go 프로젝트: aut0/restic
func SetupRepo() *repository.Repository {
	tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
	if err != nil {
		panic(err)
	}

	// create repository below temp dir
	b, err := local.Create(filepath.Join(tempdir, "repo"))
	if err != nil {
		panic(err)
	}

	repo := repository.New(b)
	err = repo.Init(TestPassword)
	if err != nil {
		panic(err)
	}

	return repo
}
예제 #8
0
파일: global.go 프로젝트: rawtaz/restic
// Create the backend specified by URI.
func create(u string) (backend.Backend, error) {
	url, err := url.Parse(u)
	if err != nil {
		return nil, err
	}

	if url.Scheme == "" {
		return local.Create(url.Path)
	} else if url.Scheme == "s3" {
		return s3.Open(url.Host, url.Path[1:])
	}

	args := []string{url.Host}
	if url.User != nil && url.User.Username() != "" {
		args = append(args, "-l")
		args = append(args, url.User.Username())
	}
	args = append(args, "-s")
	args = append(args, "sftp")
	return sftp.Create(url.Path[1:], "ssh", args...)
}