Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
roivaz committed Nov 20, 2023
1 parent aaefb98 commit 10cfe34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
34 changes: 12 additions & 22 deletions pkg/redis/backup/s3upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,25 @@ func (br *Runner) UploadBackup(ctx context.Context) error {
return err
}

var commands = []ssh.Runnable{
// mv /data/dump.rdb /data/redis-backup-<shard>-<server>-<timestamp>.rdb
ssh.NewCommand(fmt.Sprintf("mv %s %s/%s",
br.RedisDBFile,
path.Dir(br.RedisDBFile), br.BackupFile(),
)),
// gzip /data/redis-backup-<shard>-<server>-<timestamp>.rdb
// ssh.NewCommand(fmt.Sprintf("gzip -1 %s/%s", path.Dir(br.RedisDBFile), br.BackupFile())),
ssh.NewCommand(fmt.Sprintf("gzip -1 %s/%s", path.Dir(br.RedisDBFile), br.BackupFile())),
// AWS_ACCESS_KEY_ID=*** AWS_SECRET_ACCESS_KEY=*** s3cmd put /data/redis-backup-<shard>-<server>-<timestamp>.rdb s3://<bucket>/<path>/redis-backup-<shard>-<server>-<timestamp>.rdb
ssh.NewScript(
fmt.Sprintf("%s=%s %s=%s %s=%s python -",
util.AWSRegionEnvvar, br.AWSRegion,
util.AWSAccessKeyEnvvar, br.AWSAccessKeyID,
util.AWSSecretKeyEnvvar, br.AWSSecretAccessKey),
uploadScript,
br.AWSSecretAccessKey,
),
ssh.NewCommand(fmt.Sprintf("rm -f %s/%s*", path.Dir(br.RedisDBFile), br.BackupFileBaseName())),
}

remoteExec := ssh.RemoteExecutor{
Host: br.Server.GetHost(),
User: br.SSHUser,
Port: br.SSHPort,
PrivateKey: br.SSHKey,
Logger: logger,
CmdTimeout: 0,
Commands: commands,
Commands: []ssh.Runnable{
ssh.NewCommand(fmt.Sprintf("mv %s %s/%s", br.RedisDBFile, path.Dir(br.RedisDBFile), br.BackupFile())),
ssh.NewCommand(fmt.Sprintf("gzip -1 %s/%s", path.Dir(br.RedisDBFile), br.BackupFile())),
ssh.NewScript(fmt.Sprintf("%s=%s %s=%s %s=%s python -",
util.AWSRegionEnvvar, br.AWSRegion,
util.AWSAccessKeyEnvvar, br.AWSAccessKeyID,
util.AWSSecretKeyEnvvar, br.AWSSecretAccessKey),
uploadScript,
br.AWSSecretAccessKey,
),
ssh.NewCommand(fmt.Sprintf("rm -f %s/%s*", path.Dir(br.RedisDBFile), br.BackupFileBaseName())),
},
}

err = remoteExec.Run()
Expand Down
4 changes: 2 additions & 2 deletions pkg/ssh/remote_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type Command struct {

var _ Runnable = &Command{}

func NewCommand(value string) *Command {
return &Command{value: value}
func NewCommand(value string, sensitive ...string) *Command {
return &Command{value: value, sensitive: sensitive}
}

func (c *Command) Info() string {
Expand Down

0 comments on commit 10cfe34

Please sign in to comment.