如何备份/移动LXC容器? [英] How do I Backup / Move LXC containers?

查看:369
本文介绍了如何备份/移动LXC容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想备份lxc容器.我们的服务器上装有12.04 LTS ubuntu server,并且我已经在其中安装了LXC - 1.0.0.alpha2.我想将我们的Ubuntu服务器更新为14.04 LTS.所以我要做的是备份LXC容器->将操作系统升级到14.04->恢复LXC容器.在早期版本(我猜是0.7.5)中,有lxc-backup和lxc-restore,但是对于1.0.0.alpha2,我们没有备份和还原操作.我如何备份lxc容器.我花了3个多小时的时间将容器文件夹(/var/lib/lxc/my_container/)复制到pendrive中,然后将其粘贴到另一台12.04 LTS服务器中,但是它无法正常工作,

I want to take lxc container backup. We have server with 12.04 LTS ubuntu server and I have installed LXC - 1.0.0.alpha2 in it. I wanted to update our ubuntu server to 14.04 LTS. So what I want to do is have LXC containers backed up -> upgrade OS to 14.04 -> restore LXC containers. With earlier version(0.7.5 I guess) there was lxc-backup and lxc-restore but with 1.0.0.alpha2 we don't have backup and restore operations. How can I have lxc containers backup. I spent more than 3 hours with copy container folder(/var/lib/lxc/my_container/) into pendrive and paste it in another 12.04 LTS server but it is not working the error am getting is,

#sudo lxc-start -n my_container
lxc-start: invalid sequence number 1, expected 4.
lxc-start: failed to spwan "my_container"

那我怎么期望它可以在升级的14.04服务器操作系统中工作.

then how can I expect that it will work in upgraded 14.04 server OS.

是否有备份lxc容器的想法?

Any Idea to have lxc-container backup?

推荐答案

2016年3月29日

如果您偶然发现了这篇文章,我的回答实际上是关于在系统之间移动容器,因为这似乎是一个要问的问题.

March 29, 2016

In case you stumbled upon this post, my answer is really about moving the LXC containers between systems, since that seemed to be the question being asked.

如果您要备份您的LXC容器,请参阅@Stuart的答案以获取一些不错的选择.

If you want to backup your LXC containers, see @Stuart's answer for some great options.

这是我在系统之间迁移LXC容器的方式.我已经成功地将基于ubuntu的12.04容器移动到了14.04主机上,并且它们运行良好.

This is how I migrate LXC containers between systems. I've successfully moved ubuntu based 12.04 containers to a 14.04 host, and they work great.

  • 关闭容器

# lxc-stop -n $NAME

  • 归档容器rootfs&配置

    # cd /var/lib/lxc/$NAME/
    # tar --numeric-owner -czvf container_fs.tar.gz ./*
    

    --numeric-owner标志非常重要!没有它,容器可能无法启动,因为uid/gids在提取的文件系统中被破坏了. 当tar创建档案时,它将保留用户/组所有权信息.默认情况下,解压缩时,tar尝试使用运行tar的系统上的ID解析归档用户/组所有权名称.这是为了确保新系统上的用户所有权得到解决,以防UID数值在系统之间不同.

    The --numeric-owner flag is very important! Without it, the container may not boot because the uid/gids get mangled in the extracted filesystem. When tar creates an archive, it preserves user / group ownership information. By default, when extracting, tar tries to resolve the archive user/group ownership names with the ids on the system running tar. This is intended to ensure that user ownership is resolved on the new system, in case the UID numeric values differ between systems.

    这对LXC文件系统不利,因为打算将数字uid/gid所有权保留给整个文件系统.如果将其解析为其他值,则会发生坏事.

    将文件复制到新服务器

    # rsync -avh container_fs.tar.gz user@newserver:/var/lib/lxc/
    

  • 提取rootfs

    # mkdir /var/lib/lxc/$NAME/
    # cd /var/lib/lxc/$NAME/
    # tar --numeric-owner -xzvf container_fs.tar.gz .
    

  • 如果您使用的是叠加层支持的容器,则还需要迁移新容器所基于的容器.最后,您可能会看到有关跳过套接字文件的一些警告:

    If you're using an overlay backed container, you'll also need to migrate the container this new one is based off of. Lastly, you might see a few warnings about skipped socket files:

    tar: /var/lib/lxc/$NAME/rootfs/dev/log: socket ignored

    我已经忽略了此错误,并且我管理的任何容器都没有任何问题.如果您还有其他问题,请将错误消息添加到原始帖子中,我将详细说明.

    I've ignored this error, and haven't had any issues with any of the containers I manage. If you have further issues, add your error messages to the original post and I'll elaborate.

    这篇关于如何备份/移动LXC容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆