重复的站点未被识别为站点

时间:2017-12-04 作者:Arcticooling

我使用以下代码复制了一个站点。在最后一行之前,所有代码都工作正常(网站本身在web上运行,但最后一行代码失败,我收到一个错误):

echo "Please enter the domain of the site for duplication"
read domain
echo "Please enter the password of the site\'s DB user"
read -s psw

cp -r /var/www/html/${domain} /var/www/html/test
sed -i "s/${domain}/test"/g /var/www/html/test/wp-config.php
mysql -u root -p <<-MYSQL
    DROP user IF EXISTS \'test\'@\'localhost\'; SELECT user FROM mysql.user;
    DROP database IF EXISTS test; show databases;

    CREATE user \'test\'@\'localhost\' IDENTIFIED BY \'${psw}\';
    CREATE database test;
    GRANT ALL PRIVILEGES ON test.* TO test@localhost;
MYSQL

cd /var/www/html/test
wp search-replace "${domain}" "test" --allow-root
最后一个WPCLI命令输出:

错误:未安装您请求的站点。

其他WPCLI命令也是如此。由于某些原因,WPCLI无法识别test 地点

知道为什么WPCLI在我清楚地位于其目录中时无法识别我的站点吗?

motivast更新:

mysql -u root -p <<-MYSQL
    DROP user IF EXISTS \'test\'@\'localhost\'; SELECT user FROM mysql.user;
    DROP database IF EXISTS test; show databases;

    CREATE user \'test\'@\'localhost\' IDENTIFIED BY \'${psw}\';
    CREATE database test;
    GRANT ALL PRIVILEGES ON test.* TO test@localhost;
MYSQL

mysqldump -u root -p ${domain} > test.sql
mysql -u root -p test < test.sql
我的逻辑正确吗?我通过考试了吗?

1 个回复
最合适的回答,由SO网友:kierzniak 整理而成

错误来自上一个命令wp search-replace "${domain}" "test" --allow-root. 您的WordPress站点尚未安装,您希望执行需要安装WordPress的命令。

在脚本的前面,您正在删除test 并创建一个新的数据库,但您必须用WordPress表填充它。如果没有此表,WordPress不会按照错误说明安装。您必须通过访问浏览器中的测试页或执行wp core install 命令行中有参数。

您还可以使用复制数据库mysqldumpmysql 命令:

转储:mysqldump -u root -p [database_name] > dumpfilename.sql

导入:mysql -u root -p [database_name] < dumpfilename.sql

以下脚本将为您的:

#!/bin/bash
#===================================================================================
#
# FILE: wpdup.sh
#
# USAGE: wpdup.sh <dir_old> <dir_new> <dbname_old> <dbname_new> <dbuser_new> <dbpass_new> <domain_old> <domain_new>
#
# DESCRIPTION: Duplicate WP installation with database and replace domain.
#
# OPTIONS: see function ’usage’ below
#===================================================================================

EXPECTED_ARGS=8
E_BADARGS=65

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: $0 <dir_old> <dir_new> <dbname_old> <dbname_new> <dbuser_new> <dbpass_new> <domain_old> <domain_new>"
  exit $E_BADARGS 
fi

MYSQL=`which mysql`
MYSQLDUMP=`which mysqldump`
WP=`which wp`
CP=`which cp`

TMPDIR=\'/tmp\'

DIR_OLD=$1
DIR_NEW=$2

DBNAME_OLD=$3
DBNAME_NEW=$4

DBUSER_NEW=$5
DBPASS_NEW=$6

DOMAIN_OLD=$7
DOMAIN_NEW=$8

echo -n "Enter root mysql password:"
read -s DBROOT_PASS

echo "Copy directory"
# Copy WP site  
$CP -r $DIR_OLD $DIR_NEW

echo "Dump database"
# Dump database
$MYSQLDUMP -u root -p$DBROOT_PASS $DBNAME_OLD > "${TMPDIR}/dbdump.sql"

# Create new database if not exists and add privileges.
Q1="DROP DATABASE IF EXISTS $DBNAME_NEW;"
Q2="DROP USER \'$DBUSER_NEW\'@\'localhost\';"
Q3="CREATE DATABASE $DBNAME_NEW COLLATE utf8_general_ci;"
Q4="CREATE USER \'$DBUSER_NEW\'@\'localhost\' IDENTIFIED BY \'$DBPASS_NEW\';"
Q5="GRANT ALL PRIVILEGES ON $DBNAME_NEW.* TO \'$DBUSER_NEW\'@\'localhost\' IDENTIFIED BY \'$DBPASS_NEW\';"
Q6="FLUSH PRIVILEGES;"

SQL="${Q1}${Q2}${Q3}${Q4}${Q5}${Q6}"

echo "Create database"
$MYSQL -e "${SQL}" -u root -p$DBROOT_PASS

echo "Import database"
# Import dumped database
$MYSQL -u root -p$DBROOT_PASS $DBNAME_NEW < "${TMPDIR}/dbdump.sql"

echo "Create wp config"
# Create new wordpress config
cd $DIR_NEW && $WP core config --dbname=${DBNAME_NEW} --dbuser=${DBUSER_NEW} --dbpass=${DBPASS_NEW} --dbhost="localhost" --allow-root --skip-check --force

echo "Replace domain"
# Replace domain in new wp site
cd $DIR_NEW && $WP search-replace "${DOMAIN_OLD}" "${DOMAIN_NEW}" --allow-root
您可以通过以下方式使用它:

sudo ./wpdup.sh /var/www/test /var/www/testnew wp_test wp_testnew wp_testnew xxxxxx test.dev testnew.dev

结束

相关推荐

mysql query order by

我是mysql新手。我有个问题:$tenantsInfo = $wpdb->get_results(\"SELECT * FROM exp_ten WHERE tenant_number = \" . (int) $user->ID); 我需要通过desc订购;由于双引号,我不确定在何处添加desc订单。请任何人指出我应该在何处添加它?非常感谢。