473,763 Members | 7,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3250

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.200209 01.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.200209 01.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
2271
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 task.TaskID = p_description.pTaskLink GROUP BY TaskID ORDER BY TaskName
0
1985
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 Server objects (databases, tables, views, stored procedures, user defined data functions etc.) accross servers. - view and print dependencies; - generate color coded scripts for any object in the database or many of them at once (many configurable...
4
1786
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 database with "mysql -u root -psecret < backup.sql" gives the following error message: ERROR 1064 at line 11: You have an error in your SQL syntax near '123456789' at line 1
1
5204
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 extensions ..001, .002 and .003. The files are placed into a d:\dbname.0\db2.0\yyyymmdd directory tree, as does DB2/2 when performing the backup. I created a similar DMS 3x1Gb DB on another machine for the restore. But when I launch: db2...
3
2746
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 particulars about my app 1) The front end is distributed as a .mde file. 2) Front end uses workgroup security 3) A separate logon form is used to actually launch the front end. 4) My app includes a backup front end form, that backups the front end...
1
2984
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 query. I am familiar with database concepts, but am new to Access. The problem is in the query statement. I'm not sure what to put after FROM because it would depend on the user's entry. I would need it to look something like this, but my...
1
6653
by: sridhar21 | last post by:
hi to all i am sridhar My question is: To select all tables in a database is
2
4221
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
1270
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 tables neighter their names. i nead a solution like SELECT * from database_name.* thanks
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8821
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.