Skip to content

Instantly share code, notes, and snippets.

@trunknx
Last active September 12, 2022 23:03
Show Gist options
  • Save trunknx/7657ad8d8290a91f87ce7db3030f10a0 to your computer and use it in GitHub Desktop.
Save trunknx/7657ad8d8290a91f87ce7db3030f10a0 to your computer and use it in GitHub Desktop.
#Osx
config dir: /usr/local/etc/redis.conf
db dif: /usr/local/var/db/
STOP REDIS : brew services stop redis
START REDIS: brew services start redis
#Ubuntu
config dir: /etc/redis/redis.conf
db dif: /var/lib/redis
STOP REDIS : sudo systemctl stop redis
START REDIS: sudo systemctl start redis
# OR
STOP REDIS : /etc/init.d/redis-server stop
START REDIS: /etc/init.d/redis-server start
#Backup
Firstly access redis-cli to get redis.conf info.
cat /usr/local/etc/redis.conf |grep '^dir '|cut -d' ' -f2
redis-cli bgsave
cp /usr/local/var/db/redis/dump.rdb ~/dump.$(date +%Y%m%d%H%M).rdb
#Restore
cat /usr/local/etc/redis.conf |grep 'appendonly '|cut -d' ' -f2
AOF = no:
STOP REDIS
mv /var/lib/redis/dump.rdb /var/lib/redis/dump.rdb.back
cp dump.201812291040.rdb /usr/local/var/db/redis/dump.rdb
chown redis:redis dump.rdb
START REDIS
AOF = yes:
STOP REDIS
cd /var/lib/redis/
mv /var/lib/redis/dump.rdb /var/lib/redis/dump.rdb.old
mv /var/lib/redis/appendonly.aof /var/lib/redis/appendonly.aof.old
cp /backup/redis/dump.xxxxxx.rdb /var/lib/redis/dump.rdb
chown redis:redis /var/lib/redis/dump.rdb
#Verify appendonly is set to "no":
cat /etc/redis/redis.conf |grep 'appendonly '|cut -d' ' -f2
#Next start the Redis server and run the following command to create new appendonly.aof file:
START REDIS
redis-cli bgrewriteaof
#Check the progress (0 - done, 1 - not yet):
redis-cli info | grep aof_rewrite_in_progress
STOP REDIS
#After it finished, enable AOF again by changing appendonly in /etc/redis/redis.conf file to yes
START REDIS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment