为了账号安全,请及时绑定邮箱和手机立即绑定

生产环境备份shell脚本

标签:
MySQL

批量备份多个数据库

#!/bin/bash

BACKUP_HOST="localhost"

BACKUP_USER="root"

BACKUP_PASS="123456"

BACKUP_DIR="/backup/mysql"

BACKUP_DBNAME="one two three"

COPIES=10

MYSQLDUMP="mysqldump"

TIMEPOINT=$(date +%Y-%m-%d)

MYSQLDUMP_OPTS="-h $BACKUP_HOST -u$BACKUP_USER -p$BACKUP_PASS"

umask 0077

test ! -d "$BACKUP_DIR" && mkdir -p "$BACKUP_DIR"

test ! -w $BACKUP_DIR && echo "Error: $BACKUP_DIR is un-writeable." && exit 0

for dbname in $BACKUP_DBNAME

do

   test ! -d "$BACKUP_DIR/$dbname" && mkdir -p "$BACKUP_DIR/$dbname"

   $MYSQLDUMP $MYSQLDUMP_OPTS $dbname | gzip > $BACKUP_DIR/$dbname/$dbname.$TIMEPOINT.sql.gz

done

find $BACKUP_DIR -type f -mtime +$COPIES -delete

网站目录备份

#!/bin/bash

BACKUP_DIR=/backup/website

WEBSITE_DIR=/www

TIMEPOINT=$(date +%Y-%m-%d)

COPIES=10

test ! -d "$BACKUP_DIR" && mkdir -p "$BACKUP_DIR"

test ! -w $BACKUP_DIR && echo "Error: $BACKUP_DIR is un-writeable." && exit 0

umask 0077

tar -zcf $BACKUP_DIR/www.$TIMEPOINT.tar.gz $WEBSITE_DIR

find $BACKUP_DIR -type f -mtime +$COPIES -delete

目录rsync同步(需先安装配置rsync)

#!/bin/sh

srcdir1=/www/example1.com

srcdir2=/www/example2.com

dstdir3=jszb@111.111.111.111::example1

dstdir4=jszb@222.222.222.222::example2

rsync -avz --delete --progress --password-file=/backup/bash/rsync.pas $srcdir1 $dstdir3 &

rsync -avz --delete --progress --password-file=/backup/bash/rsync.pas $srcdir2 $dstdir4 &

nginx日志切割

#!/bin/bash

logs_path="/usr/local/webserver/nginx/logs/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log

kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

©著作权归作者所有:来自51CTO博客作者amwytai的原创作品,如需转载,请注明出处,否则将追究法律责任

生产环境备份shell脚本shell


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消