The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1943
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Currently, LXC only allows to create new containers using a snapshot if the source container is shutdown. While it is safer to do so, it is not required to shutdown the source container to get an working clone. This is because creating a snapshot is much like an unexpected power outage; most Filesystems and databases are built from ground up to handle this case with minimum impact. I have deployed LXC in a way that i have "live" containers that receive traffic and some sandbox/dev containers that are for testing with live data and environment. Using the --allowrunning option, i can reset and retest the sandboxes multiple times without downtime of the live containers. i tested this against lxc-2.0 branch and have had no problems so far. Signed-off-by: Bernd Helm <bernd.helm at helmundwalter.de>
From bc9eda0702b5a30c588c381eb6c22eba8e8d6cd7 Mon Sep 17 00:00:00 2001 From: Bernd Helm <bernd.h...@helmundwalter.de> Date: Thu, 23 Nov 2017 14:49:42 +0100 Subject: [PATCH] added allowrunning command line option for snapshotting alive containers --- doc/lxc-copy.sgml.in | 11 +++++++++++ src/lxc/arguments.h | 1 + src/lxc/lxccontainer.c | 5 ++--- src/lxc/lxccontainer.h | 1 + src/lxc/tools/lxc_copy.c | 7 +++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/lxc-copy.sgml.in b/doc/lxc-copy.sgml.in index 475feb05b..6e63e98c6 100644 --- a/doc/lxc-copy.sgml.in +++ b/doc/lxc-copy.sgml.in @@ -55,6 +55,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA <arg choice="opt">-p, --newpath <replaceable>newpath</replaceable></arg> <arg choice="opt">-B, --backingstorage <replaceable>backingstorage</replaceable></arg> <arg choice="opt">-s, --snapshot</arg> + <arg choice="opt">-a, --allowrunning</arg> <arg choice="opt">-K, --keepname</arg> <arg choice="opt">-D, --keepdata</arg> <arg choice="opt">-M, --keepmac</arg> @@ -70,6 +71,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA <arg choice="req">-e, --ephemeral</arg> <arg choice="opt">-B, --backingstorage <replaceable>backingstorage</replaceable></arg> <arg choice="opt">-s, --snapshot</arg> + <arg choice="opt">-a, --allowrunning</arg> <arg choice="opt">-K, --keepname</arg> <arg choice="opt">-D, --keepdata</arg> <arg choice="opt">-M, --keepmac</arg> @@ -208,6 +210,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA </listitem> </varlistentry> + <varlistentry> + <term> <option>-a,--allowrunning </option> </term> + <listitem> + <para> Allow the creation of a Snapshot of an already running container. + This may cause data corruption or data loss depending on the used + filesystem and applications. Use with care. </para> + </listitem> + </varlistentry> + <varlistentry> <term> <option>-F,--foreground</option> </term> <listitem> diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index b07caf42b..33d19d917 100644 --- a/src/lxc/arguments.h +++ b/src/lxc/arguments.h @@ -119,6 +119,7 @@ struct lxc_arguments { int keepdata; int keepname; int keepmac; + int allowrunning; /* lxc-ls */ char *ls_fancy_format; diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 413dd375b..c7cdd3192 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -3451,9 +3451,8 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char if (container_mem_lock(c)) return NULL; - - if (!is_stopped(c)) { - ERROR("error: Original container (%s) is running", c->name); + if (!is_stopped(c) && !(flags & LXC_CLONE_ALLOW_RUNNING)) { + ERROR("error: Original container (%s) is running. Use --allowrunning if you want to force a snapshot of the running container.", c->name); goto out; } diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h index 9ea67df7f..1f5a46e98 100644 --- a/src/lxc/lxccontainer.h +++ b/src/lxc/lxccontainer.h @@ -40,6 +40,7 @@ extern "C" { #define LXC_CLONE_KEEPBDEVTYPE (1 << 3) /*!< Use the same bdev type */ #define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4) /*!< Snapshot only if bdev supports it, else copy */ #define LXC_CLONE_MAXFLAGS (1 << 5) /*!< Number of \c LXC_CLONE_* flags */ +#define LXC_CLONE_ALLOW_RUNNING (1 << 6) /*!< allow snapshot creation even if source container is running */ #define LXC_CREATE_QUIET (1 << 0) /*!< Redirect \c stdin to \c /dev/zero and \c stdout and \c stderr to \c /dev/null */ #define LXC_CREATE_MAXFLAGS (1 << 1) /*!< Number of \c LXC_CREATE* flags */ diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c index 7eddb77d6..9fa80df91 100644 --- a/src/lxc/tools/lxc_copy.c +++ b/src/lxc/tools/lxc_copy.c @@ -78,6 +78,7 @@ static const struct option my_longopts[] = { { "newpath", required_argument, 0, 'p'}, { "rename", no_argument, 0, 'R'}, { "snapshot", no_argument, 0, 's'}, + { "allowrunning", no_argument, 0, 'a'}, { "foreground", no_argument, 0, 'F'}, { "daemon", no_argument, 0, 'd'}, { "ephemeral", no_argument, 0, 'e'}, @@ -114,6 +115,7 @@ Options :\n\ -p, --newpath=NEWPATH NEWPATH for the container to be stored\n\ -R, --rename rename container\n\ -s, --snapshot create snapshot instead of clone\n\ + -a, --allowrunning allow snapshot creation even if source container is running\n\ -F, --foreground start with current tty attached to /dev/console\n\ -d, --daemon daemonize the container (default)\n\ -e, --ephemeral start ephemeral container\n\ @@ -209,6 +211,8 @@ int main(int argc, char *argv[]) if (my_args.task == SNAP || my_args.task == DESTROY) flags |= LXC_CLONE_SNAPSHOT; + if (my_args.allowrunning) + flags |= LXC_CLONE_ALLOW_RUNNING; if (my_args.keepname) flags |= LXC_CLONE_KEEPNAME; if (my_args.keepmac) @@ -615,6 +619,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg) case 's': args->task = SNAP; break; + case 'a': + args->allowrunning = 1; + break; case 'F': args->daemonize = 0; break;
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel