备份: Difference between revisions

Jump to navigation Jump to search
m (Adding interlang links (links to translated versions of this page in other languages) triggered by origin English page "Backups" update.)
Line 12: Line 12:
{{Template用户手册}}
{{Template用户手册}}


= [[File:Who.png]] Why ? =
=[[File:Who.png]] 为什么?=
There is several reason why it is important to "backup" a complete instance of Dolibarr. For example:
有几个原因可以说明“备份”一个完整的 Dolibarr 实例数据库是非常重要的。例如:
* Because you plan to make an upgrade and want to do a go back to previous version if it fails.
* Because you want to move Dolibarr from one server to another server.
* And of course, to be able to make a restore to be safe if something bad happens (crash disk, hack corruption, ...)
For all the above reasons, it is recommended to '''regularly''' make a new backup of all data used and saved by Dolibarr.


= [[File:Who.png]] What to save ? =
*计划进行升级,并希望在失败时能回溯到以前的版本。
*想要把 Dolibarr 从一台服务器迁移到另一台服务器上。
*最重要的是,为了在发生灾难(操作错误、磁盘崩溃、黑客入侵破坏...)时,能够进行恢复以确保安全。
 
基于上述所有原因,建议'''定期'''对Dolibarr使用和保存的所有数据进行备份。
 
=[[File:Who.png]] What to save ?=
Dolibarr save its data in 3 different spaces. They all must be saved before each version upgrade to be sure to be able to get back its data if a problem occurs or if you want to go back on previous version. This is the 3 kind of data you need to save to be sure to loose nothing.
Dolibarr save its data in 3 different spaces. They all must be saved before each version upgrade to be sure to be able to get back its data if a problem occurs or if you want to go back on previous version. This is the 3 kind of data you need to save to be sure to loose nothing.


== A) The database ==
==A) The database==
The database contains all data you have added from Dolibarr screens (except the attached/generated files that are presented in next chapter).
The database contains all data you have added from Dolibarr screens (except the attached/generated files that are presented in next chapter).
Saving the database must be done in a global way (all content). It is advised to '''save the database regularly'''. See the chapter "How" later in this  document.
Saving the database must be done in a global way (all content). It is advised to '''save the database regularly'''. See the chapter "How" later in this  document.


== B) Documents ==
==B) Documents==
All documents related to your Dolibarr instance are saved into directory defined into your config file ''dolibarrdir/htdocs/conf/conf.php''. If you kept the choice by default during first installation, it should be something like ''dolibarrdir/documents''. This directory must be completely saved.  
All documents related to your Dolibarr instance are saved into directory defined into your config file ''dolibarrdir/htdocs/conf/conf.php''. If you kept the choice by default during first installation, it should be something like ''dolibarrdir/documents''. This directory must be completely saved.  
When making an upgrade, the upgrade process should not change this directory, however this directory can be read and write by web server at any time, it might be altered by a bad action or a bug. To be sure to keep all your joined files and be able to restore them if they are accidentally deleted or altered, just make a copy of all content of this directory.
When making an upgrade, the upgrade process should not change this directory, however this directory can be read and write by web server at any time, it might be altered by a bad action or a bug. To be sure to keep all your joined files and be able to restore them if they are accidentally deleted or altered, just make a copy of all content of this directory.
Line 32: Line 34:
''Note'': copying the whole folder containing all your documents might be an heavy process, so if you can't do this regularly, at least make a backup of your database (which should be a lot smaller and would still enable you to recover most of your data, which can then be used to regenerate most of your documents).
''Note'': copying the whole folder containing all your documents might be an heavy process, so if you can't do this regularly, at least make a backup of your database (which should be a lot smaller and would still enable you to recover most of your data, which can then be used to regenerate most of your documents).


== C) The configuration file ==
==C) The configuration file==
The configuration file should not be modified by upgrade process, but it is more prudent to save it also when you do an upgrade.
The configuration file should not be modified by upgrade process, but it is more prudent to save it also when you do an upgrade.
The configuration file is called ''conf.php'' and you can find it into directory ''dolibarrdir/htdocs/conf/''.  
The configuration file is called ''conf.php'' and you can find it into directory ''dolibarrdir/htdocs/conf/''.  
Line 39: Line 41:
''Note'': This backup is however optional as you can still rebuild this file manually from scratch or with the Dolibarr install wizard if you know your database credentials (this file contains only parameters to connect to database and directory where you Dolibarr is installed). When making a restore, it is still possible to rebuild this file by an installation from scratch.
''Note'': This backup is however optional as you can still rebuild this file manually from scratch or with the Dolibarr install wizard if you know your database credentials (this file contains only parameters to connect to database and directory where you Dolibarr is installed). When making a restore, it is still possible to rebuild this file by an installation from scratch.


== D) Code change ==
==D) Code change==


Finally, any custom development of modules, ie: all php files (or others) that would have been added or modified to accommodate specific needs, should also be saved. In most cases, you are not concerned by this point.
Finally, any custom development of modules, ie: all php files (or others) that would have been added or modified to accommodate specific needs, should also be saved. In most cases, you are not concerned by this point.


= [[File:Who.png]] When ? =
=[[File:Who.png]] When ?=
Frequency of backups depends on how often you use Dolibarr and what you accept to loose if something happens. More often the frequency, less data will be lost in case of a crash/failure.
Frequency of backups depends on how often you use Dolibarr and what you accept to loose if something happens. More often the frequency, less data will be lost in case of a crash/failure.


Line 52: Line 54:
Also, the conf.php file needs to be backed only once (since it only changes if you change your host, and anyway can be made manually).
Also, the conf.php file needs to be backed only once (since it only changes if you change your host, and anyway can be made manually).


= [[File:Who.png]] How ?=
=[[File:Who.png]] How ?=


== A) The database ==
==A) The database==
There are 4 ways to backup your database:
There are 4 ways to backup your database:


=== Using Dolibarr system backup tool ===
===Using Dolibarr system backup tool===


This is the simplest way to make your backup, and in addition all your backups will be stored on server and will be listed, so that you can retrieve any version anyday.
This is the simplest way to make your backup, and in addition all your backups will be stored on server and will be listed, so that you can retrieve any version anyday.
Line 68: Line 70:
''Alternative'': the default method '''MySQL Dump (mysqldump)''' also needs that you have access to the mysqldump binary in execution on your server. If you are on a shared host that disable the mysqldump usage, you can try other method called '''MySQL Dump (php)'''. This method is not guaranted at 100%, so please try it first by yourself by making a backup and then restoring it on a local non production server to check that your data is correctly saved.
''Alternative'': the default method '''MySQL Dump (mysqldump)''' also needs that you have access to the mysqldump binary in execution on your server. If you are on a shared host that disable the mysqldump usage, you can try other method called '''MySQL Dump (php)'''. This method is not guaranted at 100%, so please try it first by yourself by making a backup and then restoring it on a local non production server to check that your data is correctly saved.


=== Using mysqldump ===
===Using mysqldump===
If you prefer a manual mode, you can also use the backup tool designed for your database.
If you prefer a manual mode, you can also use the backup tool designed for your database.
With Mysql, the command to backup your database into a file is :
With Mysql, the command to backup your database into a file is :
<syntaxHighlight lang="bash">
<syntaxhighlight lang="bash">
mysqldump -u user -pyourpass --result-file=mysqldump_databasename_version_date.sql databasename
mysqldump -u user -pyourpass --result-file=mysqldump_databasename_version_date.sql databasename
</syntaxHighlight>
</syntaxhighlight>
where :
where :
* ''user'' is MySQL user that Dolibarr use to connect to database,
 
* ''yourpass'' is password of MySQL account user (warning, no space between the p and yourpass),
*''user'' is MySQL user that Dolibarr use to connect to database,
* ''databasename'' is the name of Dolibarr database.
*''yourpass'' is password of MySQL account user (warning, no space between the p and yourpass),
*''databasename'' is the name of Dolibarr database.
 
Those informations (user, password and database) are available into your configuration file ''dolibarrdir/htdocs/conf/conf.php''
Those informations (user, password and database) are available into your configuration file ''dolibarrdir/htdocs/conf/conf.php''


The result file ("dump file"), is called mysqldump_databasename_version_date.sql where
The result file ("dump file"), is called mysqldump_databasename_version_date.sql where
* ''version'' is the dolibarr version (ex: 3.7).
 
* ''date'' can be replaced with a date, recommanded format is YYYYMMDD, with YYYY the year (ex. 2011), MM is month number (ex. 05) and DD is day in month (ex. 18).  
*''version'' is the dolibarr version (ex: 3.7).
With value used as example, we will get a dump file called ''mysqldump_databasename_3.7_20110518.sql.
*''date'' can be replaced with a date, recommanded format is YYYYMMDD, with YYYY the year (ex. 2011), MM is month number (ex. 05) and DD is day in month (ex. 18).
 
With value used as example, we will get a dump file called ''mysqldump_databasename_3.7_20110518.sql.''




If you want to have your file compressed (compressé) :
If you want to have your file compressed (compressé) :
<syntaxHighlight lang="bash">
<syntaxhighlight lang="bash">
mysqldump databasename -h host -u user -pyourpass -l --single-transaction -K --add-drop-table=TRUE --tables -c -e --hex-blob --default-character-set=utf8 | bzip2 > mysqldump_databasename_version_date.bz2
mysqldump databasename -h host -u user -pyourpass -l --single-transaction -K --add-drop-table=TRUE --tables -c -e --hex-blob --default-character-set=utf8 | bzip2 > mysqldump_databasename_version_date.bz2
</syntaxHighlight>
</syntaxhighlight>
Dump file will be generated with a bzip compressed format.
Dump file will be generated with a bzip compressed format.


Line 95: Line 101:


With Linux, to make a regular backup at 1:30 each day into file mysqldump_databasename_DD.sql.bz2, you can add this into your cron file:
With Linux, to make a regular backup at 1:30 each day into file mysqldump_databasename_DD.sql.bz2, you can add this into your cron file:
<syntaxHighlight lang="bash">
<syntaxhighlight lang="bash">
30 1 * * * mysqldump databasename -h host -u user -pyourpass -l --single-transaction -K --add-drop-table=TRUE --tables -c -e --hex-blob --default-character-set=utf8 | bzip2 > mysqldump_databasename_`date +%d`.sql.bz2
30 1 * * * mysqldump databasename -h host -u user -pyourpass -l --single-transaction -K --add-drop-table=TRUE --tables -c -e --hex-blob --default-character-set=utf8 | bzip2 > mysqldump_databasename_`date +%d`.sql.bz2
</syntaxHighlight>
</syntaxhighlight>


=== Using phpMyAdmin ===
===Using phpMyAdmin===


Do not use phpMyAdmin to save your database ! phpMyAdmin generates some dump files, but if you used default option, you won't be able to restore it. You must enable one specific option for you to be able to restore your backup later on (if you forgot to do so and already have a backup that you want to restore, please read the note about FOREIGN_KEY_CHECKS below).
Do not use phpMyAdmin to save your database ! phpMyAdmin generates some dump files, but if you used default option, you won't be able to restore it. You must enable one specific option for you to be able to restore your backup later on (if you forgot to do so and already have a backup that you want to restore, please read the note about FOREIGN_KEY_CHECKS below).
Line 105: Line 111:
In phpMyAdmin, click on the tab '''Export''', then select your Dolibarr's database/tables (depending whether you are in multi-database view or tables view), and then '''enable''' the option '''Disable foreign key checks''', also check that the output will be SQL, and then you can validate your export. Also, not that, even with this option, backup is NEVER guaruanted with phpMyAdmin and is OFTEN useless. The only secured method is to use mysqldump (from Dolibarr or manually. See the two previous chapters).
In phpMyAdmin, click on the tab '''Export''', then select your Dolibarr's database/tables (depending whether you are in multi-database view or tables view), and then '''enable''' the option '''Disable foreign key checks''', also check that the output will be SQL, and then you can validate your export. Also, not that, even with this option, backup is NEVER guaruanted with phpMyAdmin and is OFTEN useless. The only secured method is to use mysqldump (from Dolibarr or manually. See the two previous chapters).


=== Using another Third-Party Tools ===
===Using another Third-Party Tools===


You can also use third-party database backup softwares, like php scripts that you can upload on your server (such as db2SQL by Howard Yeend or BigDump), or also use database designer/workbench softwares which generally offer to remotely connect to your database and allow you to make a full backup (along to remotely manage your database).
You can also use third-party database backup softwares, like php scripts that you can upload on your server (such as db2SQL by Howard Yeend or BigDump), or also use database designer/workbench softwares which generally offer to remotely connect to your database and allow you to make a full backup (along to remotely manage your database).
Line 115: Line 121:
[[File:Warning.png]] in any case, '''your sql backup file should disable foreign keys prior to restoring''', else your backup won't be restorable because of foreign keys clashing!
[[File:Warning.png]] in any case, '''your sql backup file should 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:
Eg: Add FOREIGN_KEY_CHECKS in headers and footers:
<syntaxHighlight lang="sql">
<syntaxhighlight lang="sql">
-- SQL Dump
-- SQL Dump
-- Server version: 5.5.8
-- Server version: 5.5.8
Line 139: Line 145:


SET FOREIGN_KEY_CHECKS=1;
SET FOREIGN_KEY_CHECKS=1;
</syntaxHighlight>
</syntaxhighlight>




[[File:Warning.png]] Mysqldump (using command line tool or using Dolibarr backup tool) is the most secure way to backup your data because it is developed along MySQL and thus is always up-to-date. '''PhpMyAdmin''' and other thirdparty tools may generate a correct SQL dump but may be outdated or miss some features (depending on options you choose).
[[File:Warning.png]] Mysqldump (using command line tool or using Dolibarr backup tool) is the most secure way to backup your data because it is developed along MySQL and thus is always up-to-date. '''PhpMyAdmin''' and other thirdparty tools may generate a correct SQL dump but may be outdated or miss some features (depending on options you choose).


== B) The documents ==
==B) The documents==
Just copy the Documents folder (''dolibarr/documents'' by default) to your local backup directory.
Just copy the Documents folder (''dolibarr/documents'' by default) to your local backup directory.


Line 150: Line 156:




== C) The configuration file ==
==C) The configuration file==
A simple copy of file ''conf/conf.php'' into a directory dedicated to your backup is enough.
A simple copy of file ''conf/conf.php'' into a directory dedicated to your backup is enough.


= [[File:Astuces.png]] Restore =
=[[File:Astuces.png]] Restore=
This topic is explained into page [[Restores]].
This topic is explained into page [[Restores]].


714

edits

Navigation menu