473,408 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Restoring select databases/tables from an --all-databases backup

I use the --all-databases switch to backup my entire database.
Sometimes there's a need to restore individual databases or tables form
the backup file. What command should I use for this?

Thanks,
Raffi

Jul 23 '05 #1
2 3220

Taken from: Linux Server Hacks
By Rob Flickenger

Here is a method for restoring a single mysql table from a huge
mysqldump

Like a good admin, you faithfully dump your mysql tables every night,
and save them to the filesystem in compressed form (presumably to be
picked up by a backup script later). You probably have something like
this running in cron on your database server (or one of its replicated
slaves):

for x in `mysql -Bse show databases`; do
mysqldump $x | gzip -9 > /var/spool/mysqldump/$x.`date +%Y%m%d`.gz
done
This will cover you if anything catastrophic happens to your live
database. But if your database grows to an appreciable size, doing
partial restores can be difficult. On a database with several million
rows, your dumps suddenly become massive piles of data that need to be
sifted through. How can you easily restore a single table out of a
several hundred megabyte compressed dump?

Here's a simple method using Perl. Create a script called
extract-table, with this in it:

#!/usr/bin/perl -wn
BEGIN { $table = shift @ARGV }
print if /^create table $table\b/io .. /^create table (?!$table)\b/io;
To extract the User table from the dump of a database called randomdb,
try something like this:

# zcat /var/spool/mysqldump/randomdb.20020901.gz | extract-table Users
~/

Users.dump
Now you can restore your Users table with a simple:

# mysql randomdb -e "drop table Users"
# mysql randomdb < ~/Users.dump

Jul 23 '05 #2
Bill Turczyn wrote:
Taken from: Linux Server Hacks
By Rob Flickenger

Here is a method for restoring a single mysql table from a huge
mysqldump

Like a good admin, you faithfully dump your mysql tables every night,
and save them to the filesystem in compressed form (presumably to be
picked up by a backup script later). You probably have something like
this running in cron on your database server (or one of its replicated slaves):

for x in `mysql -Bse show databases`; do
mysqldump $x | gzip -9 > /var/spool/mysqldump/$x.`date +%Y%m%d`.gz
done
This will cover you if anything catastrophic happens to your live
database. But if your database grows to an appreciable size, doing
partial restores can be difficult. On a database with several million
rows, your dumps suddenly become massive piles of data that need to be sifted through. How can you easily restore a single table out of a
several hundred megabyte compressed dump?

Here's a simple method using Perl. Create a script called
extract-table, with this in it:

#!/usr/bin/perl -wn
BEGIN { $table = shift @ARGV }
print if /^create table $table\b/io .. /^create table (?!$table)\b/io;

To extract the User table from the dump of a database called randomdb, try something like this:

# zcat /var/spool/mysqldump/randomdb.20020901.gz | extract-table

Users
~/

Users.dump
Now you can restore your Users table with a simple:

# mysql randomdb -e "drop table Users"
# mysql randomdb < ~/Users.dump


That's exactly what is happening and many times only specific
tables/databases get corrupted and it's inefficient to restore the
complete database structure. I'll try the script out as soon as I get a
chance. I guess mysql doesn't have a built in feature that resores
individual tables and databases from a full backup and leaves
everything else alone.

Raffi

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerald Maher | last post by:
Hi I need to select 2 tables . The field 'p_description' is not always aviable but i still need to print it to the screen SELECT * FROM task,p_description WHERE ComponentIDLink = 34 OR...
0
by: SQLServer007 | last post by:
25 more days until the "get it free" promotion runs out for xSQL Object (you can get it from http://www.x-sql.com) Here are just some of the great features packed in the product: - Compare SQL...
4
by: Raffi | last post by:
Hi, I'm developing a database application that uses numeric databases. At this point not using numeric databases is not an option. Doing a mysqldump works. However when trying to restore the...
1
by: Luc Le Blanc | last post by:
I'm trying to restore a backup from a DMS DB2/2 database. The original DB has 3x 1Gb containers in the user tablespace. So the backup has 3 files, bearing the time of the backup as file name, with...
3
by: rdemyan via AccessMonster.com | last post by:
I'm thinking about providing a relatively easy method for users to restore the front end from a backup. The purpose is to allow for restoring if the front end becomes corrupt. Here are some...
1
by: wizardRahl | last post by:
Hello, I'm curious to know if there is a way to select all tables when using a query in access. I have some (unsuccessful) cascading combo boxes and need a little help maybe working out the...
1
by: sridhar21 | last post by:
hi to all i am sridhar My question is: To select all tables in a database is
2
by: info | last post by:
Hi, my query is: SELECT a.symbol_art,b.node_key FROM artykuly a, art_podz b WHERE a.symbol_art=b.symbol_art
2
by: antoine1987 | last post by:
hi, if anyone can help me please, i nead to select all the tables in my database in one instruction. all the tables have the same structure. the problem is that i dont know the number of...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.