コード例 #1
0
func (b *backuper) Backup(client redis.Client, s3TargetPath string) error {
	localLogger := b.logger.WithData(lager.Data{
		"redis_address": client.Address(),
	})

	localLogger.Info("backup", lager.Data{"event": "starting"})

	snapshotter := b.snapshotterProvider(client, b.snapshotTimeout, b.logger)
	artifact, err := snapshotter.Snapshot()
	if err != nil {
		localLogger.Error("backup", err, lager.Data{"event": "failed"})
		return err
	}

	originalPath := artifact.Path()

	tmpSnapshotPath := filepath.Join(b.tmpDir, uuid.New())

	renameTask := b.renameTaskProvider(tmpSnapshotPath, b.logger)

	uploadTask := b.s3UploadTaskProvider(
		b.s3BucketName,
		s3TargetPath,
		b.s3Endpoint,
		b.awsAccessKey,
		b.awsSecretKey,
		b.logger,
	)

	cleanupTask := b.cleanupTaskProvider(
		originalPath,
		tmpSnapshotPath,
		b.logger,
	)

	artifact, err = task.NewPipeline(
		"redis-backup",
		b.logger,
		renameTask,
		uploadTask,
	).Run(artifact)

	if err != nil {
		localLogger.Error("backup", err, lager.Data{"event": "failed"})
	}

	task.NewPipeline(
		"cleanup",
		b.logger,
		cleanupTask,
	).Run(artifact)

	localLogger.Info("backup", lager.Data{"event": "done"})

	return err
}
コード例 #2
0
var _ = Describe("Pipeline", func() {
	var (
		logger lager.Logger
		log    *gbytes.Buffer
	)

	BeforeEach(func() {
		logger = lager.NewLogger("logger")
		log = gbytes.NewBuffer()
		logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))
	})

	Describe(".Name", func() {
		It("returns the pipeline name", func() {
			pipeline := task.NewPipeline("some-pipeline", logger)

			Expect(pipeline.Name()).To(Equal("some-pipeline"))
		})

	})

	Describe(".Run", func() {
		var (
			task1            *fakeTask
			task2            *fakeTask
			originalArtifact = task.NewArtifact("path/to/artifact")
			finalArtifact    task.Artifact
			runErr           error
		)