>  기사  >  백엔드 개발  >  Linux system_php 팁을 한 번 클릭하여 WordPress를 다시 설치하는 스크립트 예

Linux system_php 팁을 한 번 클릭하여 WordPress를 다시 설치하는 스크립트 예

WBOY
WBOY원래의
2016-05-16 20:12:261464검색

수시로 웹사이트를 마이그레이션해야 할 수도 있고, 오작동으로 인해 데이터베이스가 유실될 수도 있으므로, 시간을 절약하기 위해 WordPress 원클릭 재설치 스크립트를 작성했습니다.

대략적인 개요를 작성하고 있을 뿐입니다. 필요에 따라 스크립트를 수정할 수 있습니다.

사용 조건:

저는 주로 웹사이트 마이그레이션과 전체 재설치에 이 스크립트를 사용합니다. 즉, 내 작업은 데이터베이스 및 기타 작업만 가져옵니다. 아래 스크립트에서는 해당 WordPress 테마 및 플러그인 파일을 사용하지 않았습니다. 필요한 경우 직접 변경할 수 있습니다(아래 언급).

다음 서류를 준비하세요.

  • 원본 WordPress 구성 파일 wp-config.php
  • 원본 워드프레스 데이터베이스 백업 파일
  • 시스템에 wget이 설치되어 있습니다(대부분 기본적으로 설치되어 있음)
#!bin/sh
#vps wordpress一键重新安装脚本
#global setting
USERNAME="root"  #数据库用户名
PASSWORD="ksharpdabu.info"  #数据库密码

DBNAME="wordpress"     #要导入的数据库名
BACKUPSQL="/home/ksharpdabu.sql"      #备份的sql文件绝对路径

OLD_WP-CONFIG="/home/wp-config.php"  #以前保存到wp-config.php文件的绝对路径
#setting end!!

WEBROOT="/home/wwwroot" #网站根目录http://www.dabu.info/?p=4329

echo "###################################################################\n"
echo "please backup your website data when you run this shell script!!!!\n"
echo "please backup your website data when you run this shell script!!!!\n"
echo "please backup your website data when you run this shell script!!!!\n"
echo "###################################################################\n"

  get_char()     #这一段的代码其实的功能就是让用户输入任意键以继续执行脚本,是常用的代码段
  {
  SAVEDSTTY=`stty -g`
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2> /dev/null
  stty -raw
  stty echo
  stty $SAVEDSTTY
  }
  echo ""
  echo "Press any key to start..."
  char=`get_char`

create_db="create database IF NOT EXISTS ${DBNAME}"
mysql -u${USERNAME} -p${PASSWORD} -e "${create_db}" #创建名为wordpress的数据库,如果不存在http://www.dabu.info/?p=4329

wget -c http:#cn.wordpress.org/wordpress-3.7.1-zh_CN.zip  #下载wordpress网站程序
unzip wordpress-3.7.1-zh_CN.zip  #解压wordpress程序
cd wordpress  #切换到解压后的wordpress目录
cp ./*  ${WEBROOT}  #将网站程序复制到网站根目录
\cp ${OLD_WP-CONFIG} ${WEBROOT}   #将原先的wordpress的配置文件wp-config.php放到网站根目录
mysql -u${USERNAME} -p${PASSWORD} ${DBNAME} <${BACKUPSQL}   #导入你备份的数据库到wordpress数据库里

echo "###################################################################\n"
echo "please view you blog to check the success or failure.\n"
echo "view my blog:http://www.dabu.info/ if you have question!!\n"
echo "###################################################################\n"
 
#!bin/sh
#vps wordpress一键重新安装脚本
#global setting
USERNAME="root"  #数据库用户名
PASSWORD="ksharpdabu.info"  #数据库密码
 
DBNAME="wordpress"     #要导入的数据库名
BACKUPSQL="/home/ksharpdabu.sql"      #备份的sql文件绝对路径
 
OLD_WP-CONFIG="/home/wp-config.php"  #以前保存到wp-config.php文件的绝对路径
#setting end!!
 
WEBROOT="/home/wwwroot" #网站根目录http://www.dabu.info/&#63;p=4329
 
echo "###################################################################\n"
echo "please backup your website data when you run this shell script!!!!\n"
echo "please backup your website data when you run this shell script!!!!\n"
echo "please backup your website data when you run this shell script!!!!\n"
echo "###################################################################\n"
 
  get_char()     #这一段的代码其实的功能就是让用户输入任意键以继续执行脚本,是常用的代码段
  {
  SAVEDSTTY=`stty -g`
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2> /dev/null
  stty -raw
  stty echo
  stty $SAVEDSTTY
  }
  echo ""
  echo "Press any key to start..."
  char=`get_char`
 
create_db="create database IF NOT EXISTS ${DBNAME}"
mysql -u${USERNAME} -p${PASSWORD} -e "${create_db}" #创建名为wordpress的数据库,如果不存在http://www.dabu.info/&#63;p=4329
 
wget -c http:#cn.wordpress.org/wordpress-3.7.1-zh_CN.zip  #下载wordpress网站程序
unzip wordpress-3.7.1-zh_CN.zip  #解压wordpress程序
cd wordpress  #切换到解压后的wordpress目录
cp ./*  ${WEBROOT}  #将网站程序复制到网站根目录
\cp ${OLD_WP-CONFIG} ${WEBROOT}   #将原先的wordpress的配置文件wp-config.php放到网站根目录
mysql -u${USERNAME} -p${PASSWORD} ${DBNAME} <${BACKUPSQL}   #导入你备份的数据库到wordpress数据库里
 
echo "###################################################################\n"
echo "please view you blog to check the success or failure.\n"
echo "view my blog:http://www.dabu.info/ if you have question!!\n"
echo "###################################################################\n"

Ps: 필요에 따라 스크립트를 수정하세요

1. 데이터베이스뿐만 아니라 웹사이트의 플러그인 및 기타 파일도 백업한 경우 다음을 직접 수행할 수 있습니다.

wget -c http:#cn.wordpress.org/wordpress-3.7.1-zh_CN.zip  #下载wordpress网站程序
unzip wordpress-3.7.1-zh_CN.zip  #解压wordpress程序
cd wordpress  #切换到解压后的wordpress目录
cp ./*  /home/wwwroot/  #将网站程序复制到网站根目录
\cp ${OLD_WP-CONFIG} ${WEBROOT}
 
wget -c http:#cn.wordpress.org/wordpress-3.7.1-zh_CN.zip  #下载wordpress网站程序
unzip wordpress-3.7.1-zh_CN.zip  #解压wordpress程序
cd wordpress  #切换到解压后的wordpress目录
cp ./*  /home/wwwroot/  #将网站程序复制到网站根目录
\cp ${OLD_WP-CONFIG} ${WEBROOT}

삭제하고 웹사이트의 모든 백업 파일의 압축해제 및 복사 명령으로 대체합니다.

전체 /wwwroot 디렉토리를 all.tar.gz로 백업했다고 가정합니다

다음과 같이 작성하세요.

tar -zvxf all.tar.gz  /home

2. 그냥 재설치하는 경우

그런 다음 원본 WordPress 데이터베이스나 테이블을 삭제하는 명령을 추가해야 합니다.

drop database

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.