<html>
<body>
<a href="eternalcenter-2021.txt" download="eternalcenter.txt">Download test.txt</a>
</body>
</html>
(补充:这里以下载和此 html 文件在同目录下的 eternalcenter-2021.txt 文件,且下载命名为 eternalcenter.txt 为例)
<html>
<body>
<a href="eternalcenter-2021.txt" download="eternalcenter.txt">Download test.txt</a>
</body>
</html>
(补充:这里以下载和此 html 文件在同目录下的 eternalcenter-2021.txt 文件,且下载命名为 eternalcenter.txt 为例)
作者:朱明宇
名称:将远程服务器的 LNMP 备份还原到本地
作用:将远程服务器的 LNMP 备份还原到本地
1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本
1. tmppath=/cache #本地用于备份数据的目录
2. webpath=/usr/share/nginx/html #本地用于存放网站文件的目录
3. key=”~/.ssh/eternalcenter” #本地私钥
4. tmpfile=tmpfile.txt #用于存储记录的文件
5. dbuser=ec #网站在数据库中的用户
6. ruser=eternalcenter #用于远程服务器的用户
7. rhost=eternalcenter.com #远程服务器
8. rcache=”/cache” #远程服务器用于备份数据的目录
1. 本地需要已经搭建好 LNMP 平台
2. 用于远程服务器的用户,需要能免密钥 ssh 远程服务器,且对于本地用于备份数据的目录和远程服务器用于备份数据的目录拥有读和执行的权限
3. 执行此脚本的用户需要有 sudo systemctl 权限
4. 脚本 ”mysql -uroot -p’eternalcenter’ ec < $sqlfile“ 中 “eternalcenter“ 是指本地 MariaDB 数据库 root 用户的密码,需要修改成本地 MariaDB 数据库的 root 用户密码
#!/bin/bash
####################### Separator ########################
tmppath=/cache
webpath=/usr/share/nginx/html
key="~/.ssh/eternalcenter"
tmpfile=tmpfile.txt
dbuser=ec
ruser=eternalcenter
rhost=eternalcenter.com
rcache="/cache"
####################### Separator ########################
nowdirectory=`pwd`
a=`ssh -i $key $ruser@$rhost "du -s $rcache" | awk '{print $1}'`
sleep 10
b=`ssh -i $key $ruser@$rhost "du -s $rcache" | awk '{print $1}'`
if [ $a -eq 0 ];then
echo "no file"
fi
if [ $a -ne $b ];then
echo "backup is running now"
exit
fi
c=0
if [ -f $tmpfile ];then
c=`cat $tmpfile`
fi
if [ $a -eq $c ];then
echo "no new file"
exit
fi
echo $a > $tmpfile
sqlfile=`ssh -i $key $ruser@$rhost "ls -rtlh $rcache | grep sql | tail -1" | awk '{print $NF}'`
if [ $? -eq 0 ]; then
tarfile=`ssh -i $key $ruser@$rhost "ls -rtlh $rcache | grep tar | tail -1" | awk '{print $NF}'`
if [ $? -eq 0 ]; then
rm -rf $tmppath/*
mkdir $tmppatch &> /dev/null
echo $sqlfile
echo $tarfile
scp -i $key $ruser@$rhost:$rcache/$sqlfile $tmppath
scp -i $key $ruser@$rhost:$rcache/$tarfile $tmppath
# sudo systemctl stop nginx
# sudo systemctl stop php-fpm
cd $tmppath
mysql -uroot -p'eternalcenter' -e "drop database $dbuser;"
mysql -uroot -p'eternalcenter' -e "create database $dbuser;"
mysql -uroot -p'eternalcenter' -e "grant all privileges on $dbuser.* to \"$dbuser\"@\"localhost\";"
mysql -uroot -p'eternalcenter' ec < $sqlfile
sudo rm -rf $webpath/*
sudo tar -zxvf $tarfile -C $webpath/ &> /dev/null
# sudo systemctl start nginx
# sudo systemctl start php-fpm
cd $nowdirectory
fi
fi
作者:朱明宇
名称:LNMP 没运行则重启系统
作用:LNMP 没运行则重启系统
1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本
#!/bin/bash
systemctl status nginx | grep 'active (running)'
if [ $? -ne 0 ];then
/usr/sbin/reboot
fi
systemctl status mariadb | grep 'active (running)'
if [ $? -ne 0 ];then
/usr/sbin/reboot
fi
systemctl status php-fpm | grep 'active (running)'
if [ $? -ne 0 ];then
/usr/sbin/reboot
fi
# ssh -q -t -t -o StrictHostKeyChecking=no -o ConnectTimeout=5 -l eternalcenter eternalcenter.com
(
补充:这里以
1) 安静模式
2) 打开新端口的模式
3) 不检查服务器记录
4) 超时时间为 5 秒
5) 通过 eternalcenter 用户
6) 登录 eternalcenter.com 服务器
为例
)
# ssh -X eternalcenter@eternalcenter.com
(
补充:这里以
1) 带图形的模式
2) 通过 eternalcenter 用户
3) 登录 eternalcenter.com 服务器
为例
)
# cat test.txt
a1
b2
c3
a1
d2
e3
a1
c3
# sort test.txt | uniq
a1
b2
c3
d2
e3
(补充:这里以给 test.txt 文件里的字符为例)
# cat test.txt
a1
b2
c3
a1
d2
e3
a1
c3
# sort test.txt | uniq -d
a1
c3
(补充:这里以只显示 test.txt 文件里重复的行为例)
# cat test.txt
a1
b2
c3
a1
d2
e3
a1
c3
# sort test.txt | uniq -u
b2
d2
e3
(补充:这里以只显示 test.txt 文件里不重复的行为例)
# cat test.txt
a1
b2
c3
a1
d2
e3
a1
c3
# sort test.txt | uniq -c
3 a1
1 b2
2 c3
1 d2
1 e3
(补充:这里以显示 test.txt 每个字符出现的次数为例)