]>
sourceware.org Git - lvm2.git/blob - tools/vgcfgbackup.c
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 static char *_expand_filename(const char *template, const char *vg_name
,
24 return dm_strdup(template);
26 if (!(filename
= dm_malloc(PATH_MAX
))) {
27 log_error("Failed to allocate filename.");
31 if (dm_snprintf(filename
, PATH_MAX
, template, vg_name
) < 0) {
32 log_error("Error processing filename template %s",
37 if (*last_filename
&& !strncmp(*last_filename
, filename
, PATH_MAX
)) {
38 log_error("VGs must be backed up into different files. "
39 "Use %%s in filename for VG name.");
44 dm_free(*last_filename
);
45 *last_filename
= filename
;
50 static int vg_backup_single(struct cmd_context
*cmd
, const char *vg_name
,
51 struct volume_group
*vg
,
54 char **last_filename
= (char **)handle
;
57 if (arg_count(cmd
, file_ARG
)) {
58 if (!(filename
= _expand_filename(arg_value(cmd
, file_ARG
),
59 vg
->name
, last_filename
))) {
64 if (!backup_to_file(filename
, vg
->cmd
->cmd_line
, vg
)) {
69 if (vg_read_error(vg
) == FAILED_INCONSISTENT
) {
70 log_error("No backup taken: specify filename with -f "
71 "to backup an inconsistent VG");
76 /* just use the normal backup code */
77 backup_enable(cmd
, 1); /* force a backup */
84 log_print("Volume group \"%s\" successfully backed up.", vg_name
);
85 return ECMD_PROCESSED
;
88 int vgcfgbackup(struct cmd_context
*cmd
, int argc
, char **argv
)
91 char *last_filename
= NULL
;
95 ret
= process_each_vg(cmd
, argc
, argv
, READ_ALLOW_INCONSISTENT
,
96 &last_filename
, &vg_backup_single
);
98 dm_free(last_filename
);
This page took 0.043708 seconds and 5 git commands to generate.