Regular backup and deletion of MySQL database under Linux

Source: Internet
Author: User

1. connect to the server through the shell

Ssh-l root-p Port IP

After entering the password, enter the server

2, Create a folder where database backup data resides

mkdir/mysql/mysqldata_backup

3. Create and edit files

Vi/usr/sbin/bakmysql

The contents of the file are as follows:

fn = ' Date +%y%m%d '
Tar zcvf/mysql/mysqldata_backup/mysql$fn.tar.gz/mysql/data

Or

Mysqldump-uroot-ppassword/mysql/data/yourdatabase >/mysql/mysqldata_backup/mysql$fn.sql
Find $fn-name "mysql*.tar.gz"-type f-mtime +7-exec fm{}; >/dev/null 2>&1

Or

Find $fn-name "Mysql*.sql"-type f-mtime +7-exec fm{}; >/dev/null 2>&1

 

description:

/mysql/mysqldata_backup /Save the path for the backup data, msql$fn.tar.gz the name of the backup data according to the date number,/mysql/data the data path for the server database, yourdatabase the name of the database you want to back up ;
Note:

The First command is not a single quotation mark, but a symbol above the TAB key, and a space is required before and after date;
The second command has two methods, the first direct backup and compression of the database data source files, the second is to use the MySQL command mysqldump export database yourdatabase SQL file;
The third sentence is to delete the backup file 7 days ago, the file name corresponds to the second sentence.

4, Modify file Bakmysql property

chmod +x/usr/sbin/bakmysql

5, modify/etc/crontab

vi/etc/crontab

01 3 * * * root/usr/sbin/bakmysql
description:

01 3 is a daily 3:01 execution of the bakmysql file;

6, There are times when rebooting is not required, if the server has Crond service under the/etc/rc.d/init.d/path, you can choose to restart Crond

/etc/rc.d/init.d/crond restart


Regular backup and deletion of MySQL database under Linux

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.