示例#1
0
// Called when you want to restore data Examine the ShieldEndpoint passed in, and perform actions accordingly
func (p DummyPlugin) Restore(endpoint plugin.ShieldEndpoint) error {
	file, err := endpoint.StringValue("file")
	if err != nil {
		return err
	}

	return plugin.Exec(fmt.Sprintf("/bin/sh -c \"/bin/cat > %s\"", file), plugin.STDIN)
}
示例#2
0
// Called when you want to back data up. Examine the ShieldEndpoint passed in, and perform actions accordingly
func (p DummyPlugin) Backup(endpoint plugin.ShieldEndpoint) error {
	data, err := endpoint.StringValue("data")
	if err != nil {
		return err
	}

	return plugin.Exec(fmt.Sprintf("/bin/echo %s", data), plugin.STDOUT)
}
示例#3
0
// Called when you want to retreive backup data. Examine the ShieldEndpoint passed in, and perform actions accordingly
func (p DummyPlugin) Retrieve(endpoint plugin.ShieldEndpoint, file string) error {
	directory, err := endpoint.StringValue("directory")
	if err != nil {
		return err
	}

	return plugin.Exec(fmt.Sprintf("/bin/cat %s/%s", directory, file), plugin.STDOUT)
}
示例#4
0
// Called when you want to store backup data. Examine the ShieldEndpoint passed in, and perform actions accordingly
func (p DummyPlugin) Store(endpoint plugin.ShieldEndpoint) (string, error) {
	directory, err := endpoint.StringValue("directory")
	if err != nil {
		return "", err
	}

	file := plugin.GenUUID()

	err = plugin.Exec(fmt.Sprintf("/bin/sh -c \"/bin/cat > %s/%s\"", directory, file), plugin.STDIN)
	return file, err
}
示例#5
0
func (p FSPlugin) Restore(endpoint plugin.ShieldEndpoint) error {
	cfg, err := getFSConfig(endpoint)
	if err != nil {
		return err
	}

	cmd := fmt.Sprintf("%s -x -C %s", cfg.BsdTar, cfg.BasePath)
	plugin.DEBUG("Executing `%s`", cmd)
	err = plugin.Exec(cmd, plugin.STDIN)
	if err != nil {
		return err
	}

	return nil
}
示例#6
0
func (p RedisBrokerPlugin) Restore(endpoint plugin.ShieldEndpoint) error {
	redis, err := getRedisEndpoint(endpoint)
	if err != nil {
		return err
	}

	var services = []string{"cf-redis-broker"}
	if redis.Mode == "dedicated" {
		services = []string{"redis", "redis-agent"}
	}

	for _, svc := range services {
		err = plugin.Exec(fmt.Sprintf("/var/vcap/bosh/bin/monit stop %s", svc), plugin.STDOUT)
		if err != nil {
			return err
		}
	}

	err = plugin.Exec("bash -c \"while [[ $(/var/vcap/bosh/bin/monit summary | grep redis | grep running) ]]; do sleep 1; done\"", plugin.STDOUT)
	if err != nil {
		return err
	}

	// Don't look for errors here, because pkill will return non-zero if there
	// were no processes to kill in the first place.
	// FIXME: handle this better, so we know we're pkilling properly
	plugin.Exec("pkill redis-server", plugin.STDOUT)
	time.Sleep(2 * time.Second)
	plugin.Exec("pkill -9 redis-server", plugin.STDOUT)
	time.Sleep(1 * time.Second)

	err = plugin.Exec("tar -x -C /var/vcap/store . ", plugin.STDIN)
	if err != nil {
		return err
	}

	err = plugin.Exec("bash -c 'yes | find /var/vcap/store -name appendonly.aof -exec /var/vcap/packages/redis/bin/redis-check-aof --fix {} \\;'", plugin.STDOUT)
	if err != nil {
		return err
	}

	for _, svc := range services {
		err = plugin.Exec(fmt.Sprintf("/var/vcap/bosh/bin/monit start %s", svc), plugin.STDOUT)
		if err != nil {
			return err
		}
	}
	return nil
}
示例#7
0
func (p FSPlugin) Backup(endpoint plugin.ShieldEndpoint) error {
	cfg, err := getFSConfig(endpoint)
	if err != nil {
		return err
	}

	//FIXME: drop include and exclude if they were not specified
	var flags string
	if cfg.Include != "" {
		flags = fmt.Sprintf("%s --include '%s'", flags, cfg.Include)
	}
	if cfg.Exclude != "" {
		flags = fmt.Sprintf("%s --exclude '%s'", flags, cfg.Exclude)
	}
	cmd := fmt.Sprintf("%s -c -C %s %s .", cfg.BsdTar, cfg.BasePath, flags)
	plugin.DEBUG("Executing `%s`", cmd)
	err = plugin.Exec(cmd, plugin.STDOUT)
	if err != nil {
		return err
	}

	return nil
}
示例#8
0
		go drain(rStdout, stdoutC)

		_, err = wStdin.Write([]byte("This should go to stdout"))
		Expect(err).ShouldNot(HaveOccurred())
		wStdin.Close()

		opts := plugin.ExecOptions{
			Cmd:      "test/bin/exec_tester 0",
			Stdout:   wStdout,
			Stderr:   wStderr,
			Stdin:    rStdin,
			ExpectRC: []int{0},
		}

		err = plugin.ExecWithOptions(opts)
		wStderr.Close() // simulate command exiting + its pipe being closed
		wStdout.Close() // simulate command exiting + its pipe being closed

		stderr := <-stderrC
		stdout := <-stdoutC

		Expect(err).ShouldNot(HaveOccurred())
		Expect(stdout).Should(Equal("This should go to stdout"))
		Expect(stderr).Should(Equal("This goes to stderr\n"))
	})
	It("Returns an error for commands that cannot be parsed", func() {
		err := plugin.Exec("this '\"cannot be parsed", plugin.NOPIPE)
		Expect(err).Should(HaveOccurred())
	})
})