lxc_snapshot.c revision 813a4837659d5d7a2c0d0abe03c87196747217e9
/*
*
* Copyright � 2013 Serge Hallyn <serge.hallyn@ubuntu.com>.
* Copyright � 2013 Canonical Ltd.
*
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "../lxc/lxccontainer.h"
#include <stdio.h>
#include <libgen.h>
#include <unistd.h>
#include <ctype.h>
#include "arguments.h"
#include "utils.h"
char *newname;
char *snapshot;
#define DO_SNAP 0
#define DO_LIST 1
#define DO_RESTORE 2
int action;
int print_comments;
char *commentfile;
int do_snapshot(struct lxc_container *c)
{
int ret;
if (ret < 0) {
ERROR("Error creating a snapshot");
return -1;
}
return 0;
}
void print_file(char *path)
{
if (!path)
return;
if (!f)
return;
}
if (line)
fclose(f);
}
int do_list_snapshots(struct lxc_container *c)
{
struct lxc_snapshot *s;
int i, n;
n = c->snapshot_list(c, &s);
if (n < 0) {
ERROR("Error listing snapshots");
return -1;
}
if (n == 0) {
printf("No snapshots\n");
return 0;
}
for (i=0; i<n; i++) {
if (print_comments)
print_file(s[i].comment_pathname);
s[i].free(&s[i]);
}
free(s);
return 0;
}
{
return 0;
return -1;
}
{
switch (c) {
case 'C': print_comments = true; break;
}
return 0;
}
static const struct option my_longopts[] = {
};
static struct lxc_arguments my_args = {
.progname = "lxc-snapshot",
.help = "\
--name=NAME [-P lxcpath] [-L [-C]] [-c commentfile] [-r snapname [newname]]\n\
\n\
lxc-snapshot snapshots a container\n\
\n\
Options :\n\
-n, --name=NAME NAME for name of the container\n\
-L, --list list snapshots\n\
-C, --showcomments show snapshot comments in list\n\
-c, --comment=file add file as a comment\n\
-r, --restore=name restore snapshot name, i.e. 'snap0'\n",
.options = my_longopts,
};
/*
* lxc-snapshot -P lxcpath -n container
* lxc-snapshot -P lxcpath -n container -l
* lxc-snapshot -P lxcpath -n container -r snap3 recovered_1
*/
{
struct lxc_container *c;
int ret = 0;
exit(1);
ERROR("Too many arguments");
return -1;
}
exit(1);
if (geteuid()) {
exit(1);
}
}
if (!c) {
exit(1);
}
switch(action) {
case DO_SNAP:
ret = do_snapshot(c);
break;
case DO_LIST:
ret = do_list_snapshots(c);
break;
case DO_RESTORE:
break;
}
}