脚本备份Shell

/ 0评 / 0

Nginx备份脚本

#!/bin/bash
#function:cut nginx log files for lnmp v0.5 and v0.6
#author: https://lnmp.org

########
#配置项#
########
#set the path to nginx log files(nginx日志目录)
log_files_path="/home/wwwlogs/"
#nginx日志目录以年月日存放即(nginx日志存放目录/2017/09.....)
log_files_dir=${log_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
#set nginx log files you want to cut(nginx日志文件名称,满足多个名称,每个名称之间用空格隔开)
log_files_name=(nsxsg_access)
#set the path to nginx.(nginx启动文件)
nginx_sbin="/usr/local/nginx/sbin/nginx"
#Set how long you want to save(日志保存天数)
save_days=120

############################################
#Please do not modify the following script #
############################################
mkdir -p $log_files_dir
log_files_num=${#log_files_name[@]}
#cut nginx log files
for((i=0;i<$log_files_num;i++));do
mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").log
done
#delete 30 days ago nginx log files
find $log_files_path -mtime +$save_days -exec rm -rf {} \;
$nginx_sbin -s reload

项目备份脚本

#!/bin/bash
#author:1072966772@qq.com
#time:2017-09-29
#项目备份脚本

##############
# 配置项内容 #
##############
# set the path to project 项目的根目录
project_path="/home/wwwroot"
# 存放备份文件的目录
backup_path="/data/backup"
# 需要备份的项目名称
project_name="wordpress"
# 备份文件名
backup_name="wordpress"
# set how long you want to save
save_days=30

###########################################
#Please do not modify the following script#
###########################################
cd ${project_path}
/bin/tar -zcvpf ${backup_path}/${backup_name}_$(date +%Y%m%d).tar.gz ${project_name}
find ${backup_path} -type f -mtime +${save_days} -exec rm -rf {} \;

数据库备份脚本

#!/bin/bash
#author:1072966772@qq.com
#time:2017-09-29
#数据库备份脚本

##############
# 配置项内容 #
##############
# 存放数据库备份文件的目录
backup_path="/data/backup/databasebackup"
# 数据库主机
mysql_host="localhost"
# 数据库用户
mysql_user="root"
# 数据库密码
mysql_pwd="123456"
# 数据库名称
mysql_name="wordpress"
# 备份文件名
backup_name="wpdatabase"
# set how long you want to save
save_days=30

###########################################
#Please do not modify the following script#
###########################################
cd ${backup_path}
/usr/bin/mysqldump -h ${mysql_host} -u ${mysql_user} --password=${mysql_pwd}  ${mysql_name} > ${backup_path}/${backup_name}_$(date +%Y%m%d).sql
/bin/gzip -1 ${backup_name}_$(date +%Y%m%d).sql
find ${backup_path} -type f -mtime +${save_days} -exec rm -rf {} \;

发表评论

电子邮件地址不会被公开。 必填项已用*标注