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