1

I write a Web application using Yii framework and MySQL.

Now the boss wants "to store all changes in the database", in order to be able to restore older data if someone destroys some important information in the current version of the data.

What is to store all changes in the database is vague. I am not sure what exactly we should do.

How to fulfill this vague boss's requirement?

Can we do it with MySQL logs? What are pros and contras of using MySQL logs for this? Is it true that we need a programmer (me) to restore some (possibly not all) data from MySQL logs? Can MySQL (partial) data restoration be made simple?

Or should I hard work to manually (not with MySQL logs) store all old data in specific MySQL tables?

4

3 回答 3

3

我猜您所描述的是审计跟踪,它可以方便地返回并查看历史记录,但至于恢复,则需要手动进行。

查看用于创建审计跟踪的技术。

于 2013-07-23T16:51:37.313 回答
1

您可能想尝试在扩展库中搜索诸如eactsasversioned之类的东西,它将存档对记录所做的编辑。我不确定它是否会保存已删除的记录,但它似乎接近你想要的。

于 2013-07-23T17:32:45.457 回答
0

如果您正在寻找可以轻松恢复的东西,您可能需要定期运行备份脚本。我在 cron 中使用 bash 脚本(如下所示)来每小时备份我担心的数据库。我的数据库相当小,所以这只需要几秒钟,如果你超级偏执,可以增加到每 15 分钟运行一次。

    #!/bin/bash
    dbName1="li_appointments"
    dbName2="lidb_users"
    dbName3="orangehrm_li"

    fileName1=$dbName1"_`date +%Y.%m.%d-%H:%M:%S`.sql"
    fileName2=$dbName2"_`date +%Y.%m.%d-%H:%M:%S`.sql"
    fileName3=$dbName3"_`date +%Y.%m.%d-%H:%M:%S`.sql"

    backupDir="/home/backups/mysql"

    mysqldump -u backup_user --password='********************************' $dbName1 > $backupDir/$fileName1
    mysqldump -u backup_user --password='********************************' $dbName2 > $backupDir/$fileName2
    mysqldump -u backup_user --password='********************************' $dbName3 > $backupDir/$fileName3

    bzip2 $backupDir/$fileName1
    bzip2 $backupDir/$fileName2
    bzip2 $backupDir/$fileName3

    gpg -c --passphrase '********************************' $backupDir/$fileName1".bz2"
    gpg -c --passphrase '********************************' $backupDir/$fileName2".bz2"
    gpg -c --passphrase '********************************' $backupDir/$fileName3".bz2"


    rm $backupDir/*.bz2

    echo "Backups completed on `date +%D`" >> $backupDir/backuplog.log
于 2013-07-23T18:20:26.523 回答