1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

o sync tool changes for backup stuff.

This commit is contained in:
Joe Thornber 2002-01-07 11:12:11 +00:00
parent 330c46317c
commit 197c3f2ab4
22 changed files with 156 additions and 184 deletions

View File

@ -21,52 +21,52 @@ static void _not_written(const char *cmd)
log_err("The text format is lacking an implementation for '%s'", cmd);
}
struct list *_get_vgs(struct format_instance *fi)
static struct list *_get_vgs(struct format_instance *fi)
{
_not_written("_get_vgs");
return NULL;
}
struct list *_get_pvs(struct format_instance *fi)
static struct list *_get_pvs(struct format_instance *fi)
{
_not_written("_get_vgs");
return NULL;
}
struct physical_volume *_pv_read(struct format_instance *fi,
const char *pv_name)
static struct physical_volume *_pv_read(struct format_instance *fi,
const char *pv_name)
{
_not_written("_get_vgs");
return NULL;
}
int _pv_setup(struct format_instance *fi, struct physical_volume *pv,
struct volume_group *vg)
static int _pv_setup(struct format_instance *fi, struct physical_volume *pv,
struct volume_group *vg)
{
_not_written("_get_vgs");
return 0;
}
int _pv_write(struct format_instance *fi, struct physical_volume *pv)
static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
{
_not_written("_get_vgs");
return 0;
}
int _vg_setup(struct format_instance *fi, struct volume_group *vg)
static int _vg_setup(struct format_instance *fi, struct volume_group *vg)
{
_not_written("_get_vgs");
return 0;
}
struct volume_group *_vg_read(struct format_instance *fi,
const char *vg_name)
static struct volume_group *_vg_read(struct format_instance *fi,
const char *vg_name)
{
_not_written("_get_vgs");
return NULL;
}
int _vg_write(struct format_instance *fi, struct volume_group *vg)
static int _vg_write(struct format_instance *fi, struct volume_group *vg)
{
FILE *fp;
char *file = (char *) fi->private;
@ -85,7 +85,7 @@ int _vg_write(struct format_instance *fi, struct volume_group *vg)
return 1;
}
void _destroy(struct format_instance *fi)
static void _destroy(struct format_instance *fi)
{
pool_free(fi->cmd->mem, fi);
}

View File

@ -21,6 +21,7 @@ top_srcdir = @top_srcdir@
VPATH = @srcdir@
SOURCES=\
archive.c \
lvchange.c \
lvcreate.c \
lvdisplay.c \

View File

@ -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)

View File

@ -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

29
tools/defaults.h Normal file
View File

@ -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 */

View File

@ -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;
}

View File

@ -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);

View File

@ -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,27 +912,8 @@ 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");
if (!_init_backup(cmd->cf))
return 0;
}
if (!create_dir(_backup_dir))
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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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))

View File

@ -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",

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);