FirebirdSQL / NETProvider

Firebird ADO.NET Data Provider
https://www.firebirdsql.org/en/net-provider/
Other
152 stars 63 forks source link

Include isc_spb_res_fix_fss_data and isc_spb_res_fix_fss_metadata FbRestoreFlags #1113

Open cborges82 opened 1 year ago

cborges82 commented 1 year ago

I'm automating a migration from Firebird 2.5 to 3.0 using FbStreamingBackup and FbStreamingRestore and Embeded servers. However the isc_spb_res_fix_fss_data and isc_spb_res_fix_fss_metadata is not on FbRestoreFlags options.

I clone the repository and included:

[Flags]
public enum FbRestoreFlags
{
        **FixFssMetadata = IscCodes.isc_spb_res_fix_fss_metadata,
    FixFssData = IscCodes.isc_spb_res_fix_fss_data,**
    DeactivateIndexes = IscCodes.isc_spb_res_deactivate_idx,
    NoShadow = IscCodes.isc_spb_res_no_shadow,
    NoValidity = IscCodes.isc_spb_res_no_validity,
    IndividualCommit = IscCodes.isc_spb_res_one_at_a_time,
    Replace = IscCodes.isc_spb_res_replace,
    Create = IscCodes.isc_spb_res_create,
    UseAllSpace = IscCodes.isc_spb_res_use_all_space,
    MetaDataOnly = IscCodes.isc_spb_res_metadata_only
}

But, when i run the process he show the follow error:

FirebirdSql.Data.FirebirdClient.FbException: 'option -GARBAGE_COLLECT is allowed only on backup No message for error code 336330835 found.'

I think I need to change something on FbStreamingRestore.Execute() to include this parameters, but I don't know where.

Here the code:

public void Backup()
        {
            var connectionStringV25 = new FbConnectionStringBuilder
            {
                Database = "C:\\TMP\\ORIGEM.FDB",
                DataSource = "127.0.0.1",
                ServerType = FbServerType.Embedded,
                UserID = "sysdba",
                Password = "masterkey",
                ClientLibrary = "C:\\TMP\\25\\fbclient.dll"
            }.ToString();

            var connectionStringV30 = new FbConnectionStringBuilder
            {
                Database = "C:\\TMP\\ORIGEM_30.FDB",
                DataSource = "localhost",
                //Port = 3050,
                ServerType = FbServerType.Default,
                UserID = "sysdba",
                Password = "masterkey",
            }.ToString();

            using (var fbk = File.Create("C:\\TMP\\origem_2.fbk"))
            {
                var backup = new FbStreamingBackup();
                backup.ConnectionString = connectionStringV25;
                backup.OutputStream = fbk;
                backup.Execute();
            }

            using (var fbk = File.OpenRead("C:\\TMP\\origem_2.fbk"))
            {
                var RESTORE = new FbStreamingRestore();
                RESTORE.ConnectionString = connectionStringV30;    
                RESTORE.InputStream = fbk;
                RESTORE.Verbose = false;
                RESTORE.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace | FbRestoreFlags.FixFssData | FbRestoreFlags.FixFssMetadata;
                //RESTORE.ServiceOutput += ServiceOutput;

                RESTORE.Execute();
            }
        }
mrotteveel commented 1 year ago

Just a sanity check: do you really need it? Because those options can potentially corrupt your database if you use them incorrectly. They are only intended for one off use to correct issues with a database, if you're sure the database actually has that problem. If your database doesn't have the problem, or you specify the wrong character set, it will logically corrupt your database (by reinterpreting bytes of strings using the specified character set). Only use it if restoring with gbak returns an error and prompts you to use these options.

Also, isc_spb_res_fix_fss_metadata and isc_spb_res_fix_fss_data aren't bitmaps options, so they shouldn't be added to FbRestoreFlags, they are Server Parameter Buffer options with a string value (the character set to use).

mrotteveel commented 1 year ago

To expand: because isc_spb_res_fix_fss_metadata and isc_spb_res_fix_fss_data aren't bitmap option, you get the error, because they will enable options which are bitmap options:

isc_spb_res_fix_fss_data = 13 (1101) and isc_spb_res_fix_fss_metadata = 14 (1110), so using them as flags will enable other options. isc_spb_res_fix_fss_data will enable options isc_spb_bkp_ignore_checksums, isc_spb_bkp_metadata_only, isc_spb_bkp_no_garbage_collect, and isc_spb_res_fix_fss_metadata enables options isc_spb_bkp_ignore_limbo, isc_spb_bkp_metadata_only, isc_spb_bkp_no_garbage_collect.

cborges82 commented 1 year ago

Just a sanity check: do you really need it? Because those options can potentially corrupt your database if you use them incorrectly. They are only intended for one off use to correct issues with a database, if you're sure the database actually has that problem. If your database doesn't have the problem, or you specify the wrong character set, it will logically corrupt your database (by reinterpreting bytes of strings using the specified character set). Only use it if restoring with gbak returns an error and prompts you to use these options.

Also, isc_spb_res_fix_fss_metadata and isc_spb_res_fix_fss_data aren't bitmaps options, so they shouldn't be added to FbRestoreFlags, they are Server Parameter Buffer options with a string value (the character set to use).

Yes, I need. The convertion from 1.5 to 3.0 I need to inform that the DB will be on WIN1252.

Where should be included this kind of option?

mrotteveel commented 1 year ago

Yes, I need. The convertion from 1.5 to 3.0 I need to inform that the DB will be on WIN1252.

Where should be included this kind of option?

Taking a quick look at the sources, I think you would need to add them (with Append2) to the startSpb in Execute and ExecuteAsync of FbRestore and FbStreamingRestore, with the appropriate value. .

infoserwis-jarek commented 7 months ago

This option will allow you to migrate your database from version 2.1 or earlier to version 2.5 or later of Firebird without the use of external tools or manual gbak operations.

I can't wait for them to be added.