UbuntuServer uses automysqlbackup script UbuntuServerUbuntu
BitsCN.com
Ubuntu Server uses the automysqlbackup script
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
Tar-xzf automysqlbackup-v3.0_rc6.tar.gz
2. cut down permissions for convenience
Sudo su-
3. Installation (if there are no special requirements on the path, you can press Enter)
./Install. sh
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)
# 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)
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, if 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 monthly backups. VALUE * 24 hours (number of days the 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? Remote)
CONFIG_mysql_dump_usessl = 'no'
# What wowould 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)
#-Stdout: will simply output the log to the screen if run manually. 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, just send a message)
CONFIG_mailcontent = 'files'
# Email Address to send mail? (User@domain.com) (mail address, don't talk about it)
CONFIG_mail_address = 'NC @ na.com'
5. change the script bug first .. However, if the mail and mutt on your server are complete, ignore this step.
Vi/usr/local/bin/automysqlbackup
To Line 2, 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
Fi
Changed:
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_mailcontent" = 'xfiles']; then
Dependencies = ("$ {dependencies [@]}" 'mail ')
Fi
Fi
6. install the mail client mutt + msmtp
Apt-get install 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 remove postfix-purge
Apt-get autoremove-purge
Install msmtp
Apt-get install msmtp
After installation, configure the email.
7. mail client configuration
Vi/etc/Muttrc
Add the following at the top:
# My Mail Setting
Set sendmail = "/usr/bin/msmtp"
Set use_from = yes
Set realname = "email address alias"
Set from = username@126.com
Set envelope_from = yes
# Do not retain the local sent Archive
Set copy = no
Then go ~ Directory to create a. msmtprc
Cd ~
Vi. msmtprc
Add the following content:
Account mailbox alias
Host smtp.126.com
From username@126.com
Auth plain
User username
Password pwd
Logfile ~ /. Msmtp. log
Because the plaintext password is used here, we recommend that you modify the 600 stream and add another log file.
Chmod 600. msmtprc
Touch ~ /. Msmtp. log
If this is all done, you can try sending emails without sending them out.
Echo "Hello" | mutt-s? Testmail@126.com
If the test is successful, run the backup script.
8. install several commands on my server:
Apt-get install pax
Apt-get install pigz
9. If no environment variable is set for mysql, but a shortcut is added, set an environment variable.
Vi/etc/profile
Add at the last position
Export PATH = $ PATH:/usr/local/mysql/bin
Save, and then refresh and check
Source/etc/profile
Echo $ 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 ~
Vi 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-crontab
Live together...
BitsCN.com