lxc_snapshot.c revision f10fad2f53e3f4f2f862bacf218a5aa7feceb505
/*
*
* 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 "config.h"
#include <stdio.h>
#include <libgen.h>
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <lxc/lxccontainer.h>
#include "lxc.h"
#include "log.h"
#include "bdev.h"
#include "arguments.h"
#include "utils.h"
static char *newname;
static char *snapshot;
#define DO_SNAP 0
#define DO_LIST 1
#define DO_RESTORE 2
#define DO_DESTROY 3
static int action;
static int print_comments;
static char *commentfile;
static int do_snapshot(struct lxc_container *c)
{
int ret;
if (ret < 0) {
ERROR("Error creating a snapshot");
return -1;
}
return 0;
}
static void print_file(char *path)
{
if (!path)
return;
if (!f)
return;
}
fclose(f);
}
static 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;
}
static int do_restore_snapshots(struct lxc_container *c)
{
return 0;
return -1;
}
static int do_destroy_snapshots(struct lxc_container *c)
{
bool bret;
bret = c->snapshot_destroy_all(c);
else
if (bret)
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\
-d, --destroy=name destroy snapshot name, i.e. 'snap0'\n\
use ALL to destroy all snapshots\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");
exit(1);
}
exit(1);
if (geteuid()) {
exit(1);
}
}
if (!c) {
exit(1);
}
if (!c->may_control(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:
ret = do_restore_snapshots(c);
break;
case DO_DESTROY:
ret = do_destroy_snapshots(c);
break;
}
if (ret == 0)
}