How to Take Redis Backup and Restore from One Server to Another on Ubuntu?


Redis is an in-memory data structure store widely used as a cache, message broker, and database. To ensure data safety and continuity, it's crucial to back up Redis data and restore it to another server when needed. In this guide, we'll walk you through the steps to back up and restore Redis from one Ubuntu server to another.
Step 1: Check Redis Status on Source Server
Before taking a backup, ensure Redis is running on the source server.
sudo systemctl status redis
If Redis is not running, start it using:
sudo systemctl start redis
Step 2: Locate Redis Data Files
Redis stores its data in an RDB (Redis Database) file. The default location is:
/var/lib/redis/dump.rdb
To confirm the file location, check the Redis configuration file:
grep 'dir' /etc/redis/redis.conf
Step 3: Backup Redis Database
To ensure data consistency, save the Redis snapshot before copying:
redis-cli save
Once saved, copy the dump file to a safe location:
sudo cp /var/lib/redis/dump.rdb /backup/
You can also use tar to compress it:
tar -czvf redis_backup.tar.gz /var/lib/redis/dump.rdb
Step 4: Transfer Backup to Destination Server
Use SCP or rsync to transfer the backup to another server.
Using SCP:
scp /backup/redis_backup.tar.gz user@destination-server:/backup/
Using rsync:
rsync -avz /backup/redis_backup.tar.gz user@destination-server:/backup/
Step 5: Stop Redis on the Destination Server
Before restoring, stop Redis to avoid data corruption.
sudo systemctl stop redis
Step 6: Restore Redis Backup
Extract the backup file:
tar -xzvf /backup/redis_backup.tar.gz -C /var/lib/redis/
Set correct ownership and permissions:
sudo chown redis:redis /var/lib/redis/dump.rdb
sudo chmod 660 /var/lib/redis/dump.rdb
Step 7: Start Redis and Verify Data
Restart Redis on the destination server:
sudo systemctl start redis
Check if Redis is running:
sudo systemctl status redis
Verify data by connecting to Redis and checking keys:
redis-cli
keys *
Conclusion
By following these steps, you can easily back up and restore your Redis database from one Ubuntu server to another. This ensures data persistence and recovery in case of failures. For regular backups, consider automating the process using cron jobs.
Subscribe to my newsletter
Read articles from Ankit Patel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ankit Patel
Ankit Patel
👋 Hey there! So, I've been down this road of DevOps for about 4 years now. It's been quite the journey, filled with late-night debugging sessions, triumphant code deployments, and a lot of coffee. But you know what? I wouldn't trade it for the world. ⚙️ What's in My Toolkit: Alright, let's talk tech. I've got these amazing tools that make the whole DevOps world tick. You know those pipelines that magically make code travel from a developer's keyboard to the heart of production? Well, I've got Jenkins, GitLab CI/CD, and GItlab CI doing the heavy lifting there. And then there's this bit of magic called Terraform and CloudFormation that let me weave infrastructures like an artist. 🐳 Embracing Containers and Clouds: Containers are like my little creations that hold the essence of an application. Docker's my go-to wizard for that. And clouds? I've got a thing for AWS, and Google Cloud. I've set up these amazing architectures that auto-scale, heal, and keep things humming even when the virtual storms hit. 🌐 Taming the Chaos: You know that feeling when you're juggling a hundred things at once? Well, I've got my helpers for that too—Prometheus, Grafana, ELK stack, and Nagios. They're like my trusty companions, keeping watch while I navigate the DevOps wilderness. 🚀 Moments to Remember: I've had these moments when everything just clicked. Like that time I led the charge in turning this clunky old app into a slick set of microservices. It was like breathing new life into it. Oh, and remember the days before infrastructure as code? Now, I just write a script, hit a button, and voilà—stuff's deployed like magic. 🌟 Beyond the Tech: But DevOps isn't just about tech, you know? It's about connecting with teams, understanding their challenges, and finding solutions that make everyone's life easier. I'm not just a techie—I'm a listener, a problem-solver, and a bit of a dreamer too. 🔭 What's Next: As I gaze into the future, I see myself diving deeper into the world of security automation. I want to master the art of Kubernetes like it's a symphony. And multi-cloud? Yeah, that's calling my name too. Also, I'm all ears for cool open-source projects that can change the world one code commit at a time. 📞 Let's Connect: So, if you're on the hunt for someone who's not just a DevOps engineer but also a friend to your development and ops teams, I'm here. Let's have a chat, exchange stories, and who knows, we might just cook up some incredible DevOps magic together. Ready to make tech dreams come true? 🚀🔗