导读 在计算机科学中,俗称壳(用来区别于核),是指“为使用者提供操作界面”的软件(解析器)。它类似于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

原文来自:

本文地址://q13zd.cn/simple-shell-backup-script.html编辑:向云艳,审核员:逄增宝

Linux命令大全:

Linux系统大全:

红帽认证RHCE考试心得: