How to regularly back up mysql and regularly cut nginx access log

Source: Internet
Author: User

Regular mysql backup
Put/etc/cron. hourly/
Copy codeThe Code is 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 days 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-mongodate.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 cut nginx access. log, only keep records 3 days ago
Put/etc/cron. hourly/
Copy codeThe Code is 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 days 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. 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.