Skip to content

Instantly share code, notes, and snippets.

@Om4ar
Forked from basiszwo/google-cloud-memorystore-dump.md
Last active June 14, 2021 09:21
Show Gist options
  • Save Om4ar/5f1b09d362623fa242c2de8d91ad691a to your computer and use it in GitHub Desktop.
Save Om4ar/5f1b09d362623fa242c2de8d91ad691a to your computer and use it in GitHub Desktop.
Dump Redis rdb file from Google Cloud MemoryStore
First, create a dump on server A.
A$ redis-cli
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/var/lib/redis/"
127.0.0.1:6379> SAVE
OK
This ensures dump.rdb is completely up-to-date, and shows us where it is stored (/var/lib/redis/dump.rdb in this case). dump.rdb is also periodically written to disk automatically.
Next, copy it to server B:
A$ scp /var/lib/redis/dump.rdb myuser@B:/tmp/dump.rdb
Stop the Redis server on B, copy dump.rdb (ensuring permissions are the same as before), then start.
B$ sudo service redis-server stop
B$ sudo cp /tmp/dump.rdb /var/lib/redis/dump.rdb
B$ sudo chown redis: /var/lib/redis/dump.rdb
B$ sudo service redis-server start
The version of Redis on B must be greater or equal than that of A, or you may hit compatibility issues.

Dumping a redis rdb file from a Google Cloud MemoryStore is easier than expected using redis-cli

Command

redis-cli -h <IP of MemoryStore Instance> --rdb dump.rdb

Restore rdb file from localhost to a Google Cloud MemoryStore instance

Command

rdb command is available by installing rdb-tools

rdb --command protocol ~/dump.rdb | redis-cli -h <IP of MemoryStore Instance> -p <Port of MemoryStore Instance> --pipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment