Skip to content

Commit

Permalink
Merge branch 'wal-g:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chipitsine authored Sep 5, 2024
2 parents df8f2e7 + c3dc6aa commit bd7f0ce
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
5 changes: 1 addition & 4 deletions cmd/redis/rdb_backup_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/wal-g/wal-g/internal"
conf "github.com/wal-g/wal-g/internal/config"
"github.com/wal-g/wal-g/internal/databases/redis"
"github.com/wal-g/wal-g/internal/databases/redis/archive"
"github.com/wal-g/wal-g/utility"
)

Expand Down Expand Up @@ -49,9 +48,7 @@ var backupFetchCmd = &cobra.Command{
restoreCmd.Stdout = os.Stdout
restoreCmd.Stderr = os.Stderr

dataPath, _ := conf.GetSetting(conf.RedisDataPath)
dataDir := archive.CreateFolderInfo(dataPath)
err = redis.HandleBackupFetch(ctx, storage.RootFolder(), args[0], restoreCmd, dataDir)
err = redis.HandleBackupFetch(ctx, storage.RootFolder(), args[0], restoreCmd)
tracelog.ErrorLogger.FatalOnError(err)
},
}
Expand Down
5 changes: 3 additions & 2 deletions docker/mysql/Dockerfile_v8
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ RUN apt-get update && \
mysql-client \
s3cmd \
jq \
lsb-release && \
lsb-release \
gnupg2 && \
wget https://repo.percona.com/apt/percona-release_latest.focal_all.deb && \
dpkg -i percona-release_latest.focal_all.deb && \
percona-release enable tools release && \
Expand All @@ -46,4 +47,4 @@ COPY docker/common/s3cfg /root/.s3cfg

# append
COPY docker/mysql/my.cnf /tmp/my.cnf
RUN cat /tmp/my.cnf >> /etc/mysql/my.cnf; rm /tmp/my.cnf
RUN cat /tmp/my.cnf >> /etc/mysql/my.cnf; rm /tmp/my.cnf
File renamed without changes.
8 changes: 4 additions & 4 deletions internal/databases/redis/aof/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type RestoreService struct {
Context context.Context
Folder *archive.FolderInfo
Folder *archive.AofFolderInfo
Uploader internal.Uploader
versionParser *archive.VersionParser
}
Expand All @@ -24,8 +24,8 @@ type RestoreArgs struct {
SkipBackupDownload bool
}

func CreateRestoreService(ctx context.Context, folder *archive.FolderInfo, uploader internal.Uploader, versionParser *archive.VersionParser,
) (*RestoreService, error) {
func CreateRestoreService(ctx context.Context, folder *archive.AofFolderInfo, uploader internal.Uploader,
versionParser *archive.VersionParser) (*RestoreService, error) {
return &RestoreService{
Context: ctx,
Folder: folder,
Expand Down Expand Up @@ -58,7 +58,7 @@ func (restoreService *RestoreService) DoRestore(args RestoreArgs) error {
}

if !args.SkipBackupDownload {
err = restoreService.Folder.CleanParent()
err = restoreService.Folder.CleanData()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/databases/redis/aof_backup_fetch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func HandleAofFetchPush(
dataFolder, _ := conf.GetSetting(conf.RedisDataPath)
aofFolder, _ := conf.GetSetting(conf.RedisAppendonlyFolder)
aofPath := filepath.Join(dataFolder, aofFolder)
folder := archive.CreateFolderInfo(aofPath)
folder := archive.CreateAofFolderInfo(aofPath)

uploader, err := internal.ConfigureUploader()
if err != nil {
Expand Down
26 changes: 17 additions & 9 deletions internal/databases/redis/archive/fs.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package archive

import (
"fmt"
"os"
"path/filepath"
)

type FolderInfo struct {
type AofFolderInfo struct {
Path string
}

func CreateFolderInfo(path string) *FolderInfo {
return &FolderInfo{
func CreateAofFolderInfo(path string) *AofFolderInfo {
return &AofFolderInfo{
Path: path,
}
}

func (f *FolderInfo) CleanParent() (err error) {
parent := filepath.Dir(f.Path)
starred := filepath.Join(parent, "*")
func (f *AofFolderInfo) CleanData() error {
path := filepath.Clean(f.Path)
err := os.RemoveAll(path)
if err != nil {
return fmt.Errorf("failed to remove AOF folder: %v", err)
}

parent := filepath.Dir(path)
starred := filepath.Join(parent, "*.rdb")
contents, err := filepath.Glob(starred)
if err != nil {
return
return fmt.Errorf("failed to create glob for rdb files: %v", err)
}

for _, item := range contents {
err = os.RemoveAll(item)
if err != nil {
return
return fmt.Errorf("failed to remove rdb file: %v", err)
}
}
return

return nil
}
3 changes: 1 addition & 2 deletions internal/databases/redis/rdb_backup_fetch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"os/exec"

"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/databases/redis/archive"
"github.com/wal-g/wal-g/pkg/storages/storage"
"github.com/wal-g/wal-g/utility"
)

func HandleBackupFetch(ctx context.Context, folder storage.Folder, backupName string, restoreCmd *exec.Cmd, _ *archive.FolderInfo) error {
func HandleBackupFetch(ctx context.Context, folder storage.Folder, backupName string, restoreCmd *exec.Cmd) error {
backup, err := internal.GetBackupByName(backupName, utility.BaseBackupPath, folder)
if err != nil {
return err
Expand Down

0 comments on commit bd7f0ce

Please sign in to comment.