>  기사  >  백엔드 개발  >  Redis 데이터 백업 및 복구 방법

Redis 데이터 백업 및 복구 방법

小云云
小云云원래의
2017-12-14 14:06:412483검색

이 기사에서는 간단하고 투박한 Redis 데이터 백업 및 복구 방법, 다양한 호스트에서 Redis 데이터를 마이그레이션하는 예, 백업 스크립트 구현에 대한 핵심 팁을 공유합니다.

목표: CentOS 서버의 redis 데이터를 Mac에 복사

단계:

CentOS에서 덤프 파일 위치 찾기


vi /etc/redis.conf
dbfilename dump.rdb 
dir /var/lib/redis

설명 파일은


/var/lib/redis/dump.rdb
에 있습니다.

Mac에서


vi /usr/local/etc/redis.conf


dbfilename dump.rdb 
dir /usr/local/var/db/redis

에서 덤프 파일의 위치를 ​​찾습니다. 서버의 dump.rdb를 Mac 컴퓨터에 복사합니다


scp root@dv:/var/lib/redis/dump.rdb ./

Mac에서 Redis를 다시 시작


launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist 
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist


PS: 백업 script
다음 스크립트를 참조하세요.


#! /bin/bash

PATH=/usr/local/bin:$PATH
redis-cli SAVE

date=$(date +"%Y%m%d")
cp /var/lib/redis/6379/dump.rdb /data01/cache_backup/$date.rdb

echo "done!"

위 스크립트를 사용하면 cron 또는 기타 방법을 사용하여 Redis 데이터 파일을 백업할 수 있습니다. 자세한 내용은 다음과 같습니다.
redis의 rdb 파일은 항상 메모리 데이터의 완전한 이미지가 아니기 때문에 SAVE를 먼저 수행해야 합니다. 즉, 백업 전에 SAVE를 수행해야 합니다. 즉, SAVE 명령을 보낸 후 복사해야 합니다. rdb 파일입니다.
rdb의 특정 경로는 반드시 위 경로일 필요는 없으며 redis 구성 파일 /etc/redis/6379.conf


# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis/6379

에서 찾을 수 있습니다. 관련 권장 사항:

MySQL 데이터베이스 데이터 백업에 대한 자세한 설명 and Recovery_MySQL

MySQL 데이터베이스의 데이터 백업 및 복구에 대한 자세한 설명

역사상 가장 간단한 MySQL 데이터 백업 및 복구 튜토리얼

위 내용은 Redis 데이터 백업 및 복구 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.