Ubuntu Server uses the automysqlbackup script

Source: Internet
Author: User

The server was accidentally shut down yesterday, causing damage to the database file in the development environment. So I remembered how to perform automatic backup. I originally planned to use Mysqldump to write a script 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. decompress the package in any directory

 –xzf automysqlbackup-v3.0_rc6..gz

 

2. Cut Down permissions for convenience

  -

 

3. Installation (if there are no special requirements on the path, you can press Enter)

./.

Default Configuration File Location:/etc/automysqlbackup

Default sh File Location:/usr/local/bin

 

4. modify the configuration file

After the installation is complete, two configuration files are created by default, one is automysqlbackup. conf and the other is 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)

== host name of MySQL server to be used =/= Daily/Weekly Backup e.g. (   =(=( you want monthly backups? ( to  day of the month, it will be = you want weekly backups? ( to  where =*CONFIG_rotation_daily= weekly backups. VALUE*= monthly backups. VALUE*=?=?- log   : send only log - files : send log - stdout : will simply output the log to the screen - quiet : Only send logs =?=

 

5. Change the script bug first .. However, if the mail and mutt on your server are complete, ignore this step.

 /usr/local/bin/automysqlbackup

To line 2, set:

 [[  =  ||  =  ]]; =(   [[  =  ]]; =(   [[  !=  ]]; =(      

Changed:

 [[  !=  ]];        [[  =  ||  =  ]]; =(   [[  =  ]]; =(                 [[  =  ||  =  ]]; =(   [[  =  ]]; =(      

 

6. Install the mail client mutt + msmtp

apt-get  mutt

When mutt is installed, postfix will be automatically installed as the mail server. The problem is that this stuff 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 autoremove –purge

Install msmtp

apt-get  msmtp

After installation, configure the email.

 

7. Mail Client Configuration

 /etc/Muttrc

Add the following at the top:

====username@== no

Then go ~ Directory to create a. msmtprc

cd ~ .msmtprc

Add the following content:

~/.msmtp.log

Because the plaintext password is used here, we recommend that you modify the 600 stream and add another log file.

  ~/.msmtp.log

If this is all done, you can try sending emails without sending them out.

  |mutt -s  testmail@.com

If the test is successful, run the backup script.

 

8. install several commands on my server:

apt-get -get  pigz

 

9. If no environment variable is set for mysql, but a shortcut is added, set an environment variable.

  /etc/profile

Add at the last position

export  PATH=$PATH:/usr/local/mysql/bin

Save, And then refresh and check

source  /etc/ $PATH

 

10. Start the backup script. By the way, create a backup path first.

mkdir /srv/backup
mkdir /srv/backup/mysql
automysqlbackup

If there is no problem, you will see the backup file path, and several directories are automatically created for you:

Daily fullschema latest monthly status tmp weekly

In addition, when you open daily, there should be files backed up just now.

Check the mail again. All the emails are OK, so configure a scheduled task to complete.

 

11. Configure scheduled tasks

crontab –l

First check whether there are any tasks. If there are no tasks, go ~ Create a configuration file

cd ~ root-crontab

Add content

30 23 ***/usr/local/bin/automysqlbackup

Indicates that the backup script is automatically run at every day.

Then add it to the scheduled task.

crontab -u root root-crontab

Live together...

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.