在Linux系统下一键重新安装WordPress的脚本示例

yipeiwu_com5年前PHP代码库

网站可能时不时的要迁移,或者误操作,数据库没了,所以,我为了省时间,写了个wordpress一键重新安装的脚本。

我这只是写个大概的。大家可以根据自己的需要修改脚本。

使用条件:

我这个脚本主要用在网站迁移的情况下,完全重新安装时候用的。也就是说,我这个操作只导入数据库等操作。那些wordpress的主题和插件等文件我并没有用在下面的脚本,需要的话,你可以自己改(下面会提到)。

准备以下文件:

  •     原来wordpress的配置文件wp-config.php
  •     原来的wordpress数据库备份文件
  •     系统安装了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/?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"

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

相关文章

PHP 模拟登陆功能实例详解

PHP 模拟登陆功能实例详解

本文实例讲述了PHP 模拟登陆功能。分享给大家供大家参考,具体如下: 说明:该模拟登陆实例仅适用于没有验证码的模拟登陆实例 该程序基本功能是,模拟登陆高校图书馆网站,并获取读者信息和借书...

PHP中Session ID的实现原理实例分析

本文实例讲述了PHP中Session ID的实现原理。分享给大家供大家参考,具体如下: Session 的工作机制是:为每个访问者创建一个唯一的 id (UID),并基于这个 UID 来...

解决file_get_contents无法请求https连接的方法

错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to...

PHP 数据库 常见问题小结第1/3页

如果只有一种 方式使用数据库是正确的…… 您可以用很多的方式创建数据库设计、数据库访问和基于数据库的 PHP 业务逻辑代码,但最终一般以错误告终。本文说明了数据库设计和访问数据库的 PH...

php socket通信(tcp/udp)实例分析

本文实例讲述了php socket通信(tcp/udp)方法。分享给大家供大家参考,具体如下: 注意 1.在socket_bind的时候ip地址不能真回环地址如127.0.0.1 2.s...