导读 | 在计算机科学中,Shell俗称壳(用来区别于核),是指“为使用者提供操作界面”的软件(命令解析器)。它类似于DOS下的command.com和后来的cmd.exe。它接收用户命令,然后调用相应的应用程序。 |
线上的配置文件以及应用配置文件是非常有必要进行备份的,不排除能够上服务器的朋友没有备份就直接修改出错或者其他人员误操作的情况。现在花了十分钟简单写了一个备份脚本,另外也可以自己加上其他备份脚本进去。
虽简单,但有了这个东西还是放心了不少,再也不用担心原始配置文件找不到了。
#!/bin/bash # bakup configfile for system 、nginx 、 php 、ELK and so on #author:21yunwei #date:2017.4.22 time=`date +%Y%m%d` LOGFILE=/backup/configbak/configbak.log [ ! -e /backup/configbak/elkbak/$time ] && mkdir -p /backup/configbak/elkbak/$time [ ! -e /backup/configbak/nginxbak/$time ] && mkdir -p /backup/configbak/nginxbak/$time [ ! -e /backup/configbak/phpbak/$time ] && mkdir -p /backup/configbak/phpbak/$time [ ! -e /backup/configbak/etcbak/$time ] && mkdir -p /backup/configbak/etcbak/$time function etcbak() { tar zcf /backup/configbak/etcbak/$time/etc$time.tar.gz /etc/* } function nginxbak() { cp -rfpu /usr/local/nginx/conf/* /backup/configbak/nginxbak/$time/ } function phpbak() { cp -rfpu /usr/local/php/etc/* /backup/configbak/phpbak/$time/ } function elkbak() { cd /backup/configbak/elkbak/$time && mkdir es logstash kibana cp -rfpu /usr/local/ELK/elasticsearch-5.1.1/config/* /backup/configbak/elkbak/$time/es/ cp -rfpu /usr/local/ELK/logstash-5.1.1/config/* /backup/configbak/elkbak/$time/logstash/ cp -rfpu /usr/local/ELK/kibana-5.1.1/config/* /backup/configbak/elkbak/$time/kibana/ } #start bak working: etcbak nginxbak phpbak elkbak #bakwork end ret=$? FINISHTIME=`date +%Y%m%d_%H%M%S` [ $ret -eq 0 ] && echo "configbak finished, time: $FINISHTIME">> $LOGFILE || echo "configbak failed,please check time:$FINISHTIME" >> $LOGFILE find /backup/configbak/ -type d -mtime +15 |xargs rm -rf
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/121800.html