diff --git a/README.md b/README.md index 5c7a963..3418bcc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ redis-shake is a tool for Redis data migration and data filtering. - ## Feature * 🚄 High performance @@ -16,7 +15,8 @@ redis-shake is a tool for Redis data migration and data filtering. * 💖 Support `restore` mode and `sync` mode * ☁️ Support Aliyun Redis and ElastiCache -For older versions of redis-shake (support codis, twemproxy) please visit [here](https://github.com/alibaba/RedisShake/tree/develop). +For older versions of redis-shake (support codis, twemproxy) please +visit [here](https://github.com/alibaba/RedisShake/tree/develop). ![redis-shake2.PNG](https://s2.loli.net/2022/07/10/OZrSGutknlI8XNp.png) @@ -42,7 +42,7 @@ sh build.sh ## Usage -1. Edit `redis-shake.toml` or `restore.toml` and modify the source and target configuration items in it. +1. Edit `sync.toml` or `restore.toml`. 2. Start redis-shake. ```shell @@ -55,7 +55,7 @@ sh build.sh ## Configure -The redis-shake configuration file refers to `redis-shake.toml` or `restore.toml`. +The redis-shake configuration file refers to `sync.toml` or `restore.toml`. ## Data filtering @@ -63,7 +63,7 @@ redis-shake supports custom filtering rules using lua scripts. redis-shake can b the following command: ```shell -./bin/redis-shake redis-shake.toml filter/xxx.lua +./bin/redis-shake sync.toml filter/xxx.lua ``` Some following filter templates are provided in `filter` directory: diff --git a/build.sh b/build.sh index 980ab7a..2a32808 100755 --- a/build.sh +++ b/build.sh @@ -24,14 +24,14 @@ for g in "linux" "darwin"; do done done -cp redis-shake.toml "$BIN_DIR" +cp sync.toml "$BIN_DIR" cp restore.toml "$BIN_DIR" if [ "$1" == "dist" ]; then echo "[ DIST ]" cd bin cp -r ../filters ./ - tar -czvf ./redis-shake.tar.gz ./redis-shake.toml ./restore.toml ./redis-shake-* ./filters + tar -czvf ./redis-shake.tar.gz ./sync.toml ./restore.toml ./redis-shake-* ./filters rm -rf ./filters cd .. fi diff --git a/cmd/redis-shake/main.go b/cmd/redis-shake/main.go index c9c5f64..5f7b7c7 100644 --- a/cmd/redis-shake/main.go +++ b/cmd/redis-shake/main.go @@ -17,11 +17,12 @@ import ( func main() { if len(os.Args) < 2 || len(os.Args) > 3 { - fmt.Println("Usage: redis-shake ") - fmt.Println("Example: redis-shake config.toml lua.lua") + fmt.Println("Usage: redis-shake ") + fmt.Println("Example: redis-shake config.toml filter.lua") os.Exit(1) } + // load filter file if len(os.Args) == 3 { luaFile := os.Args[2] filter.LoadFromFile(luaFile) @@ -40,6 +41,7 @@ func main() { log.Infof("No lua file specified, will not filter any cmd.") } + // start pprof if config.Config.Advanced.PprofPort != 0 { go func() { err := http.ListenAndServe(fmt.Sprintf("localhost:%d", config.Config.Advanced.PprofPort), nil) @@ -64,12 +66,12 @@ func main() { // create reader source := &config.Config.Source var theReader reader.Reader - if source.Type == "sync" { + if config.Config.Type == "sync" { theReader = reader.NewPSyncReader(source.Address, source.Username, source.Password, source.IsTLS, source.ElastiCachePSync) - } else if source.Type == "restore" { + } else if config.Config.Type == "restore" { theReader = reader.NewRDBReader(source.RDBFilePath) } else { - log.Panicf("unknown source type: %s", source.Type) + log.Panicf("unknown source type: %s", config.Config.Type) } ch := theReader.StartRead() diff --git a/internal/config/config.go b/internal/config/config.go index 4dfbd83..6ce919d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -10,13 +10,15 @@ import ( ) type tomlSource struct { - Type string `toml:"type"` + // sync mode Address string `toml:"address"` Username string `toml:"username"` Password string `toml:"password"` IsTLS bool `toml:"tls"` ElastiCachePSync string `toml:"elasticache_psync"` - RDBFilePath string `toml:"rdb_file_path"` + + // restore mode + RDBFilePath string `toml:"rdb_file_path"` } type tomlTarget struct { @@ -49,6 +51,7 @@ type tomlAdvanced struct { } type tomlShakeConfig struct { + Type string Source tomlSource Target tomlTarget Advanced tomlAdvanced @@ -57,8 +60,9 @@ type tomlShakeConfig struct { var Config tomlShakeConfig func init() { + Config.Type = "sync" + // source - Config.Source.Type = "sync" Config.Source.Address = "" Config.Source.Username = "" Config.Source.Password = "" diff --git a/restore.toml b/restore.toml index 81aaa5f..dbf6e63 100644 --- a/restore.toml +++ b/restore.toml @@ -1,5 +1,6 @@ +type = "restore" + [source] -type = "restore" # sync, restore # Path to the dump.rdb file. Absolute path or relative path. Note # that relative paths are relative to the dir directory. rdb_file_path = "dump.rdb" diff --git a/redis-shake.toml b/sync.toml similarity index 93% rename from redis-shake.toml rename to sync.toml index 996bc1d..79eb676 100644 --- a/redis-shake.toml +++ b/sync.toml @@ -1,5 +1,6 @@ +type = "sync" + [source] -type = "sync" # sync or restore address = "127.0.0.1:6379" username = "" # keep empty if not using ACL password = "" # keep empty if no authentication is required @@ -7,7 +8,7 @@ tls = false elasticache_psync = "" # using when source is ElastiCache. ref: https://github.com/alibaba/RedisShake/issues/373 [target] -type = "standalone" # standalone or cluster +type = "standalone" # "standalone" or "cluster" # When the target is a cluster, write the address of one of the nodes. # redis-shake will obtain other nodes through the `cluster nodes` command. address = "127.0.0.1:6380" diff --git a/test/assets/empty.toml b/test/assets/empty.toml index 98517ef..9144564 100644 --- a/test/assets/empty.toml +++ b/test/assets/empty.toml @@ -1,5 +1,6 @@ +type = "sync" + [source] -type = "sync" # sync or restore address = "127.0.0.1:6379" username = "" # keep empty if not using ACL password = "" # keep empty if no authentication is required