andig/dbcopy

安装数: 41,075

依赖: 1

建议者: 0

安全: 0

星标: 3

关注者: 3

分支: 4

开放问题: 7

类型:项目

1.4.0 2020-11-29 12:09 UTC

This package is auto-updated.

Last update: 2024-08-29 04:08:59 UTC


README

dbcopy 是一个数据库复制和迁移工具。它被 Volkszaehler 项目使用。

设置

dbcopy 通过一个 dbcopy.json 配置文件进行配置。如果未使用 --config 选项指定,dbcopy 将在以下位置查找此文件:

  • 当前(工作)目录
  • dbcopy 自身的目录

配置文件具有以下结构

{
	"source": {
		// source database connection
		"driver": "pdo_mysql",
		"host": "localhost",
		"user": "travis",
		"password": "",
		"dbname": "volkszaehler"
	},
	"target": {
		// target database connection
		"driver": "pdo_sqlite",
		"path": "sqlite.db3",		// path is only used if driver = pdo_sqlite
		"host": "localhost",
		"user": "travis",
		"password": ""
		// "dbname": "backup"
	},
	"tables": [
		// table configuration (optional)
		// ------------------------------
		// table name
		// 		tables will be processed in the order they are mentioned:
		//		- foreign keys on target will be dropped
		//		- if a table is not listed here, it will not be touched
		// transfer mode
		//		skip:		table will not be copied
		//		copy:		entire table will be truncated on target and copied from source
		//		pk:			selective copy by primary key. only data not present on target
		// 						will be copied from source.
		{
			"name": "table_1",
			"mode": "copy"
		},
		...
	]
}

tables 部分是可选的。如果没有配置,dbcopy 将自动发现源模式中的所有表。

命令行语法

>./dbcopy
Database backup tool

Usage:
 [options] command [arguments]

Options:
 --help (-h) Display this help message.

Available commands:
 backup   Run backup
 clear    Clear target tables
 create   Create target schema
 drop     Drop target schema
 help     Displays help for a command
 influx   Copy data to InfluxDB
 list     Lists commands

创建命令

create 命令将源数据库连接的数据库模式复制到目标数据库。如果数据库驱动程序(例如 MySQL 和 SQLite)不同,则模式定义将针对目标平台进行翻译。受底层 Doctrine/DBAL 库的限制。

清除命令

clear 命令通过截断它们来清除目标模式中的所有表。使用 --drop 选项,将删除表。

删除命令

clear 相反,如果数据库平台支持,drop 命令将删除整个目标模式。例如,如果使用 SQLite,则不会删除 SQLite 数据库文件。

备份命令

backupdbcopy 的核心过程。 backup 执行以下步骤

  1. 验证源连接是否正常工作且源模式存在,同样适用于目标连接和模式。
  2. 获取表列表,无论是从配置文件获取还是通过自动发现源模式中的表。
  3. 目标 模式中的识别表上删除外键。这是允许复制数据而不违反引用完整性的必要步骤。
  4. 根据配置的复制模式逐个复制数据表。
  5. 重新应用 目标 模式上的外键(注意:目前由于性能原因尚未实现)。

Influx 命令

influx 命令可以从 Volkszaehler 数据表中复制数据到 InfluxDB 测量。这有助于使用 GrafanaChronograf 与 Volkszaehler 一起使用。

使用此命令,将忽略表配置,仅传输数据表,包括额外的实体属性。

限制

dbcopy 不支持触发器和存储过程。没有计划提供支持。