Monday, September 20, 2021

Migrate MariaDB data files

 Self explanatory :-) 


https://www.digitalocean.com/community/tutorials/how-to-change-a-mariadb-data-directory-to-a-new-location-on-centos-7

How to install mariadb client (ODBC drivers)

 See this: https://downloads.mariadb.org/mariadb/repositories/#distro=RedHat&distro_release=rhel8-amd64--rhel8&mirror=uab&version=10.4


Add this to /etc/yum.repos.d to MariaDB.repo


# MariaDB 10.4 RedHat repository list - created 2021-09-21 05:57 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/rhel8-amd64 module_hotfixes=1 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1



[root@unicaapdemo-rhel84 yum.repos.d]# yum install MariaDB-client Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Last metadata expiration check: 0:00:20 ago on Tue 21 Sep 2021 02:01:42 PM +08. Dependencies resolved. ====================================================================================================================================================================== Package Architecture Version Repository Size ====================================================================================================================================================================== Installing: MariaDB-client x86_64 10.4.21-1.el8 mariadb 12 M Installing dependencies: MariaDB-common x86_64 10.4.21-1.el8 mariadb 87 k MariaDB-shared x86_64 10.4.21-1.el8 mariadb 115 k replacing mariadb-connector-c.x86_64 3.1.11-2.el8_3 replacing mariadb-connector-c-config.noarch 3.1.11-2.el8_3 Transaction Summary ====================================================================================================================================================================== Install 3 Packages Total download size: 12 M Is this ok [y/N]: y Downloading Packages: (1/3): MariaDB-common-10.4.21-1.el8.x86_64.rpm 64 kB/s | 87 kB 00:01 (2/3): MariaDB-shared-10.4.21-1.el8.x86_64.rpm 70 kB/s | 115 kB 00:01 (3/3): MariaDB-client-10.4.21-1.el8.x86_64.rpm 1.6 MB/s | 12 MB 00:07 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 1.6 MB/s | 12 MB 00:07 warning: /var/cache/dnf/mariadb-0a89ccdc1e8b8fd8/packages/MariaDB-client-10.4.21-1.el8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY MariaDB 7.3 kB/s | 8.2 kB 00:01 Importing GPG key 0x1BB943DB: Userid : "MariaDB Package Signing Key <package-signing-key@mariadb.org>" Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: MariaDB-shared-10.4.21-1.el8.x86_64 1/5 Installing : MariaDB-shared-10.4.21-1.el8.x86_64 1/5 Running scriptlet: MariaDB-shared-10.4.21-1.el8.x86_64 1/5 Running scriptlet: MariaDB-common-10.4.21-1.el8.x86_64 2/5 Installing : MariaDB-common-10.4.21-1.el8.x86_64 2/5 Running scriptlet: MariaDB-common-10.4.21-1.el8.x86_64 2/5 Running scriptlet: MariaDB-client-10.4.21-1.el8.x86_64 3/5 Installing : MariaDB-client-10.4.21-1.el8.x86_64 3/5 Running scriptlet: MariaDB-client-10.4.21-1.el8.x86_64 3/5 Obsoleting : mariadb-connector-c-3.1.11-2.el8_3.x86_64 4/5 Obsoleting : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 5/5 Running scriptlet: mariadb-connector-c-config-3.1.11-2.el8_3.noarch 5/5 Verifying : MariaDB-client-10.4.21-1.el8.x86_64 1/5 Verifying : MariaDB-common-10.4.21-1.el8.x86_64 2/5 Verifying : MariaDB-shared-10.4.21-1.el8.x86_64 3/5 Verifying : mariadb-connector-c-3.1.11-2.el8_3.x86_64 4/5 Verifying : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 5/5 Installed products updated. Installed: MariaDB-client-10.4.21-1.el8.x86_64 MariaDB-common-10.4.21-1.el8.x86_64 MariaDB-shared-10.4.21-1.el8.x86_64 Complete!


Saturday, September 11, 2021

Error "Use RESTORE FILELISTONLY to list the logical file names." when restoring MSSQL DB

 https://stackoverflow.com/questions/22245808/sql-server-error-logical-file-is-not-part-of-database-use-restore-fileliston

I experienced this issue when trying to restore a database on MS SQL Server 2012.

Here's is my script for restoring the database:

USE master;
GO

ALTER DATABASE my_db SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO

    
RESTORE DATABASE my_db
    FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\my_db_backup.bak'
    WITH REPLACE,
    MOVE 'my_db' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\my_db.mdf',
    MOVE 'my_db_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\my_db_log.ldf'
GO
    
ALTER DATABASE my_db SET MULTI_USER;
GO

And I was encountering the error:

Msg 3234, Level 16, State 1, Line 1
Logical file 'my_db' is not part of database 'my_db'. 
Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

Here's how I fixed it:

The issue was that I was not referencing the logical files properly.

I had to run the RESTORE FILELISTONLY command below on the backup file:

RESTORE FILELISTONLY 
    FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\my_db_backup.bak'

This displayed the LogicalName and the corresponding PhysicalName of the Data and Log files for the database respectively:

LogicalName      PhysicalName               
com.my_db        C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\com.my_db.mdf
com.my_db_log    C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\com.m




1> RESTORE FILELISTONLY

2> FROM DISK = '/data/dbbackup/Camp_Macro.bak'

3> go

LogicalName                                                                                                                      PhysicalName                                                                                                                                                                                                                                                                                                       Type FileGroupName                                                                                                                                           Size                 MaxSize              FileId               CreateLSN                   DropLSN                     UniqueId                                                    ReadOnlyLSN                 ReadWriteLSN                BackupSizeInBytes    SourceBlockSize FileGroupId LogGroupGUID                         DifferentialB                       aseLSN         DifferentialBaseGUID                 IsReadOnly IsPresent TDEThumbprint                              SnapshotUrl                                                                                                                                                                                                                                                             

-------------------------------------------------------------------------------------------------------------------------------- --------------------------------------                       -----------------------------------------------------------------------------------------------------------------------------------------------------------------------                       ------------------------------------------------------- ---- ----------------------------------------------------------------------------------------------------------                       ---------------------- -------------------- -------------------- -------------------- --------------------------- --------------------------- -------------------------                       ----------- --------------------------- --------------------------- -------------------- --------------- ----------- ------------------------------------ -------------                       -------------- ------------------------------------ ---------- --------- ------------------------------------------ ---------------------------------------------------                       -----------------------------------------------------------------------------------------------------------------------------------------------------------------------                       ----------------------------------------------------------------------------------------------------------------------

Camp_Macros_Data                                                                                                                 C:\Program Files\Microsoft SQL Server\                       MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Camp_Macro.mdf                                                                                                                                                                                                      D    PRIMARY                                                                                                                                                              3211264       35184372080640                    1                           0                           0 D3EF0F25-0362-4350-8E80-4                       BCB3FAF2A61                           0                           0              3080192             512           1 NULL                                          1270                       00000012200037 41407C89-4889-405C-8B5F-63D427939647          0         1 NULL                                       NULL                                                                                                                                                                                                                                                                    

Camp_Macros_Log                                                                                                                  C:\Program Files\Microsoft SQL Server\                       MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Camp_Macro_1.ldf                                                                                                                                                                                                    L    NULL                                                                                                                                                                 4194304        2199023255552                    2                           0                           0 65DD3631-9172-4C21-9BEB-8                       B0AA88BBD23                           0                           0                    0             512           0 NULL                                                                                  0 00000000-0000-0000-0000-000000000000          0         1 NULL                                       NULL                                                                                                                                                                                                                                                                    


(2 rows affected)


Network packet size (bytes): 4096

1 xact[s]:

Clock Time (ms.): total        38  avg   38.0 (26.3 xacts per sec.)


Installing SQLServer on Linux

 https://phoenixnap.com/kb/sql-server-linux#ftoc-heading-6