@@ -787,3 +787,66 @@ gchar* bd_lvm_config_get (const gchar *section, const gchar *setting, const gcha
787787 return NULL ;
788788 return g_strchomp (output );
789789}
790+
791+ gboolean _vgcfgbackup_restore (const gchar * command , const gchar * vg_name , const gchar * file , const BDExtraArg * * extra , GError * * error ) {
792+ const gchar * args [6 ] = {"lvm" , NULL , NULL , NULL , NULL , NULL };
793+ guint next_arg = 1 ;
794+ gchar * output = NULL ;
795+ g_autofree gchar * config_arg = NULL ;
796+
797+ args [next_arg ++ ] = command ;
798+ if (file ) {
799+ args [next_arg ++ ] = "-f" ;
800+ args [next_arg ++ ] = file ;
801+ }
802+ args [next_arg ++ ] = vg_name ;
803+
804+ g_mutex_lock (& global_config_lock );
805+ if (global_config_str ) {
806+ config_arg = g_strdup_printf ("--config=%s" , global_config_str );
807+ args [next_arg ++ ] = config_arg ;
808+ }
809+ g_mutex_unlock (& global_config_lock );
810+
811+ return bd_utils_exec_and_capture_output (args , extra , & output , error );
812+ }
813+
814+ /**
815+ * bd_lvm_vgcfgbackup:
816+ * @vg_name: name of the VG to backup configuration
817+ * @backup_file: (nullable): file to save the backup to or %NULL for using the default backup file
818+ * in /etc/lvm/backup
819+ * @extra: (nullable) (array zero-terminated=1): extra options for the vgcfgbackup command
820+ * (just passed to LVM as is)
821+ * @error: (out) (optional): place to store error (if any)
822+ *
823+ * Note: This function does not back up the data content of LVs. See `vgcfbackup(8)` man page
824+ * for more information.
825+ *
826+ * Returns: Whether the backup was successfully created or not.
827+ *
828+ * Tech category: %BD_LVM_TECH_VG_CFG_BACKUP_RESTORE no mode (it is ignored)
829+ */
830+ gboolean bd_lvm_vgcfgbackup (const gchar * vg_name , const gchar * backup_file , const BDExtraArg * * extra , GError * * error ) {
831+ return _vgcfgbackup_restore ("vgcfgbackup" , vg_name , backup_file , extra , error );
832+ }
833+
834+ /**
835+ * bd_lvm_vgcfgrestore:
836+ * @vg_name: name of the VG to restore configuration
837+ * @backup_file: (nullable): file to restore VG configuration from to or %NULL for using the
838+ * latest backup in /etc/lvm/backup
839+ * @extra: (nullable) (array zero-terminated=1): extra options for the vgcfgrestore command
840+ * (just passed to LVM as is)
841+ * @error: (out) (optional): place to store error (if any)
842+ *
843+ * Note: This function restores VG configuration created by %bd_lvm_vgcfgbackup from given
844+ * @backup_file or from the latest backup in /etc/lvm/backup.
845+ *
846+ * Returns: Whether the configuration was successfully restored or not.
847+ *
848+ * Tech category: %BD_LVM_TECH_VG_CFG_BACKUP_RESTORE no mode (it is ignored)
849+ */
850+ gboolean bd_lvm_vgcfgrestore (const gchar * vg_name , const gchar * backup_file , const BDExtraArg * * extra , GError * * error ) {
851+ return _vgcfgbackup_restore ("vgcfgrestore" , vg_name , backup_file , extra , error );
852+ }
0 commit comments