mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
o High level archiving and backup functions.
I've split the old autobackup function into two seperate areas: 'archiving' is performed *before* a vg configuration is changed. This produces a numbered backup in /etc/lvm/archive. A 'backup' is performed *after* a vg change. So the directory /etc/lvm/backup will hold the a copy of the current configuration.
This commit is contained in:
parent
eefe4b2097
commit
6e16088e24
153
tools/archive.c
Normal file
153
tools/archive.c
Normal file
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#include "archive.h"
|
||||
#include "dbg_malloc.h"
|
||||
|
||||
static struct {
|
||||
int enabled;
|
||||
char *dir;
|
||||
unsigned int keep_days;
|
||||
unsigned int keep_number;
|
||||
|
||||
} _archive_params;
|
||||
|
||||
int archive_init(const char *dir,
|
||||
unsigned int keep_days, unsigned int keep_min)
|
||||
{
|
||||
if (!(_archive_params.dir = dbg_strdup(dir))) {
|
||||
log_err("Couldn't create copy of archive dir.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
_archive_params.keep_days = keep_days;
|
||||
_archive_params.keep_number = keep_number;
|
||||
_archive_params.enabled = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void archive_exit(void)
|
||||
{
|
||||
dbg_free(_archive_params.dir);
|
||||
memset(&_archive_params, 0, sizeof(_archive_params));
|
||||
}
|
||||
|
||||
void archive_disable(void)
|
||||
{
|
||||
_archive_params.enabled = 0;
|
||||
}
|
||||
|
||||
void archive_enable(void)
|
||||
{
|
||||
_archive_params.enabled = 1;
|
||||
}
|
||||
|
||||
static int __archive(struct volume_group *vg)
|
||||
{
|
||||
int r;
|
||||
struct format_instance *archiver;
|
||||
|
||||
if (!(archiver = backup_format_create(vg->cmd,
|
||||
_archive_params.dir,
|
||||
_archive_params.keep_days,
|
||||
_archive_params.keep_number))) {
|
||||
log_error("Couldn't create archiver object.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(r = archiver->ops->vg_write(archiver, vg)))
|
||||
stack;
|
||||
|
||||
archiver->ops->destroy(archiver);
|
||||
return r;
|
||||
}
|
||||
|
||||
int archive(struct volume_group *vg)
|
||||
{
|
||||
if (!_archive_params.enabled)
|
||||
return 1;
|
||||
|
||||
if (test_mode()) {
|
||||
log_print("Test mode: Skipping archiving of volume group.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
log_print("Creating archive of volume group '%s' ...", vg->name);
|
||||
if (!__archive(vg)) {
|
||||
log_error("Archiving failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static struct {
|
||||
int enabled;
|
||||
char *dir;
|
||||
|
||||
} _backup_params;
|
||||
|
||||
int backup_init(const char *dir)
|
||||
{
|
||||
if (!(_backup_params.dir = dbg_strdup(dir))) {
|
||||
log_err("Couldn't create copy of backup dir.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void backup_exit(void)
|
||||
{
|
||||
dbg_free(_backup_params.dir);
|
||||
memset(&backup_params, 0, sizeof(_backup_params));
|
||||
}
|
||||
|
||||
static int __backup(struct volume_group *vg)
|
||||
{
|
||||
int r;
|
||||
struct format_instance *tf;
|
||||
char name[PATH_MAX];
|
||||
|
||||
if (lvm_snprintf(name, sizeof(name), "%s/%s",
|
||||
_backup_params.dir, vg->name) < 0) {
|
||||
log_err("Couldn't generate backup filename for volume group.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(tf = text_format_create(vg->cmd, name))) {
|
||||
log_error("Couldn't create backup object.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(r = tf->ops->vg_write(tf, vg)))
|
||||
stack;
|
||||
|
||||
tf->ops->destroy(tf);
|
||||
return r;
|
||||
}
|
||||
|
||||
int backup(struct volume_group *vg)
|
||||
{
|
||||
if (!_backup_params.enabled)
|
||||
return 1;
|
||||
|
||||
if (test_mode()) {
|
||||
log_print("Test mode: Skipping volume group backup.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
log_print("Creating backup of volume group '%s' ...", vg->name);
|
||||
|
||||
if (!__backup(vg)) {
|
||||
log_error("Backup failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
39
tools/archive.h
Normal file
39
tools/archive.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_TOOL_ARCHIVE_H
|
||||
#define _LVM_TOOL_ARCHIVE_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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
int archive_init(const char *dir,
|
||||
unsigned int keep_days, unsigned int keep_min);
|
||||
void archive_exit(void);
|
||||
|
||||
void archive_disable(void);
|
||||
void archive_enable(void);
|
||||
int archive(struct volume_group *vg);
|
||||
|
||||
int backup_init(const char *dir);
|
||||
void backup_exit(void);
|
||||
|
||||
void backup_enable(void);
|
||||
void backup_disable(void);
|
||||
int backup(struct volume_group *vg);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user