Ubuntu Server uses the automysqlbackup script

Source: Internet
Author: User

Ubuntu Server used the automysqlbackup script. The Server was accidentally shut down yesterday, causing damage to the database file in the development environment. So I remembered the automatic backup task. I originally planned to write a script using Mysqldump to schedule the task, however, for the sake of laziness, I found it on the Internet and found automysqlbackup. Reading comments is not bad, and it is also implemented by shell scripts. In the spirit of not repeating the wheel, download and use it. Address: http://sourceforge.net/projects/automysqlbackup/ The new automysqlbackup-v3.0_rc6.tar.gz is selected. The installation is very simple and troublesome. It is followed by configuring the mail client and a small bug in the script. 1, in any directory, decompress the file package tar-xzf automysqlbackup-v3.0_rc6.tar.gz 2, for the sake of convenience, cut a permission sudo su-3, installation (if there is no special requirements for the path, you can press Enter when prompted ). /install. sh Default Configuration File Location:/etc/automysqlbackup default sh File Location:/usr/local/bin 4. After the configuration file is modified, two configuration files are installed by default. One is automysqlbackup. conf, and myserver. conf. In fact, I can see from the installation script that the two files are copied and redundant. I guess the purpose is to prevent the second installation or misoperation and overwrite the configured configuration file. However, it seems that the script logic is not very useful, because it is reinstalled, so the two files will be overwritten. However, if the automysqlbackup. conf configuration has a value, a prompt is displayed. Still, in order to be lazy, you can directly modify automysqlbackup. conf. After all, this is the default configuration. When sh is executed, no parameters are required. Note the following configuration items: (the configuration file contains the default value. If you do not need to change the value, you can directly maintain the commented state.) # Username to access the MySQL server e.g. dbuser (database connection username) CONFIG_mysql_dump_username = 'root' # Password to access the MySQL server e.g. password (database connection password) CONFIG_mysql_dump_password = 'Password' # "Friendly" host name of MySQL server to be used in email log # if unset or empty (default) will use CONFIG_mysql_dump_host instead Localhost) CONFIG_mysql_dump_host_friendly = 'databasealias' # Backup directory location e. g/backups (needless to say, top priority, backup path) CONFIG_backup_dir = '/srv/Backup/mysql' # List of databases for Daily/Weekly backup e.g. ('db1' 'db2 ''db3 '...) # set to (), I. e. empty, if you want to backup all databases (name of the database that requires daily backup and weekly backup) CONFIG_db_names = ('testdb') # List of databases for Monthly Backups. # set to (), I. e. empty, I F you want to backup all databases (name of the database that requires monthly backup) CONFIG_db_month_names = ('testdb') # Which day do you want monthly backups? (01 to 31) (monthly backup date. If the configured date is later than the maximum date of the current month, it will be executed on the last day of the current month) # If the chosen day is greater than the last day of the month, it will be done # on the last day of the month. # Set to 0 to disable monthly backups. # CONFIG_do_monthly = "01" # Which day do you want weekly backups? (1 to 7 where 1 is Monday) (weekly backup occurs on the day of the week) # Set to 0 to disable weekly backups. # CONFIG_do_weekly = "5" # Set rotation of daily backups. VALUE * 24 hours # If you want to keep only today's backups, you cocould choose 1, I. e. everything older than 24 hours will be removed. (How many days does the daily backup file keep?) CONFIG_rotation_daily = 7 # Set rotation for weekly backups. VALUE * 24 hours (how many days the weekly backup file is retained) # CONFIG_rotation_weekly = 35 # Set rotation for m Onthly backups. VALUE * 24 hours (How many days a monthly backup file is retained) # CONFIG_rotation_monthly = 150 # Use ssl encryption with mysqldump? (Do you want to use ssl? If it is local, enable ssl? Remotely) CONFIG_mysql_dump_usessl = 'no' # What wocould you like to be mailed to you? (Do you Want to automatically send you an email when the backup is complete ?) #-Log: send only log file (The Mail content only contains logs) #-files: send log file and SQL files as attachments (see docs) (except for log errors, back up the compressed package) #-stdout: will simply output the log to the screen if run manually. (The table email is displayed on the screen. The problem is, who can watch the server screen all day long ?) #-Quiet: Only send logs if an error occurs to the MAILADDR. (if an error occurs, send a message.) CONFIG_mailcontent = 'files' # Email Address to send mail? (User@domain.com) (mail address, needless to say) CONFIG_mail_address = 'nc @ na.com '5, first change the script of the small bug .. However, if the mail and mutt on your server are complete, ignore this step. Vi/usr/local/bin/automysqlbackup to row 1026, set: if [["x $ CONFIG_mailcontent" = 'xlog' | "x $ CONFIG_mailcontent" = 'xquiet ']; then dependencies = ("$ {dependencies [@]}" 'mail') elif [["x $ CONFIG_mailcontent" = 'xfiles']; then dependencies = ("$ {dependencies [@]}" 'mail') if ["x $ CONFIG_mail_use_uuencoded_attachments "! = 'Xyes']; then dependencies = ("$ {dependencies [@]}" 'mutt') fi changed to: if [["x $ CONFIG_mail_use_uuencoded_attachments "! = 'Xyes']; then if [["x $ CONFIG_mailcontent" = 'xlog' | "x $ CONFIG_mailcontent" = 'xquiet ']; then dependencies = ("$ {dependencies [@]}" 'mutt') elif [["x $ CONFIG_mailcontent" = 'xfiles']; then dependencies = ("$ {dependencies [@]}" 'mutt ') fi else if [["x $ CONFIG_mailcontent" = 'xlog' | "x $ CONFIG_mailcontent" = 'xquiet ']; then dependencies = ("$ {dependencies [@]}" 'mail') elif [["x $ CONFIG_mai Lcontent "= 'xfiles']; then dependencies = (" $ {dependencies [@]} "'mail ') fi 6. When installing the mail client mutt + msmtp apt-get install mutt, the system will automatically install postfix as the mail server. The problem is that this is too big, out of a clean mind, I took the initiative to kill it. After all, the small and exquisite msmtp is waiting for me. (Depending on your needs and preferences) apt-get remove postfix-purgeapt-get autoremove-purge install msmtp apt-get install msmtp after installation is complete. 7. Add the following at the top of vi/etc/Muttrc configuration on the mail client: # My Mail Settingset sendmail = "/usr/bin/msmtp" set use_from = yesset realname = "Mail address alias" set from = username@126.comset envelope_from = yes # do not retain sent's local archive set copy = no and then ~ Directory, create a. msmtprc cd ~ Vi. msmtprc with the following content: account mailbox alias host smtp.126.comfrom username@126.comauth plainuser usernamepassword pwdlogfile ~ /. Msmtp. log because the plaintext password is used here, we recommend that you modify the 600 stream and add a log file chmod 600. msmtprctouch ~ /. If msmtp. log is complete, try sending emails instead of sending them. Echo "hello" | mutt-s? "If the testmail@126.com test is successful, just run the backup script to check it 8, install a few of my server on the wood command: apt-get install paxapt-get install pigz 9. If no environment variable is set in mysql, add a shortcut, set the environment variable vi/etc/profile to add export PATH = $ PATH:/usr/local/mysql/bin at the last position to save, refresh and check source/etc/profile echo $ PATH 10. Start the backup script, remember to first create the backup path mkdir/srv/backupmkdir/srv/backup/mysqlautomysqlbackup. If there is no problem, you will see the backup file path below and automatically create several directories for you: daily fullschema latest monthly status tmp w Eekly and open daily, there should be the file you just backed up. Check the mail again. All the emails are OK, so configure a scheduled task to complete. 11. Configure the scheduled task crontab-l to check whether there are currently any tasks ~ Create a configuration file cd ~ Vi root-crontab adds 30 23 ***/usr/local/bin/automysqlbackup to indicate every day, run the backup script automatically and add it to the scheduled task to run crontab-u root-crontab...

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.