Пример #1
0
func redisPIDProvider(instancePath string) process.PIDProvider {
	return func() (int, error) {
		instanceConf, err := redisconf.Load(path.Join(instancePath, "redis.conf"))
		if err != nil {
			return 0, err
		}

		client, err := client.Connect(
			client.Host("localhost"),
			client.Port(instanceConf.Port()),
			client.Password(instanceConf.Password()),
			client.CmdAliases(instanceConf.CommandAliases()),
		)
		if err != nil {
			return 0, err
		}

		pidfile, err := client.GetConfig("pidfile")
		if err != nil {
			return 0, err
		}
		return process.ReadPID(pidfile)
	}
}
Пример #2
0
func (b *instanceBackuper) instanceBackup(redisConfig instance.RedisConfig) BackupResult {
	result := BackupResult{
		RedisConfigPath: redisConfig.Path,
		NodeIP:          b.backupConfig.NodeIP,
	}

	logger := b.logger.WithData(
		lager.Data{
			"node_ip":           b.backupConfig.NodeIP,
			"redis_config_path": redisConfig.Path,
		},
	)

	logger.Info("instance-backup", lager.Data{"event": "starting"})

	logger.Info("instance-backup.locate-iid", lager.Data{"event": "starting"})
	instanceID, err := b.instanceIDLocator.LocateID(
		redisConfig.Path,
		b.backupConfig.NodeIP,
	)
	if err != nil {
		logger.Error("instance-backup.locate-iid", err, lager.Data{"event": "failed"})
		result.Err = err
		return result
	}

	result.InstanceID = instanceID

	logger.Info("instance-backup.locate-iid", lager.Data{
		"event":       "done",
		"instance_id": instanceID,
	})

	redisAddress := fmt.Sprintf("%s:%d", redisConfig.Conf.Host(), redisConfig.Conf.Port())
	logger.Info("instance-backup.redis-connect", lager.Data{
		"event":         "starting",
		"redis_address": redisAddress,
	})
	redisClient, err := b.redisClientProvider(
		redis.Host(redisConfig.Conf.Host()),
		redis.Port(redisConfig.Conf.Port()),
		redis.Password(redisConfig.Conf.Password()),
		redis.CmdAliases(redisConfig.Conf.CommandAliases()),
	)
	if err != nil {
		logger.Error("instance-backup.redis-connect", err, lager.Data{"event": "failed"})
		result.Err = err
		return result
	}
	defer func() {
		if err := redisClient.Disconnect(); err != nil {
			logger.Error("instance-backup.redis-disconnect", err, lager.Data{"event": "failed"})
		}
	}()
	logger.Info("instance-backup.redis-connect", lager.Data{
		"event":         "done",
		"redis_address": redisAddress,
	})

	targetPath := b.buildTargetPath(instanceID)
	logger.Info("instance-backup.redis-backup", lager.Data{
		"event":       "starting",
		"target_path": targetPath,
	})
	err = b.redisBackuper.Backup(redisClient, targetPath)
	if err != nil {
		logger.Error("instance-backup.redis-backup", err, lager.Data{"event": "failed"})
		result.Err = err
		return result
	}
	logger.Info("instance-backup.redis-backup", lager.Data{
		"event":       "done",
		"target_path": targetPath,
	})

	logger.Info("instance-backup", lager.Data{"event": "done"})
	return result
}