[lxc-users] LXC Copying a running container

David Favor david at davidfavor.com
Sat Apr 21 17:19:57 UTC 2018


Tomasz Chmielewski wrote:
> On 2018-04-20 21:58, Saint Michael wrote:
>> I need to transfer a copy of a container that cannot be stopped. I
>> donĀ“t mid if the data is slightly out of sync. Is there a way to do
>> this? I tried lxc-copy and it fails because the source is running.
> 
> rsync?
> 
> On a destination server, create a container with the same operating 
> system/version.
> 
> Then copy it with rsync.
> 
> Please not that any files which are opened and in use, will most likely 
> be corrupt and unusable. Most certainly this will be true for any 
> database files, i.e. MySQL.
> 
> 
> 
> Also - if, on the source system, you have a filesystem with snapshotting 
> functionality, you can snapshot, and copy the snapshot.

LXD thinks it knows best how to do this + what LXD thinks is best simply
won't work running production sites, especially with large data containers.

Here's how I've been doing this.

1) Stop the source container on net10 machine, lets say net10:net10-clients.

lxc stop local:net10-clients

2) Now start a copy...

lxc copy local:net10-clients net11:net11-clients

3) Now restart container in another window...

lxc start local:net10-clients

4) How this works is to...

Ignore the fact that criu is no longer available
on either end of copy.

Once copy starts via rsync, there's no way (thankfully) for LXD to know you
restart the container, so all the overly complex lxd.db nonsense gets done.
Then the copy runs to completion as expected.

This is the only way I've been able to migrate live containers.

Keep in mind this works great, except database files will be corrupt.

When I'm doing this, I use a script to automate all the above actions, then
as a manual post hook (now that automatic post hooks have been removed) the
following is required.

1) Stop mysql in both source + target containers.

2) Do rsync of /var/lib/mysql from source to target container.

3) Restart mysql in both source + target containers.

This works very fast, as there will be only a few minor changes to files
in our source container, as the original rsync will have picked up the
bulk of your data.


More information about the lxc-users mailing list