简体   繁体   中英

mysql partial restore from backup

Due to a server crash I need to restore some rows, created within a certain period of time, from the backup (located on my local machine) onto the live db on server.

To select the rows in question I plan to do something like this from the backupdatabase:

SELECT *
FROM access AS t1
WHERE AccessId IN (
SELECT AccessId FROM access_completed AS t1
WHERE (TIMEDIFF(CCompleteDateTime, "2011-01-24 02:00:00") < 23 AND TIMEDIFF(CCompleteDateTime, "2011-01-24 02:00:00") > 0)
)

How do I insert the resulting rows into the live db?

You can use SELECT ... INTO OUTFILE on the backup and LOAD DATA INFILE to load data.

INTO OUTFILE dumps the selected data to a local file, in a format that MySQL can parse back using LOAD DATA INFILE . So you just have to dump and load like this:

SELECT * FROM [rest of your query] INTO OUTFILE '/tmp/outfile'

Copy outfile to the other server

And on the other server:

LOAD DATA INFILE /tmp/outfile' INTO TABLE access;

It would also work with FEDERATED tables. This would allow to query the backup database from the main server; so you could do INSERT INTO access ... SELECT ... FROM federated_access ... .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM