备份和恢复

OTOBO有内置的脚本用于备份和恢复,执行脚本时加入``-h``可以看到更详细的信息。

备份

Note

创建一个新的备份,需要用户 ``otobo``具备对目的目录有写的权限。

otobo> /opt/otobo/scripts/backup.pl -h

脚本的输出结果为:

Backup an OTOBO system.

Usage:
 backup.pl -d /data_backup_dir [-c gzip|bzip2] [-r DAYS] [-t fullbackup|nofullbackup|dbonly]
 backup.pl --backup-dir /data_backup_dir [--compress gzip|bzip2] [--remove-old-backups DAYS] [--backup-type fullbackup|nofullbackup|dbonly]

Short options:
 [-h]                   - Display help for this command.
 -d                     - Directory where the backup files should place to.
 [-c]                   - Select the compression method (gzip|bzip2). Default: gzip.
 [-r DAYS]              - Remove backups which are more than DAYS days old.
 [-t]                   - Specify which data will be saved (fullbackup|nofullbackup|dbonly). Default: fullbackup.


Long options:
 [--help]                     - same as -h
 --backup-dir                 - same as -d
 [--compress]                 - same as -c
 [--remove-old-backups DAYS]  - same as -r
 [--backup-type]              - same as -t

Help:
Using -t fullbackup saves the database and the whole OTOBO home directory (except /var/tmp and cache directories).
Using -t nofullbackup saves only the database, /Kernel/Config* and /var directories.
With -t dbonly only the database will be saved.

Override the max allowed packet size:
When backing up a MySQL one might run into very large database fields. In this case the backup fails.
For making the backup succeed one can explicitly add the parameter --max-allowed-packet=<SIZE IN BYTES>.
This setting will be passed on to the command mysqldump.

Output:
 Config.tar.gz          - Backup of /Kernel/Config* configuration files.
 Application.tar.gz     - Backup of application file system (in case of full backup).
 VarDir.tar.gz          - Backup of /var directory (in case of no full backup).
 DataDir.tar.gz         - Backup of article files.
 DatabaseBackup.sql.gz  - Database dump.

恢复

Note

恢复数据库时,请确认数据库``otobo`` 存在并且不包含表单。

otobo> /opt/otobo/scripts/restore.pl -h

脚本的输出结果为:

Restore an OTOBO system from backup.

Usage:
 restore.pl -b /data_backup/<TIME>/ -d /opt/otobo/

Options:
 -b                     - Directory of the backup files.
 -d                     - Target OTOBO home directory.
 [-h]                   - Display help for this command.

在Docker下运行OTOBO的考量

相同的脚本可以用于OTOBO在Docker下的运行,不过要考虑一些Docker特定的限制。

首先我们要确认备份文件创建时所在的文件系统,不是一个容器内部的文件系统。因为在那种情况下,当容器被停止后,所有的数据都会丢失。所以,备份目录必须在一个卷。现在我们先考虑最简单的一种情况,备份目录是Docker主机的一个本地目录。备份目录在容器中的位置可以随意选择。在本例中我们选择本地目录``otobo_backup``作为备份目录在主机的位置, 而在容器中的位置就是``/otobo_backup`` 。

首先我们需要创建卷。

# create the backup directory on the host
docker_admin> mkdir otobo_backup

# create the Docker volume
docker_admin> docker volume create --name otobo_backup --opt type=none --opt device=$PWD/otobo_backup --opt o=bind

# inspect the volume out of curiosity
docker_admin> docker volume inspect otobo_backup

为了创建备份,我们需要一个运行的数据库和卷``otobo_opt_otobo`` 以及 otobo_backup,这意味着网站服务器和Daemon可能,不是必须,被停掉。

# create a backup
docker_admin> docker run -it --rm --volume otobo_opt_otobo:/opt/otobo --volume otobo_backup:/otobo_backup --network otobo_default rotheross/otobo:latest-10_0 scripts/backup.pl -d /otobo_backup

# check the backup file
docker_admin> tree otobo_backup

为了把备份文件恢复回来,我们需要确认恢复哪个备份文件。占位符``<TIMESTAMP>`` 就如同``2020-09-07_09-38``的标记一样。

# create a backup
docker_admin> docker run -it --rm --volume otobo_opt_otobo:/opt/otobo --volume otobo_backup:/otobo_backup --network otobo_default rotheross/otobo:latest-10_0 scripts/restore.pl -d /opt/otobo -b /otobo_backup/<TIMESTAMP>