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:
- shell> mkdir /etc/automysqlbackup
- shell> sed -n '/START CFG/,/END CFG/s/^/s*//p' automysqlbackup.sh /
- > /etc/automysqlbackup/automysqlbackup.conf
It consists of two parts: basic options and advanced options. The basic options are set as follows:
- # Username to access the MySQL server e.g. dbuser
- USERNAME=debian
-
- # Password to access the MySQL server e.g. password
- PASSWORD=
-
- # Host name (or IP address) of MySQL server e.g localhost
- DBHOST=localhost
-
- # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
- DBNAMES="all"
-
- # Backup directory location e.g /backups
- BACKUPDIR="/srv/backup/db"
-
- # Mail setup
- # What would you like to be mailed to you?
- # - log : send only log file
- # - files : send log file and sql files as attachments (see docs)
- # - stdout : will simply output the log to the screen if run manually.
- # - quiet : Only send logs if an error occurs to the MAILADDR.
- 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:
- shell> cp /path/to/automysqlbackup.sh /etc/cron.daily/automysqlbackup
- 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:
- 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