Timed backup Mysql, timed to cut Nginx Access log method _mysql

Source: Internet
Author: User
Scheduled backup MySQL
Put/etc/cron.hourly/
Copy Code code as follows:

#!/bin/bash
Dump=/usr/local/webserver/mysql/bin/mysqldump
out_dir=/data1/backup/
Db_name= database name
db_user= Database User
db_pass= Database Password
#How much of the days of backup most
Days=3
#12 hours ago
mins=720
#Core of script
CD $OUT _dir
Date= ' Date +%y-%m-%d-%h '
Out_sql= "$DATE. SQL"
Tar_sql= "db-$DATE. tar.gz"
$DUMP--default-character-set=utf8--opt-u$db_user-p$db_pass $DB _name > $OUT _sql
TAR-CZF $TAR _sql./$OUT _sql
Rm-f $OUT _sql

Find./-name "db*"-type f-mmin + $MINS-exec rm {} \;
#find./-name "db*"-type f-mtime + $DAYS-exec rm {} \;
Exit 0;

Regular cutting Nginx Access.log, only 3 days before the record
Put/etc/cron.hourly/
Copy Code code as follows:

#!/bin/bash
# This script run at 00:00

# The Nginx logs path
#logs_path = "/usr/local/webserver/nginx/logs/"
Logs_path= "/data1/logs/"
#How much of the days of backup most
Days=3

#Core of script
CD $logs _path
Date= ' Date +%y-%m-%d-%h '
Src_file= "Access.log"
Tar_file= "access-$DATE. tar.gz"
Tar-czf $TAR _file $SRC _file
Rm-f $SRC _file

Find./-name "access-*"-type f-mtime + $DAYS-exec rm {} \;
KILL-USR1 ' Cat/usr/local/webserver/nginx/nginx.pid '
Exit 0;
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.