MySQL Scheduled Backup

Source: Internet
Author: User
Tags gz file mysql backup
1. Create the path to save the backup file/mysqldata # mkdir/bak/mysqlbak2, create/usr/sbin/bakmysql file # vi/usr/sbin/bakmysql. SH3. Write the following script:
NOTE: If your MySQL password contains special characters, such! @ #, You need to add ''to the end of the-p parameter and put the password in'', '123! @#'
#!/bin/bash#Name:bakmysql.sh#This is a ShellScript For Auto DB Backup and Delete old Backupbackupdir=/bak/mysqlbaktime=` date +%Y%m%d%H `mysqldump --opt -h192.168.1.1 -uroot -p123456 dbname | gzip > $backupdir/mo$time.sql.gz#find $backupdir -name "mo*.sql.gz" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1

Script parsing: backupdir database backup path time point mysqldump: MySQL backup tool, -- opt-H remote backup operation, dbname: Database Name, Gzip: compressed into GZIP format. The last line is to ensure 5 latest backup files 4. Modify the scheduled task/etc/crontab # vi/etc/crontab and add 01 3 *** root/usr/sbin/bakmysql backup is performed at three o'clock every day. 5. Restart crond #/etc/rc. d/init. d/crond restart (RedHat) #/etc/init. d/cron restart (UBUNTU) is complete.

Manual recovery: First decompress the GZ file gunzip xxx.gz mysql-u root-p -- default-character-set = utf8
Use dbname
Source/root/XX. SQL
So esay, there won't be any point there.

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.