百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>数据库> Memcached备份、还原的的示例
分享文章到:

Memcached备份、还原的的示例

发布时间:01/15 来源: 浏览: 关键词:
理论上, Memcached 不需要做备份、还原这种事情, 因为存在彦面的东西应该都是 Cache, 没有使用 Memcached 的话, 速度应该只会比较慢, 而不应该会有影响才对.

注1: Memcached restart 后, 所有资料都会清空
注2: 这次遇到的主要是实验用的项目, 刚好要搬机器, 实验不想中断, 所以才用此方式

Memcached 备份、还原的方式

先看 Memcached 的限制条件:

Key 长度 250 bytes
预设 Value 1M(可透过 -I 2M 设定)
设定过期时间的话, 过期时间最多设定30天 (设 0 为永不过期的意思)
Ref: NewCommands - memcached - Make Me a Sandwich - Memcached
一般 Memcached 能提供的方式都是 Dump key, 然后自己再写程式捞出来, 做写入(ADD)的动作, 这边有比较简易的操作方式. (利用 memcached-tool + nc 来达成)

Memcached 备份、还原的步骤

假设要将 192.168.1.1 的 memcached data 备份到 localhost (192.168.1.1. 那台 memcached ip 不能跑 localhost)

 代码如下
wget https://raw.githubusercontent.com/memcached/memcached/master/scripts/memcached-tool
chmod +x ./memcached-tool
./memcached-tool 192.168.1.1:11211 dump > data # 备份, data 内容大致如下:
add 19bc2701c3898279jkds1jklc272b35f 0 1413178136 506
a:3:{s:4:"text";..................}

注: 1413178136 # timestamp, 若是资料过期, 汇入后找不到

 代码如下
nc localhost 11211 < data # 还原
# 验证
./memcached-tool localhost:11211 dump > local-data
wc -l local-data
wc -l data

看看上述两个资料笔数是否正确
上述参考自此篇: memcache dump and load
PHP 版 Memcached backup / restore

另外有 PHP 的 Memcached backup / restore 程式, 可以参考看看(注: 我没用过)

下述摘录自此篇: Meabed/memcached-php-backup-restore - Save / Restore data from Memcache to File

php m.php -h 127.0.0.1 -p 112112 -op restore
-h : Memcache Host address ( default is 127.0.0.1 )
-p : Memcache Port ( default is 11211 )
-p : Operation is required !! ( available options is : restore , backup )
php m.php -h 127.0.0.1 -p 112112 -op backup
php m.php -h 127.0.0.1 -p 112112 -op restore
其它 Memcached 相关工具

Memcached 有其它方便使用的工具, 可以尝试看看.

sudo apt-get install libmemcached-tools # 下述取自: Welcome to the libmemcached documentation

memcapable - Checking a Memcached server capibilities and compatibility
memcat - "cat" data from a server
memcp - Copy data to a server
memdump - Dumping your server
memerror - translate an error code to a string
memflush - flush all data from a server
memrm - Remove data from a server
memslap - Load testing and benchmarking a server
memaslap - Load testing and benchmarking a server
memstat - Gather statistics from a server
memexist - Check for the existance of a key
memparse - Parse an option string
memping - Test to see if a server is available.
memtouch - Touches a key.
ex: memccat --servers=127.0.0.1

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有2人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板