Beispiel #1
0
func (p RedisBrokerPlugin) Backup(endpoint plugin.ShieldEndpoint) error {
	// Use ExecWithOptions here, to allow tar to exit 1 as warning about
	// files changing/shrinking/disappearing is ok in this specific case
	// redis-check-aof is used in restore to fix corruption on the last
	// command in the AOF, and the file is written to every second. At
	// worst, the restored data appears to have been backed up one second
	// prior to when it actually was

	opts := plugin.ExecOptions{
		Cmd:      "tar -c --warning no-file-changed --warning no-file-shrank --warning no-file-removed -C /var/vcap/store .",
		Stdout:   os.Stdout,
		ExpectRC: []int{0, 1},
	}
	err := plugin.ExecWithOptions(opts)
	if err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
var _ = Describe("Plugin Commands", func() {

	drain := func(file *os.File, output chan string) {
		data, err := ioutil.ReadAll(file)
		if err != nil {
			panic(fmt.Sprintf("Error reading from pipe, test is invalid: %s", err.Error()))
		}
		output <- string(data)
	}

	It("Executes commands successfully", func() {
		opts := plugin.ExecOptions{
			Cmd: "test/bin/exec_tester 0",
		}
		err := plugin.ExecWithOptions(opts)
		Expect(err).ShouldNot(HaveOccurred())
	})
	It("Returns errors when the command fails", func() {
		opts := plugin.ExecOptions{
			Cmd: "test/bin/exec_tester 1",
		}
		err := plugin.ExecWithOptions(opts)
		Expect(err).Should(HaveOccurred())
	})
	It("Doesn't return errors when the command returns an expected exit code", func() {
		opts := plugin.ExecOptions{
			Cmd:      "test/bin/exec_tester 1",
			ExpectRC: []int{0, 1},
		}
		err := plugin.ExecWithOptions(opts)