昨天翻看了下别人写的一键脚本,引起了我的好奇,于是看了下lnmp一键脚本,写了个博客搬家的脚本,因为是根据自己服务器写的,所以不适用于其他服务器使用,不过原理都是一样,代码也很简单,大家可以改改,用于自己的服务器。
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
read -t 30 -p "Whether to do blog migration ? yes or no :" isMove
read -t 30 -p "select nginx conf ? 1 or https com | 2 or com | 3 or top :" snginx
if [ "${isMove}" = "yes" ]; then
mkdir /home/www
mkdir /home/wwwlogs
mkdir /home/wwwroot
cp $basepath/wwwroot.zip /home/wwwroot
cd /home/wwwroot/
unzip wwwroot.zip
cp $basepath/html.tar.gz /home/www
cd /home/www/
tar zxvf html.tar.gz
cp $basepath/wordpress.tar.gz /home/www
cd /home/www/
tar zxvf wordpress.tar.gz
cp $basepath/typecho.tar.gz /home/www
cd /home/www/
tar zxvf typecho.tar.gz
cd $basepath
#mysql -hlocalhost -P3306 -uroot -ppasswd -e "create database IF NOT EXISTS wordpress DEFAULT CHARACTER SET utf8mb4 -- UTF-8 Unicode COLLATE utf8mb4_general_ci"
#mysql -hlocalhost -P3306 -uroot -ppasswd -e "use wordpress"
#mysql -hlocalhost -P3306 -uroot -ppasswd -e "source wordpress.sql"
#echo "use wordpress;" | mysql -uroot -ppasswd
#echo "source wordpress.sql;" | mysql -uroot -ppasswd
#mysql -hlocalhost -P3306 -uroot -ppasswd -e "set character set utf8mb4"
#mysql -hlocalhost -uroot -ppasswd -Dwordpress < wordpress.sql
mysql -hlocalhost -uroot -ppasswd < data.sql
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx_copy.conf
if [ "${snginx}" = "1" ]; then
cp nginx_https/* /usr/local/nginx/conf/vhost
mkdir /home/ssl
cp nginx_https/key/* /home/ssl
elif [ "${snginx}" = "2" ]; then
cp nginx_com/* /usr/local/nginx/conf/vhost
elif [ "${snginx}" = "3" ]; then
cp nginx_top/* /usr/local/nginx/conf/vhost
else
echo "nginx conf select error,so not copy nginx conf..."
fi
mv /usr/local/nginx/conf/vhost/nginx.conf /usr/local/nginx/conf/nginx.conf
service nginx restart
netstat -ntpl
echo $basepath
echo "move blog ok !"
fi
将脚本和需要的文件打成一个压缩包(本地),然后执行命令:
unzip blog.zip && cd blog && chmod +x blog.sh && ./blog.sh
将脚本和需要的文件打成一个压缩包(服务器),然后执行命令:
wget http://107.189.XXX.XXX:8000/blog.zip && unzip blog.zip && cd blog && chmod +x blog.sh && ./blog.sh
服务器开启文件服务:
python -m SimpleHTTPServer 8000
mysql导出数据:
//导出所有数据库
mysqldump -uroot -proot --all-databases > /home/all.sql
//导出单个数据库
mysqldump -uroot -ppasswd -c --default-character-set=utf8 --databases dbname > dbname.sql
//导出指定数据库
mysqldump -uroot -ppasswd -c --default-character-set=utf8 --databases dbname1 dbname2 dbname3 > dbname.sql
//导出指定条件的数据
mysqldump -uroot -ppasswd -c --default-character-set=utf8 dbname tablename --where="age>20"> dbname.sql
网友评论