12

Currently we are storing our user sessions in memcached, our web apps are running with PHP 5.3.6 and Apache 2.2.3.

We will be replacing our memcached server, I am wondering if there is a way we can transfer the data from one memcached server to another so that the user sessions are still there. (To minimize downtime)

Although I have read from the FAQ http://code.google.com/p/memcached/wiki/FAQ#How_can_you_dump_data_from_or_load_data_into_memcached? that it is probably not possible to do that...but I am hoping if someone have some tools or workaround to achieve this.

Thanks!

Best regards

forestclown
  • 1,582
  • 4
  • 25
  • 39

2 Answers2

15

It's possible with memcached-tool.

memcached-tool 10.1.2.30:11211 dump | nc 127.0.0.1 11211
Ilari Stenroth
  • 151
  • 1
  • 3
  • 3
    in case you need to find it, memcached-tool is found in `/usr/share/memcached/scripts` on debian. – phirschybar Apr 30 '15 at 14:05
  • I wrote some scripts to automate this process on startup using systemd. https://github.com/ticpu/tools/tree/master/memcached-replicate – TiCPU May 18 '16 at 23:07
  • This worked, I successfully moved my memcache data to a new server without any issue. – rayhan Jan 26 '18 at 15:23
  • On big memcached (~500k items), I had to dump into a temporary file and inject it on other node. – fraff May 11 '21 at 14:09
4

Your best bet is to probably add some code into your system that, when a user visits, writes the session into both the new server and the old one, and then let them run in parallel for a while, then turn off the old server. That way you can "warm up" the new server without actually depending on it, and then swap over once most of the sessions are moved over.

You'll still lose some sessions, but the most frequent visitors won't notice anything because their sessions will have been moved over.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Thanks Amber, is a great suggestion. But I doubt we are able to tune our codes at this point to achieve this. – forestclown Oct 06 '11 at 03:03
  • 1
    Then you're probably just going to have to swap it out. Memcache isn't designed to be a persistent store - it's best to design your website so that you can handle losing the contents of memcache (or if not, run a multi-machine memcache cluster so that you can rotate individual servers in and out without losing the entire cluster). – Amber Oct 06 '11 at 03:07
  • 1
    You might want to check out tcpcopy (http://code.google.com/p/tcpcopy/) it will allow you to split a tcp stream to both of your memcached servers, new and old. – mikewied Oct 06 '11 at 17:35