简体   繁体   English

使用 php web 应用程序恢复数据库备份

[英]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.不幸的是我几天前丢失了我的数据库(我的一些数据不是整个数据库)但幸运的是我每天都有备份。今天我发现我必须恢复 180 个巨大的数据库。 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.我需要将每 180 个数据库(备份)与当前数据库(我的数据库)进行比较,并插入不再存在于我的数据库中的数据。 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.一开始我想使用一些应用程序,如(NAVICAT 或 db forge studio),但不可能花很多时间。 and also i wanted to compare the SQL test with each other and it's not possible too.而且我还想将 SQL 测试相互比较,这也是不可能的。

now i have to build a web application(PHP) to restore the databases but i don't know how现在我必须构建一个 Web 应用程序(PHP)来恢复数据库,但我不知道如何

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 .如果您有很多文件,请使用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.没有看到您所做的事情和您的程序问题,我们无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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