2001-12-20 19:05:14 +03:00
/*
* Copyright ( C ) 2001 Sistina Software ( UK ) Limited .
*
* This file is released under the GPL .
*/
# include "tools.h"
2002-01-07 12:05:31 +03:00
# include <stdio.h>
static int _backup_to_file ( const char * file , struct volume_group * vg )
{
int r ;
struct format_instance * tf ;
2002-04-24 22:20:51 +04:00
void * context ;
2002-01-07 12:05:31 +03:00
2002-04-24 22:20:51 +04:00
if ( ! ( context = create_text_context ( vg - > cmd - > fmtt , file ,
vg - > cmd - > cmd_line ) ) | |
! ( tf = vg - > cmd - > fmtt - > ops - > create_instance ( vg - > cmd - > fmtt , NULL ,
context ) ) ) {
2002-01-07 12:05:31 +03:00
log_error ( " Couldn't create backup object. " ) ;
return 0 ;
}
2002-04-24 22:20:51 +04:00
if ( ! ( r = tf - > fmt - > ops - > vg_write ( tf , vg , context ) ) | |
! ( r = tf - > fmt - > ops - > vg_commit ( tf , vg , context ) ) )
2002-01-07 12:05:31 +03:00
stack ;
2002-04-24 22:20:51 +04:00
tf - > fmt - > ops - > destroy_instance ( tf ) ;
2002-01-07 12:05:31 +03:00
return r ;
}
2002-02-11 23:50:53 +03:00
static int vg_backup_single ( struct cmd_context * cmd , const char * vg_name )
2001-12-20 19:05:14 +03:00
{
struct volume_group * vg ;
2002-01-30 18:04:48 +03:00
log_verbose ( " Checking for volume group \" %s \" " , vg_name ) ;
2002-04-24 22:20:51 +04:00
if ( ! ( vg = vg_read ( cmd , vg_name ) ) ) {
2002-01-30 18:04:48 +03:00
log_error ( " Volume group \" %s \" not found " , vg_name ) ;
2001-12-20 19:05:14 +03:00
return ECMD_FAILED ;
}
2002-02-12 00:00:35 +03:00
if ( arg_count ( cmd , file_ARG ) ) {
_backup_to_file ( arg_value ( cmd , file_ARG ) , vg ) ;
2002-01-07 12:05:31 +03:00
} else {
/* just use the normal backup code */
2002-01-07 14:12:11 +03:00
backup_enable ( 1 ) ; /* force a backup */
2002-01-07 12:05:31 +03:00
if ( ! backup ( vg ) ) {
stack ;
return ECMD_FAILED ;
}
2001-12-20 19:05:14 +03:00
}
2002-01-30 18:04:48 +03:00
log_print ( " Volume group \" %s \" successfully backed up. " , vg_name ) ;
2001-12-20 19:05:14 +03:00
return 0 ;
}
2002-02-11 23:50:53 +03:00
int vgcfgbackup ( struct cmd_context * cmd , int argc , char * * argv )
2001-12-20 19:05:14 +03:00
{
2002-03-15 19:07:38 +03:00
return process_each_vg ( cmd , argc , argv , LCK_VG_READ , & vg_backup_single ) ;
2001-12-20 19:05:14 +03:00
}