Category Archives: backup

Loading mysql database from compressed dump

Today I had to load database on mysql. There`s nothing new or exciting about it, but I encountered few problems. First one is that dump was quite big (few gigabytes) and it was compressed with gzip. (G)Unzipping it simply to a file would take some time, waste space on disk and it wasn`t the right way ;-) So here how I managed to decompress it and load it at the same time:

gunzip -c mydbdump.sql.gz|mysql -umyuser -pmypass mydb

But then I found another problem – in my dump there was hardcoded database name. I wasn`t recovering that database, but just wanted to load it to a diffrent one. Names weren`t the same so it failed to load. I looked at the begining of that file using head command, as opening so huge file in vi(m) would probably kill the server. I found that there was two sql commands that creates database itself and use it (sql use command). So with a little help of sed I managed to modify my command so it looked like this:

gunzip -c mydbdump.sql.gz| sed -e '1,30s/old_dbname/mydb/'| mysql -umyuser -pmypass mydb

I limited sed`s search&replace to first 30 lines, because database name was at the start of the dump file and I didn`t want to mess with the rest of the file :-)

Advantages of software raid

Why using software raid when there are plenty hardware raid controllers with dedicated processors for checksum calculations, dedicated memory, cache and bbu? Well there is one major advantage of software raid solutions – hardware independence.
Recently we had a simultaneously crash of two disks in raid5 on 3ware 9550-sxu controller. That`s a real bad luck :-> Of course we recovered data from backups, but before that we tried to rebuild array. We discovered that one dik had crashed, but the other had just few bad sectors. As an experiment we cloned that disk without these few sectors and tried to rebuild the array. Unfortunatelly controller didn`t recognize that disk as a member of the array. It turned out that 3ware controller appends serial numbers of all members of array at the end of disks with a checksum (we tried to replace serial number of cloned disk with no luck).
So how would it look on software raid? Much easier. Linux for example writes only array identificator (UUID) so disk cloning is possible. Furthermore disks can be transfered to another hardware. With 3ware controller in case of its failure we would have to find another 3ware controller (probably the same model).
So a lesson has been taught – don`t rely on hardware raid, use raid6 when possible and keep your backups safe because they may save your ass someday :-)