Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 : : * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4 : : *
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
9 : : * of the GNU Lesser General Public License v.2.1.
10 : : *
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
14 : : */
15 : :
16 : : #include "tools.h"
17 : :
18 : 0 : int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
19 : : {
20 : 0 : char *vg_name = NULL;
21 : :
22 [ # # ]: 0 : if (argc == 1) {
23 : 0 : vg_name = skip_dev_dir(cmd, argv[0], NULL);
24 [ # # ]: 0 : if (!validate_name(vg_name)) {
25 : 0 : log_error("Volume group name \"%s\" is invalid", vg_name);
26 : 0 : return ECMD_FAILED;
27 : : }
28 [ # # ][ # # ]: 0 : } else if (!(arg_count(cmd, list_ARG) && arg_count(cmd, file_ARG))) {
29 : 0 : log_error("Please specify a *single* volume group to restore.");
30 : 0 : return ECMD_FAILED;
31 : : }
32 : :
33 : : /*
34 : : * FIXME: overloading the -l arg for now to display a
35 : : * list of archive files for a particular vg
36 : : */
37 [ # # ]: 0 : if (arg_count(cmd, list_ARG)) {
38 [ # # ][ # # ]: 0 : if (!(arg_count(cmd,file_ARG) ?
39 : 0 : archive_display_file(cmd,
40 : : arg_str_value(cmd, file_ARG, "")) :
41 : 0 : archive_display(cmd, vg_name))) {
42 : 0 : stack;
43 : 0 : return ECMD_FAILED;
44 : : }
45 : 0 : return ECMD_PROCESSED;
46 : : }
47 : :
48 [ # # ]: 0 : if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
49 : 0 : log_error("Unable to lock volume group %s", vg_name);
50 : 0 : return ECMD_FAILED;
51 : : }
52 : :
53 [ # # ]: 0 : if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
54 : 0 : log_error("Unable to lock orphans");
55 : 0 : unlock_vg(cmd, vg_name);
56 : 0 : return ECMD_FAILED;
57 : : }
58 : :
59 : 0 : cmd->handles_unknown_segments = 1;
60 : :
61 [ # # ][ # # ]: 0 : if (!(arg_count(cmd, file_ARG) ?
62 : 0 : backup_restore_from_file(cmd, vg_name,
63 : : arg_str_value(cmd, file_ARG, "")) :
64 : 0 : backup_restore(cmd, vg_name))) {
65 : 0 : unlock_vg(cmd, VG_ORPHANS);
66 : 0 : unlock_vg(cmd, vg_name);
67 : 0 : log_error("Restore failed.");
68 : 0 : return ECMD_FAILED;
69 : : }
70 : :
71 : 0 : log_print("Restored volume group %s", vg_name);
72 : :
73 : 0 : unlock_vg(cmd, VG_ORPHANS);
74 : 0 : unlock_vg(cmd, vg_name);
75 : 0 : return ECMD_PROCESSED;
76 : : }
|