还原: Difference between revisions

m (Adding interlang links (links to translated versions of this page in other languages) triggered by origin English page "Restores" update.)
 
(6 intermediate revisions by the same user not shown)
Line 11: Line 11:
{{Template用户手册}}
{{Template用户手册}}


This page describe how to restore a backup of Dolibarr (for example after formatting your hard disk). To know how to do a complete backup, see page [[Backups|Backup]].
本页介绍如何还原Dolibarr的备份(如在硬盘被格式化后)。要了解如何进行完整备份,请参阅 [[备份]] 页面。


= 前提条件 =
=前提条件=
For a complete restore on a clean environment, we suppose that you :
要在干净的环境中进行一个完整的还原,必需:
* Have a backup of your database (into a dump file, done with mysqldump tool for example if you used a MySQL or MariaDb database).
* Have a backup of your document files directory.
* You know a login of an admin user you used before, when old Dolibarr backup was done.


= Step 1 - Reinstall Dolibarr software =
*拥有数据库的完整备份(例如,使用mysql的工具mysqldump把MySQL或MariaDb数据库备份到转储文件中)。
If you have uninstalled Dolibarr or not yet installed because you are on a new server, you must install Dolibarr as if you want to use it with a new clean database.
*拥有 documents 目录中所有文件的完整备份。
*拥有用于访问已备份的 Dolibarr 的管理员用户的登录名和密码。


Be carefull to choose the same database type than before (Mysql, PostgreSQL...).
=步骤 1 - 重新安装 Dolibarr 软件=
如果您已经卸载了Dolibarr或因为使用新服务器而尚未安装Dolibarr,则应先安装Dolibarr,使其拥有一个新的干净的数据库。


You can install any Dolibarr distribution of your choice (Dolibarr, DoliWamp, DoliMamp, any other Linux distribution...), however it must be exactly the same version (vX.Y) than the one used to make the backup. The version may be included in the file name of the database backup.
需要使用与以前相同类型的数据库(MySQL、PostgreSQL...)。


= Step 2 - Restore documents =
您可以选择任何的 Dolibarr发行版(Dolibarr、DoliWamp、DoliMamp、DoliDeb或任何其他的Linux发行版...)进行安装;但是,它必须与备份期间使用的'''版本'''(vX.Y)'''完全相同'''(如果您想升级版本,建议稍后再进行)。
On your new installed Dolibarr, go with an administrator user in the menu '''Home / System Tools / Restore'''.


Dolibarr will show you where your documents files must be stored. This directory must be empty (if not you can purge it).
注意:如果备份是使用 Dolibarr 进行操作的,则备份的Dolibarr版本信息包含在数据库备份文件的名称中。
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 =
=步骤 2 - 还原文档=
== MySql ==
在新安装的Dolibarr上,使用管理员帐户前往菜单 '''主页>管理工具>还原''' 。
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:
Dolibarr将通过以下消息向您显示文档文件目录的存储位置:
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).
Pour restaurer une sauvegarde de Dolibarr, vous devez:
* Reprendre le fichier archive (fichier zip par exemple) du répertoire documents et en extraire l'arborescence dans le répertoire documents d'une nouvelle
  installation de dolibarr ou dans le répertoire documents de cette installation ('''''chemin du répertoire des documents''''').
此目录必须为空(否则,可以清除其内容)。 您所要做的就是将备份的目录内容复制到该目录中。
=步骤 3 - 还原数据库=
==MySql==
在非Linux平台上,如果DOS无法识别'''mysql'''命令,这意味着PATH变量未指向 mysql.exe 所在的目录。 它必须:


On your new installed Dolibarr, go with an administrator user in the menu '''Home / System Tools / Restore'''.
*在系统变量PATH中添加mysql.exe文件所在的目录;


Choose the import method.
*将备份转储文件复制到mysql.exe文件所在的目录;
 
如果备份文件是压缩文件,请先解压缩该文件。
 
例如,一个名为 mysqldump_dolibarr_2.7.0_200812021800.sql.bz2 的已压缩备份文件必需被解压缩为文件                      mysqldump_dolibarr_2.7.0_200812021800.sql(Linux平台启动命令bunzip myfile.bz2,Windows平台启动命令 7zip)。
 
在新安装的Dolibarr上,使用管理员帐户登录,然后前往菜单 '''主页 / 管理工具 / 还原''' 。
 
选择导入MySQL的方法。
 
然后,Dolibarr在命令行中显示一个命令,该命令带有隐藏密码,以执行数据库还原。单击“显示完整命令”以获得未隐藏密码的完整命令。
 
例如,我们将有:


Dolibarr offers a command line to launch to restore the database. Click on "Show the full command".
For example, you will have :
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight>
</syntaxhighlight>


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.


*<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight> 是包含Dolibarr数据的MySQL数据库的名称;
*<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight>
*<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight>
*<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight>
*<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight>
*<syntaxhighlight lang="bash">
mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
</syntaxhighlight>


'''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.
打开命令行shell(Windows平台的DOS命令、Linux平台的shell终端...)。


前往保存着要还原的备份文件和命令'''mysql'''.exe的目录。运行先前提供的命令,其中每个空格(或无空格)、“-”或“<”都是必需的,否则将会产生语法错误。


'''备选方案''':您也可以使用 ''phpMyAdmin'' 的导入标签页来还原备份文件(通常,您不必选中任何特定选项,但备份文件必须绝对禁用 foreign_key_checks ,见下文)。然而,与上一方法不同的是,该方法不能保证提供的结果是正确的。
===故障排除===


=== Troubleshooting ===
[[File:Warning.png]] ERROR 1005 (HY000) at line 20: Can't create table `dolibarr`.`llx_accounting_account` (errno: 150 "Foreign key constraint is incorrectly formed")
 
=> 如果出现此类错误,则必须手动删除表 llx_accounting_account 和 llx_accounting_system,然后再次尝试加载。


[[File:Warning.png]] 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.
[[File:Warning.png]] Error loading table on foreign key.


=> 必须在'''还原过程中禁用外键检查''',否则由于外键之间的冲突,SQL备份将无法还原!如果备份正确,则应为默认情况。


[[File:Warning.png]] 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!
示例:在SQL文件的开头和结尾添加FOREIGN_KEY_CHECKS:


Eg: Add FOREIGN_KEY_CHECKS in headers and footers:
<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
-- SQL Dump
-- SQL Dump
Line 95: Line 128:


==PostgreSql==
==PostgreSql==
A procedure similar to MySQL but with '''pg_restore'''.
使用一个类似于mysql的过程:'''pg_restore''' 。


{{ToComplete}}
{{ToComplete}}


= Step 4 - Use your restored Dolibarr =
=步骤 4 - 使用已还原的Dolibarr=
After command is finished, you can go on Dolibarr logon.
还原命令执行完成后,您可以重新登录Dolibarr。现在,您必须使用备份时存在的登录名。所有数据均为备份时的数据。
Now you must use a login account that was existing when the backup was done.


=相关视频=
=相关视频=


Data restoration on a Docker installation:
将数据还原到Docker安装:
(vocal in french but subtitles are available and review in this language)
 
(法语配音,但字幕可用,并在此语言审查)


<youtube width="200" height="120">6H9ItBB_jK8</youtube>
<youtube width="200" height="120">6H9ItBB_jK8</youtube>

Latest revision as of 07:22, 12 September 2023

本页介绍如何还原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将通过以下消息向您显示文档文件目录的存储位置:

Pour restaurer une sauvegarde de Dolibarr, vous devez:

* Reprendre le fichier archive (fichier zip par exemple) du répertoire documents et en extraire l'arborescence dans le répertoire documents d'une nouvelle 
  installation de dolibarr ou dans le répertoire documents de cette installation (chemin du répertoire des documents).

此目录必须为空(否则,可以清除其内容)。 您所要做的就是将备份的目录内容复制到该目录中。

步骤 3 - 还原数据库

MySql

在非Linux平台上,如果DOS无法识别mysql命令,这意味着PATH变量未指向 mysql.exe 所在的目录。 它必须:

  • 在系统变量PATH中添加mysql.exe文件所在的目录;
  • 将备份转储文件复制到mysql.exe文件所在的目录;

如果备份文件是压缩文件,请先解压缩该文件。

例如,一个名为 mysqldump_dolibarr_2.7.0_200812021800.sql.bz2 的已压缩备份文件必需被解压缩为文件 mysqldump_dolibarr_2.7.0_200812021800.sql(Linux平台启动命令bunzip myfile.bz2,Windows平台启动命令 7zip)。

在新安装的Dolibarr上,使用管理员帐户登录,然后前往菜单 主页 / 管理工具 / 还原 。

选择导入MySQL的方法。

然后,Dolibarr在命令行中显示一个命令,该命令带有隐藏密码,以执行数据库还原。单击“显示完整命令”以获得未隐藏密码的完整命令。

例如,我们将有:

mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql

其中:

  • mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
    
    是包含Dolibarr数据的MySQL数据库的名称;
  • mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
    
  • mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
    
  • mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
    
  • mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
    
  • mysql mydatabase -h localhost -u databaseuser -pdatabasepass < mybackupfile.sql
    

打开命令行shell(Windows平台的DOS命令、Linux平台的shell终端...)。

前往保存着要还原的备份文件和命令mysql.exe的目录。运行先前提供的命令,其中每个空格(或无空格)、“-”或“<”都是必需的,否则将会产生语法错误。

备选方案:您也可以使用 phpMyAdmin 的导入标签页来还原备份文件(通常,您不必选中任何特定选项,但备份文件必须绝对禁用 foreign_key_checks ,见下文)。然而,与上一方法不同的是,该方法不能保证提供的结果是正确的。

故障排除

  ERROR 1005 (HY000) at line 20: Can't create table `dolibarr`.`llx_accounting_account` (errno: 150 "Foreign key constraint is incorrectly formed")

=> 如果出现此类错误,则必须手动删除表 llx_accounting_account 和 llx_accounting_system,然后再次尝试加载。


  Error loading table on foreign key.

=> 必须在还原过程中禁用外键检查,否则由于外键之间的冲突,SQL备份将无法还原!如果备份正确,则应为默认情况。

示例:在SQL文件的开头和结尾添加FOREIGN_KEY_CHECKS:

-- 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

使用一个类似于mysql的过程:pg_restore 。

  Page waiting to complete. To complete, create an account, go back and clic on "Modify".
  Page en attente d'être complété. Pour compléter, créez un compte, revenez et cliquez sur "Modifier".
  Página a completar. Para completarla, cree una cuenta, vuelva a la página y haga clic en "editar"
  Seite wartet auf Vervollständigung. Um zu helfen, erstelle ein Konto, gehe zurück und klicke auf "Bearbeiten".
  待完成,欲帮助完成,注册帐号,点击“编辑"
  ページは未完成の状態です。完成させるにはアカウントを作成し、ページに戻って「編集」をクリックして下さい。

步骤 4 - 使用已还原的Dolibarr

还原命令执行完成后,您可以重新登录Dolibarr。现在,您必须使用备份时存在的登录名。所有数据均为备份时的数据。

相关视频

将数据还原到Docker安装:

(法语配音,但字幕可用,并在此语言审查)