After having a vps crash, I asked my hosting to give me the dumped file of my drupal database. It is a folder filled with of *.frm *.MYD files of the database tables. I used to restore mydb.sql files thru command line (mysqldupm …) but I have no idea how I can restore the current folder. Your help is much appreciated.
Mysql – how to restore a thesql dump FOLDER
directoryMySQLrestore
Related Solutions
As mentioned in the comments - you don't backup/restore TEMPDB.
To get the script to continue after the sqlservr -m
command, you need to "background" the command. To do this, use the start
command in front of it. Something like:
start sqlservr -m
should work. After that though, you will need to wait for SQL Server to actually start up before issuing any commands. On Windows 2003 you can get sleep.exe
from the Windows 2003 Resource Kit to do this. On Windows 2008 you can use the timeout.exe
command. You will need to time a few startups to get an idea for exactly how long to wait before attempting the restores (and add a little time to it, just in case...)
As far as restoring msdb and model though, it should be 2 more simple sqlcmd restores just like the one you have for master. You also need to make sure you stop the SQL Server instance before restarting the service.
Final script would look something like:
::set variables
set dbdirectory=C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
title Restoring system databases
net stop mssqlserver
cd C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn
start sqlservr -m
timeout /t 60
sqlcmd -Slocalhost -E -Q "restore database master from disk='c:\master.bak' WITH REPLACE"
sqlcmd -Slocalhost -E -Q "restore database msdb from disk='c:\msdb.bak' WITH REPLACE"
sqlcmd -Slocalhost -E -Q "restore database model from disk='c:\model.bak' WITH REPLACE"
taskkill /im sqlservr.exe
net start mssqlserver
pause
Be sure to check out this technet article as well.
note: I didn't test this, I'm assuming your sqlcmd
statements are correct here...
First, verify that you have the correct datadir
by using:
SHOW VARIABLES LIKE 'datadir';
This should give you a directory that contains more directories based on the database names. Inside each of these, you should see three types of files:
.frm
contains the table definition, but no actual data..myd
contains the raw table data. (MyISAM).myi
contains any table indices that you have defined. (MyISAM).ibd
contains the indices and data in a combined format. (InnoDB)
Here's where it gets tricky. InnoDB (which you mentioned int he comments is what you're using) has the notion of tablespaces, much like Oracle. That is, it separates the files out on the system into different namespaces if you've configured it to do; otherwise, it stores everything in the system tablespace. Its typically in a file called ibdata#
, where number can change. If that's gone, then your data is gone. Its very likely that your reinstall of MySQL backed up the file and put in the standard system file--but you'll need to look and see.
For future reference, you can create these on a per-file basis, which allows you to separate out the tablespaces into different files by using the innodb_file_per_table config option.
Best Answer
The best thing you could do would be to ask them to run mysqldump and give you a proper backup file, as this will be more robust to potential versioning issues in both mysql and the host OS. If they're not willing to do this, you can try copying the files they gave you directly to the data directory (e.g., /var/lib/mysql) with the server stopped, then starting the server and GRANTing privileges to appropriate users.