Linux shell simple implementation of automatic database backup

Source: Internet
Author: User

Take the CentOS system as an example to realize automatic database backup.
1. Write a shell:

1
2
#! /bin/bash
Mysqldump -cp --user=root --password=' 123 ' dbName | gzip > ~/db/dbname -'date +%y%m%d%H '. SQL. GZ ;

In the shell above, root is the user name used when backing up, 123 is the password, and dbname is the name of the database to be backed up.
Put this file in the user directory, save the path is: ~/db/dbbackup.sh

Add execute permissions after saving:
chmod a+x ~/db/dbbackup.sh

Then execute this file to see if the use is normal and there is no backup file generated under ~/db/.

2, using crontab timed call. Crontab Tutorials:
http://blog.csdn.net/richerg85/article/details/17887879
Http://www.jb51.net/article/26645.htm

Use the CRONTAB-E command, edit the crontab file, and edit it the same way you use VI.
Add a new line:
XX 2 * * * ~/db/dbbackup.sh
Indicates that the ~/db/dbbackup.sh file is executed 2:00 every day.
Once saved, the crontab-l sees new rows of data added.

Over, every day the system will call this script to back up the data.

Linux shell simple implementation of automatic database backup

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.