Mysql scheduled backup _ MySQL

Source: Internet
Author: User
Mysql regular backup operation bitsCN.com

Mysql scheduled backup

1. create the path to save the backup file/mysqldata

# Mkdir/bak/mysqlbak

2. create the/usr/sbin/bakmysql file.

# Vi/usr/sbin/bakmysql. sh

3. write the following script:

[Python]

#! /Bin/bash

# Name: bakmysql. sh

# This is a ShellScript For Auto DB Backup and Delete old Backup

Backupdir =/bak/mysqlbak

Time = 'date + % Y % m % d % H'

Mysqldump -- opt-h192.168.1.1-uroot-p123456 dbname | gzip> $ backupdir/mow.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 to gzip format.

The last line is to ensure five latest backup files

4. scheduled tasks

Modify/etc/crontab

# Vi/etc/crontab

Add

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

Indicates that a backup is performed at three o'clock every day.

5. restart crond.

#/Etc/rc. d/init. d/crond restart

Complete.

Manual recovery:

Decompress the gz file first

Gunzip xxx.gz

Mysql-u root-p -- default-character-set = utf8

Use dbname

Source/root/xx. SQL

Done

BitsCN.com

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.