If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

How to Migrate a Single Database After a Server Disk Crash?

Started by searchcandy, Yesterday at 12:01 AM

Previous topic - Next topic

searchcandyTopic starter

Experiencing a catastrophic failure on one of our servers, I opted to migrate our web applications to a redundant server. To facilitate this process, I booted the affected server in rescue mode, successfully mounted the disk, and initiated a file transfer to the secondary server via rsync.

However, I'm encountering a roadblock with regards to replicating a singular database instance. To address this, I created a compressed archive of the database files using tar, specifically the 'admin_gibonline' database, yielding a file named 'admin_gibonline.tgz'.

My question is, will simply creating a new 'admin_gibonline' database on the target server and transferring the archived files from the original database be sufficient? Or are there additional steps I need to take to ensure a seamless database migration? I'd appreciate guidance on the optimal approach, as I only need to replicate a single database, not the entire database cluster.
  •  

aamiour

I'd advise against simply transferring the archived files and creating a new database on the target server. This approach may lead to inconsistencies and potential data corruption. Instead, I recommend using a database-specific migration tool, such as mysqldump or pg_dump, to export the database schema and data from the original server. Then, import the dump file into the new database on the target server. This ensures a seamless migration, preserving database integrity and relationships.
  •  

TizeTrinnigmA

I often encounter scenarios where I need to handle MyISAM and InnoDB storage engines. When working with MyISAM, the process is typically straightforward. However, with InnoDB, it can be a bit more complex, depending on the situation.

Here's a rundown of my approach, which I've documented for future reference. If you find yourself with leftover .ibd and .frm files, the first step is to reconstruct the table schema if possible. If you only have the .frm file, you might need to get creative.

Next, run the command:

ALTER TABLE news DISCARD TABLESPACE;

This command will effectively wipe out all associated files for the "news" table located in the /var/lib/mysql/news/ directory.

After that, navigate to the directory:

cd /var/lib/mysql/news/

Then, you'll want to import your .ibd files and ensure that the ownership and group settings are correct. Use:

chown -R mysql:mysql *

Finally, to bring the table back into the fold, execute:

ALTER TABLE news IMPORT TABLESPACE;
Keep in mind that the path /var/lib/mysql/news/ is specific to my setup; yours could differ.
  •  

ryan reynold

When I encounter situations like this, my go-to approach is to deploy a replica of the MySQL environment on a staging VDS.

First, I halt the MySQL service to ensure no data is being written during the process.

Next, I perform a full copy of the /var/lib/mysql directory, which contains all the critical data files.

Once the copy is complete, I restart the MySQL service to get it running again.

Finally, I execute a database dump for the specific databases I need to work with. This method ensures that I have a secure and consistent backup to reference or restore from, maintaining data integrity throughout the workflow.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...