Production Environment backup shell script

Source: Internet
Author: User

Batch backup of multiple databases

#! /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/mongodbname.#timepoint. SQL .gz

Done

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


Website directory backup

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


Directory rsync Synchronization(Install and configure rsync first)

#! /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 log Cutting

#! /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. pid'

This article is from the "linuxart" blog, please be sure to keep this source http://linuxart.blog.51cto.com/686203/1212470

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.