Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore a redis backup in a redis container?

Tags:

docker

redis

I have a redis container. I would like to back it up and reimport the backup on another machine in another redis container.

I followed theses steps:

# Create the original redis container
docker run --name redis -d redis:3.0.3 redis-server --appendonly yes

# add a key inside it for the tests
docker run -it --link redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
> SET foo bar
OK

# backup this container
docker run --volumes-from redis -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /data

# I now have a backup.tar file on my system and I transfer it on another machine
# Recreate a redis container
docker run --name redis2 -d redis:3.0.3 redis-server --appendonly yes

# restore the backup
docker run --volumes-from redis2 -v $(pwd):/backup ubuntu sh -c "cd / && tar xvf /backup/backup.tar"

# check if the backup has been correctly restored
docker run -it --link redis2:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
> GET foo
(nil)

The backup is not restored properly. What am I doing wrong?

like image 774
poiuytrez Avatar asked Aug 19 '15 09:08

poiuytrez


1 Answers

I found a way to do it.

# untar the backup
tar -xvf backup.tar

# create a redis container an mounting the backup as the data folder
docker run --name redis2 -v /home/docker/data:/data -d redis:3.0.3 redis-server --appendonly yes

# test
docker run -it --link redis2:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
> get foo
"bar"

It works but it feels "wrong".

like image 181
poiuytrez Avatar answered Oct 11 '22 18:10

poiuytrez