sh 导入未使用--opt或--extended-insert转储的单个MySQL .sql文件(如来自VaultPress转储。显示一些* very * basic

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 导入未使用--opt或--extended-insert转储的单个MySQL .sql文件(如来自VaultPress转储。显示一些* very * basic相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash
VP_DB="set_to_your_dbname"
[[ ! -d "done" ]] && mkdir done
[[ ! -d "error" ]] && mkdir error

echo "To prevent any writes to the database during the import, you should disable the site. Add this to your wp-config.php:"
echo "if( DB_NAME == '$VP_DB' ) die( 'This site is is disabled during import.' );"
read -p "Press Enter to continue. "

time for VP_SQL_FILE in *.sql ; do
  [[ -z "$VP_DB" ]] && echo "You must set the 'VP_DB' variable first " && break
  VP_IMPORT_INSERTS=$(grep -c '^INSERT' "$VP_SQL_FILE")
  VP_TABLE=$(grep -m 1 '^CREATE TABLE' "$VP_SQL_FILE" | sed -r -e 's/^CREATE TABLE (`[^`]+`).*/\1/')
  printf "Processing table %s from %s - %d inserts, %s." "$VP_TABLE" "$VP_SQL_FILE" "$VP_IMPORT_INSERTS" $(ls -lah "$VP_SQL_FILE"  | cut -d ' ' -f 5)
  time mysql $VP_DB --force -e "SET unique_checks=0; SET foreign_key_checks=0; SET autocommit=0; source $VP_SQL_FILE ; commit;"
  VP_ERR="$?"
  if [[ "$VP_ERR" -ne "0" ]] ; then
    echo "*** IMPORT ERROR: MySQL returned errno $VP_ERR for $VP_SQL_FILE"
    mv "$VP_SQL_FILE" error/
  else
    mv "$VP_SQL_FILE" done/
    VP_SQL_ROWS=$(mysql $VP_DB -ss -N -e "SELECT COUNT(*) from $VP_TABLE")
    if [[ "$VP_SQL_ROWS" -ne "$VP_IMPORT_INSERTS" ]] ; then
        printf "*** WARNING: Finished processing %s - %d rows in table, %d insert statements in %s.\n" "$VP_TABLE" "$VP_SQL_ROWS" "$VP_IMPORT_INSERTS" "$VP_SQL_FILE"
    else
        printf "Finished processing %s - %d rows in table (expecting %d).\n" "$VP_TABLE" "$VP_SQL_ROWS" "$VP_IMPORT_INSERTS"
    fi
  fi
  echo ""
done
echo "Make sure to delete the 'jetpack_options', 'vaultpress', and related WP options if the restore is happening on a different (eg, QA) server"
for foo in jetpack_options vaultpress _vp_signatures _vp_config_option_name_ignore _vp_config_post_meta_name_ignore vaultpress_service_ips_external_cidr jetpack_protect_key ; do
  echo "wp option delete $foo"
done

printf "\n or you can use a loop: \n"

echo 'for foo in jetpack_options vaultpress _vp_signatures _vp_config_option_name_ignore _vp_config_post_meta_name_ignore vaultpress_service_ips_external_cidr jetpack_protect_key ; do'
echo '  wp option delete "$foo"'
echo 'done'

以上是关于sh 导入未使用--opt或--extended-insert转储的单个MySQL .sql文件(如来自VaultPress转储。显示一些* very * basic的主要内容,如果未能解决你的问题,请参考以下文章

CSS文件未在laravel刀片视图中导入

CATALINA_OPTS和 JAVA_OPTS区别

ASP.NET 核心 CORS 标头未显示

du 估算文件磁盘空间使用情况

未定义或导入预定义类型“System.ValueTuple´2”

即时窗口中的动态导致“Microsoft.CSharp.RuntimeBinder.Binder”未定义或导入错误