11. 备份(主要使用PostgreSQL)

备份总是个好主意。如果您的系统不这样做,您应该设置它。请注意,无论何时进行升级, cubicweb-ctl 提供备份数据库的功能。备份有多种方法。

11.1. 使用PostgreSQL(仅此)

继续之前,请确保以下权限正确:

# chgrp postgres /var/lib/cubicweb/backup
# chmod g+ws /var/lib/cubicweb/backup
# chgrp postgres /etc/cubicweb.d/*<instance>*/sources
# chmod g+r /etc/cubicweb.d/*<instance>*/sources

只需在安装的cron中使用pg_转储 postgres 数据库服务器上的用户::

# m h  dom mon dow   command
0 2 * * * pg_dump -Fc --username=cubicweb --no-owner <instance> > /var/backups/<instance>-$(date '+%Y-%m-%d_%H:%M:%S').dump

11.2. 使用 cubicweb-ctl db-dump

The CubicWeb way is to use the db-dump command. For that, you have to put your passwords in a user-only-readable file at the home directory of root user. The file is .pgpass (chmod 0600), in this case for a socket run connection to PostgreSQL

/var/run/postgresql:5432:<instance>:<database user>:<database password>

Postgres文档 .pgpass format can be found here

然后将以下命令添加到用户的crontab中 (crontab -e ):

# m h  dom mon dow   command
0 2 * * * cubicweb-ctl db-dump <instance>

11.3. 备份忍者

您可以使用组合 backup-ninja (示例目录中有Postgres脚本) backuppc )(用于版本控制)。

请注意,在 CubicWeb路 它为您的密码添加了第二个容易出错的位置。

警告

记住,每当使用Postgres以外的其他数据库后端时,这些指示都会使您失败。此外,它还可以正确处理外部管理的数据,如文件(使用字节文件系统存储)。