还原
本页介绍如何还原Dolibarr的备份(如在硬盘被格式化后)。要了解如何进行完整备份,请参阅 备份 页面。
前提条件
要在干净的环境中进行一个完整的还原,必需:
- 拥有数据库的完整备份(例如,使用mysql的工具mysqldump把MySQL或MariaDb数据库备份到转储文件中)。
- 拥有 documents 目录中所有文件的完整备份。
- 拥有用于访问已备份的 Dolibarr 的管理员用户的登录名和密码。
步骤 1 - 重新安装 Dolibarr 软件
如果您已经卸载了Dolibarr或因为使用新服务器而尚未安装Dolibarr,则应先安装Dolibarr,使其拥有一个新的干净的数据库。
需要使用与以前相同类型的数据库(MySQL、PostgreSQL...)。
您可以选择任何的 Dolibarr发行版(Dolibarr、DoliWamp、DoliMamp、DoliDeb或任何其他的Linux发行版...)进行安装;但是,它必须与备份期间使用的版本(vX.Y)完全相同(如果您想升级版本,建议稍后再进行)。
注意:如果备份是使用 Dolibarr 进行操作的,则备份的Dolibarr版本信息包含在数据库备份文件的名称中。
步骤 2 - 还原文档
在新安装的Dolibarr上,使用管理员帐户前往菜单 主页>管理工具>还原 。
Dolibarr将通过以下消息向您显示文档文件目录的存储位置。Dolibarr will show you where your documents files must be stored. This directory must be empty (if not you can purge it).
此目录必须清除(您可以清除其内容)。 您所要做的就是将备份目录的内容从旧文件复制到该目录中。All you have to do then is to copy content of your saved directory of old documents files into this directory.
Step 3 - Restore the database
MySql
Copy the backup dump file into the same directory than the command mysql.
If your backup file was a compressed archive, unzipping the file before might be required: For example, a bzip archive backup named mysqldump_dolibarr_2.7.0_200812021800.sql.bz2 must be uncompressed to mysqldump_dolibarr_2.7.0_200812021800.sql (Launch bunzip myfile.bz2 under Linux, or use 7zip under Windows).
On your new installed Dolibarr, go with an administrator user in the menu Home / System Tools / Restore.
Choose the import method.
Dolibarr offers a command line to launch to restore the database. Click on "Show the full command". For example, you will have :
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
Open a command line shell (DOS Command line with Windows or a Shell terminal with Linux). Go into the directory where command mysql and your backup file is stored. Launch the command provided previously.
Alternative: you can also use phpMyAdmin Import tab to restore your backup file (normally you don't have to check any particular option, but your backup file needs to disable foreign_key_checks, see below). Also this method can not be guaranted and may failed in some cases.
Troubleshooting
ERROR 1005 (HY000) at line 20: Can't create table `dolibarr`.`llx_accounting_account` (errno: 150 "Foreign key constraint is incorrectly formed")
=> If you have such error, you mut manually delete the table llx_accounting_account and llx_accounting_system, before trying again.
If you have error with foreign keys, check that your sql backup file disable foreign keys prior to restoring, else your backup won't be restorable because of foreign keys clashing!
Eg: Add FOREIGN_KEY_CHECKS in headers and footers:
-- SQL Dump
-- Server version: 5.5.8
SET FOREIGN_KEY_CHECKS=0;
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
CREATE TABLE IF NOT EXISTS `llx_accountingaccount` (
INSERT INTO ...
CREATE TABLE ...
INSERT INTO ...
...
SET FOREIGN_KEY_CHECKS=1;
PostgreSql
A procedure similar to MySQL but with pg_restore.
Step 4 - Use your restored Dolibarr
After command is finished, you can go on Dolibarr logon. Now you must use a login account that was existing when the backup was done.
相关视频
Data restoration on a Docker installation: (vocal in french but subtitles are available and review in this language)