Lightweight MySQL backup solution: AutoMySQLBackup_MySQL

Source: Internet
Author: User
Tags mysql backup
Lightweight MySQL backup solution: AutoMySQLBackup bitsCN.com

There is a saying: "The best choice is not necessarily the best choice !』. AutoMySQLBackup is not superior, but as a lightweight MySQL backup solution, it is definitely worth trying for some mini projects.

AutoMySQLBackup is easy to use and is a fast food tool. the procedure is as follows:

Download AutoMySQLBackup, which is a shell script named similar to automysqlbackup. sh.

Create a configuration file. the default content is the section between "start cfg" and "end cfg" in the shell script:

 
 
  1. shell> mkdir /etc/automysqlbackup
  2. shell> sed -n '/START CFG/,/END CFG/s/^/s*//p' automysqlbackup.sh /
  3. > /etc/automysqlbackup/automysqlbackup.conf

It consists of two parts: basic options and advanced options. The basic options are set as follows:

 
 
  1. # Username to access the MySQL server e.g. dbuser
  2. USERNAME=debian
  3. # Password to access the MySQL server e.g. password
  4. PASSWORD=
  5. # Host name (or IP address) of MySQL server e.g localhost
  6. DBHOST=localhost
  7. # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
  8. DBNAMES="all"
  9. # Backup directory location e.g /backups
  10. BACKUPDIR="/srv/backup/db"
  11. # Mail setup
  12. # What would you like to be mailed to you?
  13. # - log : send only log file
  14. # - files : send log file and sql files as attachments (see docs)
  15. # - stdout : will simply output the log to the screen if run manually.
  16. # - quiet : Only send logs if an error occurs to the MAILADDR.
  17. MAILCONTENT="log"

Step-by-step setting of USERNAME, PASSWORD, DBNAMES, and BACKUPDIR. because the configuration file contains sensitive information such as the account and PASSWORD, you may need to consider the permissions. In addition, you need to note the mail-related settings, as a lightweight MySQL backup solution, this feature is a bit superfluous. we recommend that you disable it (stdout ).

Everything is ready for use, and you only need to set up scheduled tasks, such as setting daily backup:

 
 
  1. shell> cp /path/to/automysqlbackup.sh /etc/cron.daily/automysqlbackup
  2. shell> chmod +x /etc/cron.daily/automysqlbackup

In this way, we will archive the files by day, week, or month in the backup directory you set.

Tip: Daily backup may occupy a large amount of disk space. to avoid disk space depletion, it is necessary to regularly delete old backup files, such as deleting backup files N days ago, you can use a shell command like the following:

 
 
  1. shell> find /path/to/backup/dir -type f -mtime +N -print0 | xargs -0 rm -f

In addition, when using mtime, the meaning of N/-N/+ N is confusing. you can refer to the relevant documentation before using it.

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.