diff options
author | Joe Thornber <thornber@redhat.com> | 2002-01-07 11:12:11 +0000 |
---|---|---|
committer | Joe Thornber <thornber@redhat.com> | 2002-01-07 11:12:11 +0000 |
commit | 197c3f2ab43358dc9914698ba1f0c9c9f5f6a393 (patch) | |
tree | b0b4f97222e17634e31098245ea2005526a2bea7 /tools | |
parent | 330c46317cb701b49c3cadab8ca63dff3c6005e0 (diff) | |
download | lvm2-197c3f2ab43358dc9914698ba1f0c9c9f5f6a393.tar.gz lvm2-197c3f2ab43358dc9914698ba1f0c9c9f5f6a393.tar.xz lvm2-197c3f2ab43358dc9914698ba1f0c9c9f5f6a393.zip |
o sync tool changes for backup stuff.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.in | 1 | ||||
-rw-r--r-- | tools/archive.c | 9 | ||||
-rw-r--r-- | tools/archive.h | 17 | ||||
-rw-r--r-- | tools/defaults.h | 29 | ||||
-rw-r--r-- | tools/lvchange.c | 8 | ||||
-rw-r--r-- | tools/lvcreate.c | 2 | ||||
-rw-r--r-- | tools/lvm.c | 94 | ||||
-rw-r--r-- | tools/lvremove.c | 2 | ||||
-rw-r--r-- | tools/lvrename.c | 2 | ||||
-rw-r--r-- | tools/lvresize.c | 2 | ||||
-rw-r--r-- | tools/pvchange.c | 2 | ||||
-rw-r--r-- | tools/toollib.c | 109 | ||||
-rw-r--r-- | tools/tools.h | 19 | ||||
-rw-r--r-- | tools/vgcfgbackup.c | 2 | ||||
-rw-r--r-- | tools/vgchange.c | 6 | ||||
-rw-r--r-- | tools/vgcreate.c | 2 | ||||
-rw-r--r-- | tools/vgextend.c | 2 | ||||
-rw-r--r-- | tools/vgmerge.c | 2 | ||||
-rw-r--r-- | tools/vgreduce.c | 2 | ||||
-rw-r--r-- | tools/vgremove.c | 2 | ||||
-rw-r--r-- | tools/vgrename.c | 2 |
21 files changed, 144 insertions, 172 deletions
diff --git a/tools/Makefile.in b/tools/Makefile.in index 6f5a39b0..9da2f41e 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -21,6 +21,7 @@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ SOURCES=\ + archive.c \ lvchange.c \ lvcreate.c \ lvdisplay.c \ diff --git a/tools/archive.c b/tools/archive.c index 62f394c8..d7ff0c4b 100644 --- a/tools/archive.c +++ b/tools/archive.c @@ -4,8 +4,13 @@ * This file is released under the GPL. */ +#include "log.h" #include "archive.h" #include "dbg_malloc.h" +#include "format-text.h" +#include "lvm-string.h" + +#include <limits.h> static struct { int enabled; @@ -24,7 +29,7 @@ int archive_init(const char *dir, } _archive_params.keep_days = keep_days; - _archive_params.keep_number = keep_number; + _archive_params.keep_number = keep_min; _archive_params.enabled = 1; return 1; } @@ -100,7 +105,7 @@ int backup_init(const char *dir) void backup_exit(void) { dbg_free(_backup_params.dir); - memset(&backup_params, 0, sizeof(_backup_params)); + memset(&_backup_params, 0, sizeof(_backup_params)); } void backup_enable(int flag) diff --git a/tools/archive.h b/tools/archive.h index 1b6d539b..78cad1d2 100644 --- a/tools/archive.h +++ b/tools/archive.h @@ -7,18 +7,22 @@ #ifndef _LVM_TOOL_ARCHIVE_H #define _LVM_TOOL_ARCHIVE_H +#include "metadata.h" + /* * There are two operations that come under the - * general area of backups. 'Archiving' occurs just - * before a volume group configuration is changed. - * The user may configure when archived files are expired. - * Typically archives will be stored in /etc/lvm/archive. + * general area of backups. 'Archiving' occurs + * just before a volume group configuration is + * changed. The user may configure when archived + * files are expired. Typically archives will be + * stored in /etc/lvm/archive. * * A 'backup' is a redundant copy of the *current* * volume group configuration. As such it should * be taken just after the volume group is * changed. Only 1 backup file will exist. - * Typically backups will be stored in /etc/lvm/backups. + * Typically backups will be stored in + * /etc/lvm/backups. */ int archive_init(const char *dir, @@ -31,8 +35,7 @@ int archive(struct volume_group *vg); int backup_init(const char *dir); void backup_exit(void); -void backup_enable(void); -void backup_disable(void); +void backup_enable(int flag); int backup(struct volume_group *vg); #endif diff --git a/tools/defaults.h b/tools/defaults.h new file mode 100644 index 00000000..b5354aae --- /dev/null +++ b/tools/defaults.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the GPL. + */ + +#ifndef _LVM_DEFAULTS_H +#define _LVM_DEFAULTS_H + + +#define DEFAULT_SYS_DIR "/etc/lvm" + +#define DEFAULT_ARCHIVE_FLAG 1 +#define DEFAULT_BACKUP_FLAG 1 + +#define DEFAULT_ARCHIVE_SUBDIR "archive" +#define DEFAULT_BACKUP_SUBDIR "backup" + +/* + * FIXME: these are deliberately low for the beta + * series to encourage testing. + */ +#define DEFAULT_ARCHIVE_DAYS 7 +#define DEFAULT_ARCHIVE_NUMBER 5 + +#define DEFAULT_DEV_DIR "/dev" + + +#endif /* _LVM_DEFAULTS_H */ diff --git a/tools/lvchange.c b/tools/lvchange.c index 69c6a2e4..6224b27c 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -120,7 +120,7 @@ static int lvchange_permission(struct logical_volume *lv) if (!fid->ops->vg_write(fid, lv->vg)) return 0; - autobackup(lv->vg); + backup(lv->vg); log_very_verbose("Updating permissions for %s in kernel", lv->name); if (!lv_update_write_access(lv)) @@ -158,7 +158,7 @@ static int lvchange_availability(struct logical_volume *lv) lv->name); if (!fid->ops->vg_write(fid, lv->vg)) return 0; - autobackup(lv->vg); + backup(lv->vg); } if ((lv_stat & ACTIVE) && (active & ACTIVE)) @@ -222,7 +222,7 @@ static int lvchange_contiguous(struct logical_volume *lv) if (!fid->ops->vg_write(fid, lv->vg)) return 0; - autobackup(lv->vg); + backup(lv->vg); return 1; } @@ -254,7 +254,7 @@ static int lvchange_readahead(struct logical_volume *lv) if (!fid->ops->vg_write(fid, lv->vg)) return 0; - autobackup(lv->vg); + backup(lv->vg); return 1; } diff --git a/tools/lvcreate.c b/tools/lvcreate.c index a941d337..5b68c50a 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -225,7 +225,7 @@ int lvcreate(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; - autobackup(vg); + backup(vg); log_print("Logical volume %s created", lv->name); diff --git a/tools/lvm.c b/tools/lvm.c index 8606762a..05b06ebd 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -5,6 +5,8 @@ */ #include "tools.h" +#include "archive.h" +#include "defaults.h" #include <assert.h> #include <getopt.h> @@ -52,6 +54,10 @@ static int _dump_filter; static int _interactive; static FILE *_log; +/* + * This structure only contains those options that + * can have a default and per command setting. + */ struct config_info { int debug; int verbose; @@ -70,15 +76,12 @@ static struct config_info _current_settings; * * o The lvm configuration (lvm.conf) * o The persistent filter cache (.cache) - * o Volume group backups (backup/) + * o Volume group backups (/backup) + * o Archive of old vg configurations (/archive) */ static char _sys_dir[PATH_MAX] = "/etc/lvm"; -static char _backup_dir[PATH_MAX]; static char _dev_dir[PATH_MAX]; -#define DEFAULT_DEV_DIR "/dev" - - /* static functions */ static void register_commands(void); static struct command *find_command(const char *name); @@ -672,6 +675,64 @@ static void __init_log(struct config_file *cf) _default_settings.test = find_config_int(cf->root, "log/test", '/', 0); } +/* + * '_sys_dir' must have been set before calling this. + */ +static int _init_backup(struct config_file *cf) +{ + int days, min; + char default_dir[PATH_MAX]; + const char *dir; + + /* set up archiving */ + _default_settings.archive = + find_config_bool(cmd->cf->root, "backup/archive", '/', + DEFAULT_ARCHIVE_FLAG); + + days = find_config_int(cmd->cf->root, "backup/retain_days", '/', + DEFAULT_ARCHIVE_DAYS); + + min = find_config_int(cmd->cf->root, "backup/retain_min", '/', + DEFAULT_ARCHIVE_NUMBER); + + if (lvm_snprintf(default_dir, sizeof(default_dir), "%s/%s", _sys_dir, + DEFAULT_ARCHIVE_SUBDIR) == -1) { + log_err("Couldn't create default archive path '%s/%s'.", + _sys_dir, DEFAULT_ARCHIVE_SUBDIR); + return 0; + } + + dir = find_config_str(cmd->cf->root, "backup/archive_dir", '/', + default_dir); + + if (!archive_init(dir, days, min)) { + log_debug("backup_init failed."); + return 0; + } + + /* set up the backup */ + _default_settings.backup = + find_config_bool(cmd->cf->root, "backup/backup", '/', + DEFAULT_BACKUP_FLAG); + + if (lvm_snprintf(default_dir, sizeof(default_dir), "%s/%s", _sys_dir, + DEFAULT_BACKUP_SUBDIR) == -1) { + log_err("Couldn't create default backup path '%s/%s'.", + _sys_dir, DEFAULT_BACKUP_SUBDIR); + return 0; + } + + dir = find_config_str(cmd->cf->root, "backup/backup_dir", '/', + default_dir); + + if (!backup_init(dir)) { + log_debug("backup_init failed."); + return 0; + } + + return 1; +} + static int dev_cache_setup(struct config_file *cf) { struct config_node *cn; @@ -851,28 +912,9 @@ static int init(void) dm_log_init(print_log); - if (!*strncpy(_backup_dir, - find_config_str(cmd->cf->root, "backup/dir", '/', ""), - sizeof(_backup_dir)) && - *_sys_dir && - lvm_snprintf(_backup_dir, sizeof(_backup_dir), "%s/backup", - _sys_dir) < 0) { - log_error("Backup directory given in config file too long"); - return 0; - } - - if (!create_dir(_backup_dir)) + if (!_init_backup(cmd->cf)) return 0; - _backup_days = find_config_int(cmd->cf->root, "backup/days", '/', - _backup_days); - - _backup_number = find_config_int(cmd->cf->root, "backup/keep", '/', - _backup_number); - - _backup_auto = find_config_int(cmd->cf->root, "backup/auto", '/', - _backup_auto); - if (!dev_cache_setup(cmd->cf)) return 0; @@ -889,7 +931,7 @@ static int init(void) if (!(fid = create_lvm1_format(cmd))) return 0; - use_settings(_default_settings); + _use_settings(&_default_settings); return 1; } diff --git a/tools/lvremove.c b/tools/lvremove.c index 6b9cf7d4..0094aab8 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -87,7 +87,7 @@ static int lvremove_single(struct logical_volume *lv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; - autobackup(vg); + backup(vg); log_print("logical volume %s successfully removed", lv->name); return 0; diff --git a/tools/lvrename.c b/tools/lvrename.c index 6fb6bbb5..964345e5 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -122,7 +122,7 @@ int lvrename(int argc, char **argv) return ECMD_FAILED; } - autobackup(lv->vg); + backup(lv->vg); /* FIXME Update symlink. */ lv_reactivate(lv); diff --git a/tools/lvresize.c b/tools/lvresize.c index c05cc0dc..991cb073 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -345,7 +345,7 @@ int lvresize(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; - autobackup(vg); + backup(vg); /* FIXME Ensure it always displays errors? */ if (!lv_reactivate(lv)) diff --git a/tools/pvchange.c b/tools/pvchange.c index 2e403914..32a44aec 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -139,7 +139,7 @@ int pvchange_single(struct physical_volume *pv) "volume group %s", pv_name, vg->name); return 0; } - autobackup(vg); + backup(vg); } else { if (!(fid->ops->pv_write(fid, pv))) { log_error("Failed to store physical volume %s", diff --git a/tools/toollib.c b/tools/toollib.c index 75524086..4b2345d9 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -8,115 +8,6 @@ #include <sys/stat.h> -static int _autobackup; -static char _backup_dir[PATH_MAX]; -static int _keep_days; /* keep for at least this number of days */ -static int _keep_number; /* keep at least this number of backups */ - -/* - * Determine whether or not to do autobackup. - * Cmd line overrides environment variable which in turn overrides config file - */ -int archive_init(const char *backup_dir, int keep_days, int keep_number, - int autobackup) -{ - char *lvm_autobackup; - - if (lvm_snprintf(_backup_dir, sizeof(_backup_dir), - "%s", backup_dir) < 0) { - log_error("Backup directory name too long."); - return 0; - } - - _keep_days = keep_days; - _keep_number = keep_number; - _autobackup = autobackup; /* Config file setting */ - - if (arg_count(autobackup_ARG)) { - _autobackup = arg_int_value(autobackup_ARG, 0); - return 1; - } - - lvm_autobackup = getenv("LVM_AUTOBACKUP"); - if (!lvm_autobackup) - return 1; - - log_verbose("Setting autobackup from environment (LVM_AUTOBACKUP)"); - if (!strcasecmp(lvm_autobackup, "no")) - _autobackup = 0; - else if (strcasecmp(lvm_autobackup, "yes")) { - log_error("Environment variable LVM_AUTOBACKUP has " - "invalid value \"%s\"!", lvm_autobackup); - return 0; - } - - return 1; -} - -static int __backup_old(struct volume_group *vg) -{ - int r; - struct pool *old; - struct format_instance *backer; - - old = vg->cmd->mem; - - /* - * Create a temporary pool for this, I - * doubt it's used but the backup code has - * the right to expect it. - */ - if (!(vg->cmd->mem = pool_create(1024))) { - stack; - vg->cmd->mem = old; - return 0; - } - - if (!(backer = backup_format_create(vg->cmd, _backup_dir, - _keep_days, _keep_number))) { - log_error("Couldn't create backup object."); - return 0; - } - - if (!(r = backer->ops->vg_write(backer, vg))) - stack; - - pool_destroy(vg->cmd->mem); - vg->cmd->mem = old; - - return r; -} - -/* - * This backs up a volume group that is about to have it's . - */ -int auto_backup(struct volume_group *vg) -{ - if (!_autobackup || !*_backup_dir) { - log_print("WARNING: You don't have an automatic backup of %s", - vg->name); - return 1; - } - - if (test_mode()) { - log_print("Test mode: Skipping automatic backup"); - return 1; - } - - log_print("Creating automatic backup of volume group \"%s\" ...", - vg->name); - - if (!__autobackup(vg)) { - log_error("Autobackup failed."); - return 0; - } - - return 1; -} - -int backup_new - - int create_dir(const char *dir) { struct stat info; diff --git a/tools/tools.h b/tools/tools.h index fcda5d08..bb1e5f83 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -20,15 +20,6 @@ #ifndef _LVM_LVM_H #define _LVM_LVM_H -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <ctype.h> -#include <string.h> -#include <limits.h> - #include "pool.h" #include "dbg_malloc.h" #include "list.h" @@ -49,6 +40,16 @@ #include "format-text.h" #include "toollib.h" #include "activate.h" +#include "archive.h" + +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <ctype.h> +#include <string.h> +#include <limits.h> #define CMD_LEN 256 #define MAX_ARGS 64 diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c index df1b7c39..c6997404 100644 --- a/tools/vgcfgbackup.c +++ b/tools/vgcfgbackup.c @@ -43,7 +43,7 @@ static int vg_backup_single(const char *vg_name) } else { /* just use the normal backup code */ - backup_enable(); /* force a backup */ + backup_enable(1); /* force a backup */ if (!backup(vg)) { stack; return ECMD_FAILED; diff --git a/tools/vgchange.c b/tools/vgchange.c index 7003fa01..d7abeca8 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -117,7 +117,7 @@ void vgchange_available(struct volume_group *vg) if (!fid->ops->vg_write(fid, vg)) return; - autobackup(vg); + backup(vg); if (available && (lv_open = activate_lvs_in_vg(vg))) log_verbose("Activated %d logical volumes in " @@ -155,7 +155,7 @@ void vgchange_allocation(struct volume_group *vg) if (!fid->ops->vg_write(fid, vg)) return; - autobackup(vg); + backup(vg); log_print("Volume group %s successfully changed", vg->name); @@ -207,7 +207,7 @@ void vgchange_logicalvolume(struct volume_group *vg) if (!fid->ops->vg_write(fid, vg)) return; - autobackup(vg); + backup(vg); log_print("Volume group %s successfully changed", vg->name); diff --git a/tools/vgcreate.c b/tools/vgcreate.c index 84a333df..de4f27be 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -88,7 +88,7 @@ int vgcreate(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; - autobackup(vg); + backup(vg); log_print("Volume group %s successfully created", vg->name); diff --git a/tools/vgextend.c b/tools/vgextend.c index 57fed525..e172ab3d 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -75,7 +75,7 @@ int vgextend(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; - autobackup(vg); + backup(vg); log_print("Volume group '%s' successfully extended", vg_name); diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 604989ba..143f801b 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -146,7 +146,7 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from) /* FIXME Remove /dev/vgfrom */ - autobackup(vg_to); + backup(vg_to); log_print("Volume group %s successfully merged into %s", vg_from->name, vg_to->name); diff --git a/tools/vgreduce.c b/tools/vgreduce.c index f620e0b2..65cb05e5 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -130,7 +130,7 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv) return ECMD_FAILED; } - autobackup(vg); + backup(vg); log_print("Removed %s from volume group %s", name, vg->name); diff --git a/tools/vgremove.c b/tools/vgremove.c index a1c0d600..c1213b5a 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -74,7 +74,7 @@ static int vgremove_single(const char *vg_name) } } - autobackup(vg); + backup(vg); if (!ret) log_print("Volume group %s successfully removed", vg_name); diff --git a/tools/vgrename.c b/tools/vgrename.c index b4dc723e..f31ee3d3 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -120,7 +120,7 @@ int vgrename(int argc, char **argv) /******* FIXME Any LV things to update? */ - autobackup(vg_old); + backup(vg_old); log_print("Volume group %s successfully renamed to %s", vg_name_old, vg_name_new); |