mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-11 20:58:50 +03:00
vgcfgrestore -l lists backup file too
This commit is contained in:
parent
fe22eb84e6
commit
96bea84664
@ -50,7 +50,7 @@ struct archive_file {
|
|||||||
/*
|
/*
|
||||||
* Extract vg name and version number from a filename.
|
* Extract vg name and version number from a filename.
|
||||||
*/
|
*/
|
||||||
static int _split_vg(const char *filename, char *vg, size_t vg_size,
|
static int _split_vg(const char *filename, char *vgname, size_t vg_size,
|
||||||
uint32_t *ix)
|
uint32_t *ix)
|
||||||
{
|
{
|
||||||
size_t len, vg_len;
|
size_t len, vg_len;
|
||||||
@ -74,8 +74,8 @@ static int _split_vg(const char *filename, char *vg, size_t vg_size,
|
|||||||
if (vg_len + 1 > vg_size)
|
if (vg_len + 1 > vg_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
strncpy(vg, filename, vg_len);
|
strncpy(vgname, filename, vg_len);
|
||||||
vg[vg_len] = '\0';
|
vgname[vg_len] = '\0';
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -121,10 +121,10 @@ static char *_join(struct pool *mem, const char *dir, const char *name)
|
|||||||
* Returns a list of archive_files.
|
* Returns a list of archive_files.
|
||||||
*/
|
*/
|
||||||
static struct list *_scan_archive(struct pool *mem,
|
static struct list *_scan_archive(struct pool *mem,
|
||||||
const char *vg, const char *dir)
|
const char *vgname, const char *dir)
|
||||||
{
|
{
|
||||||
int i, count, ix;
|
int i, count, ix;
|
||||||
char vg_name[64], *path;
|
char vgname_found[64], *path;
|
||||||
struct dirent **dirent;
|
struct dirent **dirent;
|
||||||
struct archive_file *af;
|
struct archive_file *af;
|
||||||
struct list *results;
|
struct list *results;
|
||||||
@ -148,12 +148,12 @@ static struct list *_scan_archive(struct pool *mem,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* check the name is the correct format */
|
/* check the name is the correct format */
|
||||||
if (!_split_vg(dirent[i]->d_name, vg_name, sizeof(vg_name),
|
if (!_split_vg(dirent[i]->d_name, vgname_found,
|
||||||
&ix))
|
sizeof(vgname_found), &ix))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* is it the vg we're interested in ? */
|
/* is it the vg we're interested in ? */
|
||||||
if (strcmp(vg, vg_name))
|
if (strcmp(vgname, vgname_found))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(path = _join(mem, dir, dirent[i]->d_name))) {
|
if (!(path = _join(mem, dir, dirent[i]->d_name))) {
|
||||||
@ -304,7 +304,8 @@ static void _display_archive(struct cmd_context *cmd, struct archive_file *af)
|
|||||||
char *desc;
|
char *desc;
|
||||||
void *context;
|
void *context;
|
||||||
|
|
||||||
log_print("path:\t\t%s", af->path);
|
log_print(" ");
|
||||||
|
log_print("File:\t\t%s", af->path);
|
||||||
|
|
||||||
if (!(context = create_text_context(cmd, af->path, NULL)) ||
|
if (!(context = create_text_context(cmd, af->path, NULL)) ||
|
||||||
!(tf = cmd->fmt_backup->ops->create_instance(cmd->fmt_backup, NULL,
|
!(tf = cmd->fmt_backup->ops->create_instance(cmd->fmt_backup, NULL,
|
||||||
@ -324,34 +325,50 @@ static void _display_archive(struct cmd_context *cmd, struct archive_file *af)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_print("description:\t%s", desc ? desc : "<No description>");
|
log_print("VG name: \t%s", vg->name);
|
||||||
log_print("time:\t\t%s", ctime(&when));
|
log_print("Description:\t%s", desc ? desc : "<No description>");
|
||||||
|
log_print("Backup Time:\t%s", ctime(&when));
|
||||||
|
|
||||||
pool_free(cmd->mem, vg);
|
pool_free(cmd->mem, vg);
|
||||||
tf->fmt->ops->destroy_instance(tf);
|
tf->fmt->ops->destroy_instance(tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int archive_list(struct cmd_context *cmd, const char *dir, const char *vg)
|
int archive_list(struct cmd_context *cmd, const char *dir, const char *vgname)
|
||||||
{
|
{
|
||||||
struct list *archives, *ah;
|
struct list *archives, *ah;
|
||||||
struct archive_file *af;
|
struct archive_file *af;
|
||||||
|
|
||||||
if (!(archives = _scan_archive(cmd->mem, vg, dir))) {
|
if (!(archives = _scan_archive(cmd->mem, vgname, dir))) {
|
||||||
log_err("Couldn't scan the archive directory (%s).", dir);
|
log_err("Couldn't scan the archive directory (%s).", dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list_empty(archives))
|
if (list_empty(archives))
|
||||||
log_print("No archives found.");
|
log_print("No archives found in %s.", dir);
|
||||||
|
|
||||||
list_iterate(ah, archives) {
|
list_iterate(ah, archives) {
|
||||||
af = list_item(ah, struct archive_file);
|
af = list_item(ah, struct archive_file);
|
||||||
|
|
||||||
_display_archive(cmd, af);
|
_display_archive(cmd, af);
|
||||||
log_print(" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pool_free(cmd->mem, archives);
|
pool_free(cmd->mem, archives);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int backup_list(struct cmd_context *cmd, const char *dir, const char *vgname)
|
||||||
|
{
|
||||||
|
struct archive_file af;
|
||||||
|
|
||||||
|
if (!(af.path = _join(cmd->mem, dir, vgname))) {
|
||||||
|
stack;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path_exists(af.path))
|
||||||
|
_display_archive(cmd, &af);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@ int archive_vg(struct volume_group *vg,
|
|||||||
/*
|
/*
|
||||||
* Displays a list of vg backups in a particular archive directory.
|
* Displays a list of vg backups in a particular archive directory.
|
||||||
*/
|
*/
|
||||||
int archive_list(struct cmd_context *cmd, const char *dir, const char *vg);
|
int archive_list(struct cmd_context *cmd, const char *dir, const char *vgname);
|
||||||
|
int backup_list(struct cmd_context *cmd, const char *dir, const char *vgname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The text format can read and write a volume_group to a file.
|
* The text format can read and write a volume_group to a file.
|
||||||
|
@ -14,6 +14,12 @@ static struct {
|
|||||||
|
|
||||||
} _archive_params;
|
} _archive_params;
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
int enabled;
|
||||||
|
char *dir;
|
||||||
|
|
||||||
|
} _backup_params;
|
||||||
|
|
||||||
int archive_init(const char *dir, unsigned int keep_days, unsigned int keep_min)
|
int archive_init(const char *dir, unsigned int keep_days, unsigned int keep_min)
|
||||||
{
|
{
|
||||||
_archive_params.dir = NULL;
|
_archive_params.dir = NULL;
|
||||||
@ -103,15 +109,16 @@ int archive(struct volume_group *vg)
|
|||||||
|
|
||||||
int archive_display(struct cmd_context *cmd, const char *vg_name)
|
int archive_display(struct cmd_context *cmd, const char *vg_name)
|
||||||
{
|
{
|
||||||
return archive_list(cmd, _archive_params.dir, vg_name);
|
int r1, r2;
|
||||||
|
|
||||||
|
init_partial(1);
|
||||||
|
r1 = archive_list(cmd, _archive_params.dir, vg_name);
|
||||||
|
r2 = backup_list(cmd, _backup_params.dir, vg_name);
|
||||||
|
init_partial(0);
|
||||||
|
|
||||||
|
return r1 && r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
|
||||||
int enabled;
|
|
||||||
char *dir;
|
|
||||||
|
|
||||||
} _backup_params;
|
|
||||||
|
|
||||||
int backup_init(const char *dir)
|
int backup_init(const char *dir)
|
||||||
{
|
{
|
||||||
_backup_params.dir = NULL;
|
_backup_params.dir = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user