summaryrefslogtreecommitdiffstats
path: root/tools/vgcfgbackup.c
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2004-06-19 18:55:29 +0000
committerAlasdair Kergon <agk@redhat.com>2004-06-19 18:55:29 +0000
commit8d267798dbd41545de724d9848a4d2af6cd4c0a0 (patch)
treeb7a63dd9a6fc056ff5e9bb1fa2df97168086eae0 /tools/vgcfgbackup.c
parent374df1cf8e385769a04c503abd289187c442eb63 (diff)
downloadlvm2-8d267798dbd41545de724d9848a4d2af6cd4c0a0.tar.gz
lvm2-8d267798dbd41545de724d9848a4d2af6cd4c0a0.tar.xz
lvm2-8d267798dbd41545de724d9848a4d2af6cd4c0a0.zip
vgcfgbackup -f accepts template with %s for VG name.
Diffstat (limited to 'tools/vgcfgbackup.c')
-rw-r--r--tools/vgcfgbackup.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index e1221694..987896a3 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -15,10 +15,42 @@
#include "tools.h"
+static char *_expand_filename(const char *template, const char *vg_name,
+ char **last_filename)
+{
+ char *filename;
+
+ if (security_level())
+ return dbg_strdup(template);
+
+ filename = dbg_malloc(PATH_MAX);
+ if (snprintf(filename, PATH_MAX, template, vg_name) < 0) {
+ log_error("Error processing filename template %s",
+ template);
+ dbg_free(filename);
+ return NULL;
+ }
+ if (*last_filename && !strncmp(*last_filename, filename,
+ strlen(template))) {
+ log_error("VGs must be backed up into different files. "
+ "Use %%s in filename for VG name.");
+ dbg_free(filename);
+ return NULL;
+ }
+
+ dbg_free(*last_filename);
+ *last_filename = filename;
+
+ return filename;
+}
+
static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg, int consistent,
void *handle)
{
+ char **last_filename = (char **)handle;
+ char *filename;
+
if (!vg) {
log_error("Volume group \"%s\" not found", vg_name);
return ECMD_FAILED;
@@ -28,8 +60,13 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
log_error("Warning: Volume group \"%s\" inconsistent", vg_name);
if (arg_count(cmd, file_ARG)) {
- backup_to_file(arg_value(cmd, file_ARG), vg->cmd->cmd_line, vg);
+ if (!(filename = _expand_filename(arg_value(cmd, file_ARG),
+ vg->name, last_filename))) {
+ stack;
+ return ECMD_FAILED;
+ }
+ backup_to_file(filename, vg->cmd->cmd_line, vg);
} else {
if (!consistent) {
log_error("No backup taken: specify filename with -f "
@@ -53,13 +90,16 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
{
int ret;
+ char *last_filename = NULL;
if (partial_mode())
init_pvmove(1);
- ret = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, NULL,
+ ret = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, &last_filename,
&vg_backup_single);
+ dbg_free(last_filename);
+
init_pvmove(0);
return ret;