生產環境備份shell指令碼

來源:互聯網
上載者:User

批量備份多個資料庫

#!/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`

本文出自 “linuxart” 部落格,請務必保留此出處http://linuxart.blog.51cto.com/686203/1212470

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.