]> sourceware.org Git - lvm2.git/blame - tools/vgcfgrestore.c
Reinstate accidentally-deleted line.
[lvm2.git] / tools / vgcfgrestore.c
CommitLineData
d33f2e9f 1/*
67cdbd7e 2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5a820745 3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
d33f2e9f 4 *
6606c3ae
AK
5 * This file is part of LVM2.
6 *
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
be684599 9 * of the GNU Lesser General Public License v.2.1.
6606c3ae 10 *
be684599 11 * You should have received a copy of the GNU Lesser General Public License
6606c3ae
AK
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
d33f2e9f
JT
14 */
15
16#include "tools.h"
17
60274aba 18int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
d33f2e9f 19{
aec21154 20 const char *vg_name = NULL;
8ae908a0 21
944cac93
BR
22 if (argc == 1) {
23 vg_name = skip_dev_dir(cmd, argv[0], NULL);
24 if (!validate_name(vg_name)) {
25 log_error("Volume group name \"%s\" is invalid", vg_name);
26 return ECMD_FAILED;
27 }
28 } else if (!(arg_count(cmd, list_ARG) && arg_count(cmd, file_ARG))) {
b8f47d5f 29 log_error("Please specify a *single* volume group to restore.");
d33f2e9f
JT
30 return ECMD_FAILED;
31 }
32
03888774
JT
33 /*
34 * FIXME: overloading the -l arg for now to display a
35 * list of archive files for a particular vg
36 */
6fda126d 37 if (arg_count(cmd, list_ARG)) {
944cac93 38 if (!(arg_count(cmd,file_ARG) ?
651ff9b3
AK
39 archive_display_file(cmd,
40 arg_str_value(cmd, file_ARG, "")) :
41 archive_display(cmd, vg_name))) {
42 stack;
03888774 43 return ECMD_FAILED;
651ff9b3 44 }
cfb7bfc7 45 return ECMD_PROCESSED;
03888774
JT
46 }
47
dae08226
PR
48 lvmcache_seed_infos_from_lvmetad(cmd);
49
5a820745 50 if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
8ae908a0 51 log_error("Unable to lock volume group %s", vg_name);
5a52dca9
AK
52 return ECMD_FAILED;
53 }
54
b85357cd
DW
55 if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
56 log_error("Unable to lock orphans");
cdc8e54e 57 unlock_vg(cmd, vg_name);
b85357cd
DW
58 return ECMD_FAILED;
59 }
60
b4048242
PR
61 cmd->handles_unknown_segments = 1;
62
6fda126d 63 if (!(arg_count(cmd, file_ARG) ?
8ae908a0 64 backup_restore_from_file(cmd, vg_name,
6fda126d 65 arg_str_value(cmd, file_ARG, "")) :
8ae908a0 66 backup_restore(cmd, vg_name))) {
d38bf361 67 unlock_vg(cmd, VG_ORPHANS);
cdc8e54e 68 unlock_vg(cmd, vg_name);
b8f47d5f 69 log_error("Restore failed.");
d33f2e9f
JT
70 return ECMD_FAILED;
71 }
72
8ae908a0
AK
73 log_print("Restored volume group %s", vg_name);
74
d38bf361 75 unlock_vg(cmd, VG_ORPHANS);
b85357cd 76 unlock_vg(cmd, vg_name);
cfb7bfc7 77 return ECMD_PROCESSED;
d33f2e9f 78}
This page took 0.092977 seconds and 5 git commands to generate.