summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJoe Thornber <thornber@redhat.com>2001-12-20 16:05:14 +0000
committerJoe Thornber <thornber@redhat.com>2001-12-20 16:05:14 +0000
commit2041d905a93c14df744f2af41fee0060c83b5178 (patch)
tree99e9b46bc3ed1a3e98909692d3c899b9910d7d04 /tools
parent493793dcbcb86b3ea01b6afcb916f42bcecda4eb (diff)
downloadlvm2-2041d905a93c14df744f2af41fee0060c83b5178.tar.gz
lvm2-2041d905a93c14df744f2af41fee0060c83b5178.tar.xz
lvm2-2041d905a93c14df744f2af41fee0060c83b5178.zip
o Added a quick vgcfgbackup, needs parameters as yet.
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.in3
-rw-r--r--tools/commands.h3
-rw-r--r--tools/lvm.c13
-rw-r--r--tools/stub.h1
-rw-r--r--tools/toollib.c14
-rw-r--r--tools/toollib.h2
-rw-r--r--tools/vgcfgbackup.c35
7 files changed, 49 insertions, 22 deletions
diff --git a/tools/Makefile.in b/tools/Makefile.in
index fe4fa12b..2c4790bf 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -37,8 +37,9 @@ SOURCES=\
pvdisplay.c \
pvscan.c \
toollib.c \
- vgck.c \
+ vgcfgbackup.c \
vgchange.c \
+ vgck.c \
vgcreate.c \
vgdisplay.c \
vgextend.c \
diff --git a/tools/commands.h b/tools/commands.h
index 46aa976b..647f9c79 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -336,7 +336,8 @@ xx(vgcfgbackup,
"\t[-h|--help] " "\n"
"\t[-v|--verbose]" "\n"
"\t[-V|--version] " "\n"
- "\t[VolumeGroupName...]\n" )
+ "\t[VolumeGroupName...]\n",
+ autobackup_ARG)
xx(vgcfgrestore,
"Restore volume group configuration",
diff --git a/tools/lvm.c b/tools/lvm.c
index 334fda5a..8db5ff3f 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -543,18 +543,9 @@ static int process_common_commands(struct command *com)
/* Set autobackup if command takes this option */
for (l = 0; l < com->num_args; l++)
- if (com->valid_args[l] == autobackup_ARG) {
- if (snprintf(backup_dir, sizeof(backup_dir),
- "%s/backup", _system_dir) < 0) {
- log_err("Backup path too long.");
- return ECMD_FAILED;
- }
-
- if (autobackup_init("/etc/lvm/backup"))
+ if (com->valid_args[l] == autobackup_ARG)
+ if (!autobackup_init(_system_dir))
return EINVALID_CMD_LINE;
- else
- break;
- }
return 0;
}
diff --git a/tools/stub.h b/tools/stub.h
index d2e2ef02..59134716 100644
--- a/tools/stub.h
+++ b/tools/stub.h
@@ -23,7 +23,6 @@ int lvmdiskscan(int argc, char **argv) {return 1;}
int lvmsadc(int argc, char **argv) {return 1;}
int lvmsar(int argc, char **argv) {return 1;}
int pvdata(int argc, char **argv) {return 1;}
-int vgcfgbackup(int argc, char **argv) {return 1;}
int vgcfgrestore(int argc, char **argv) {return 1;}
int vgexport(int argc, char **argv) {return 1;}
int vgimport(int argc, char **argv) {return 1;}
diff --git a/tools/toollib.c b/tools/toollib.c
index bf9c562a..2581265c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -7,6 +7,7 @@
#include "tools.h"
#include "format-text.h"
#include "metadata.h"
+#include "lvm-string.h"
#include <ctype.h>
#include <limits.h>
@@ -15,24 +16,23 @@ static int _autobackup = 1;
static char _backup_dir[PATH_MAX];
static int _period = 7; /* backups will be kept for at least 7 days */
static int _min_backups = 10; /* always have at least ten backups, even
- * if they're old than the period */
+ * if they're older than the period */
/*
* Work out by looking at command line, config
* file and environment variable whether we should
* do an autobackup.
*/
-int autobackup_init(const char *dir)
+int autobackup_init(const char *system_dir)
{
char *lvm_autobackup;
- if (strlen(dir) > sizeof(_backup_dir) - 1) {
- log_err("Backup directory (%s) too long.", dir);
+ if (lvm_snprintf(_backup_dir, sizeof(_backup_dir),
+ "%s/backup", system_dir) < 0) {
+ log_err("Backup directory (%s/backup) too long.", system_dir);
return 0;
}
- strcpy(_backup_dir, dir);
-
if (arg_count(autobackup_ARG)) {
_autobackup = !strcmp(arg_str_value(autobackup_ARG, "y"), "y");
return 1;
@@ -94,7 +94,7 @@ static int __autobackup(struct volume_group *vg)
int autobackup(struct volume_group *vg)
{
- if (!__autobackup) {
+ if (!_autobackup) {
log_print("WARNING: You don't have an automatic backup of %s",
vg->name);
return 1;
diff --git a/tools/toollib.h b/tools/toollib.h
index ce81dcba..559ee36a 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -22,7 +22,7 @@
#define _LVM_TOOLLIB_H
int autobackup_set(void);
-int autobackup_init(const char *dir);
+int autobackup_init(const char *system_dir);
int autobackup(struct volume_group *vg);
int process_each_vg(int argc, char **argv,
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
new file mode 100644
index 00000000..9c79e8e8
--- /dev/null
+++ b/tools/vgcfgbackup.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#include "tools.h"
+
+static int vg_backup_single(const char *vg_name)
+{
+ struct volume_group *vg;
+
+ log_verbose("Checking for volume group %s", vg_name);
+ if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ log_error("Volume group %s not found", vg_name);
+ return ECMD_FAILED;
+ }
+
+ log_print("Found %sactive volume group %s",
+ (vg->status & ACTIVE) ? "" : "in", vg_name);
+
+ if (!autobackup(vg)) {
+ stack;
+ return ECMD_FAILED;
+ }
+
+ log_print("Volume group %s successfully backed up.", vg_name);
+ return 0;
+}
+
+int vgcfgbackup(int argc, char **argv)
+{
+ return process_each_vg(argc, argv, &vg_backup_single);
+}
+