简体   繁体   中英

Restore db backup with php web application

unfortunately i lost my database a few days ago but luckily i had daily back up.

unfortunately i lost my database(some of my data not whole db) a few days ago but luckily i have daily backup.Today i find out that i have to restore 180 huge database. I need to compare every 180 databases(backups) with the current db(my db) and insert the data that is not any more in my db. AT the beginning i want to use some application like(NAVICAT or db forge studio) but it's not possible that take a lot of time. and also i wanted to compare the SQL test with each other and it's not possible too.

now i have to build a web application(PHP) to restore the databases but i don't know how

i'll be appreciate if anyone help me.

thank you.

If it is a large file, do not open it. Stream it.

$backup = fopen("yourBackUp.sql", "r");

// ...

fclose($backup);

If you have many files, use GLOB .

foreach(glob(dirname(__FILE__) . '/*.sql', GLOB_BRACE) as $sql) {
    $backup = fopen($sql, "r");

    // ...
}

If your DB is set-up correctly, you should not be able to insert duplicate rows.

while (($line = fgets($backup)) !== false)
    try {
        Illuminate\Support\Facades\DB::raw($line);
    } catch ( Exception $e ) { 
        // duplicate row
    }
}

Without seeing what you have done and your programmatic issue, we cannot help.

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