Home Database Mysql Tutorial Ubuntu Server使用automysqlbackup脚本_MySQL

Ubuntu Server使用automysqlbackup脚本_MySQL

Jun 01, 2016 pm 01:32 PM
develop server net plan

UbuntuServerUbuntu

bitsCN.com

Ubuntu Server使用automysqlbackup脚本

 

昨天服务器意外关闭,导致开发环境数据库文件损坏,所以想起了做自动备份的事情,原本是打算自己用Mysqldump写个脚本来做计划任务的,不过出于偷懒的角度考虑,在网上找了找,发现了automysqlbackup,看评论都还不错,而且本身也是shell脚本实现的。本着不重复造轮子的精神,就下载来使用了。

 

地址:http://sourceforge.net/projects/automysqlbackup/

 

选择的版本是最新的automysqlbackup-v3.0_rc6.tar.gz。

 

安装非常简单,比较麻烦的地方,是后面配置邮件客户端,以及脚本中的一个小bug。

 

1、在任意目录下,解压文件包

 

tar –xzf automysqlbackup-v3.0_rc6.tar.gz

 

2、省事起见,切个权限

 

sudo su -

 

3、安装(若对路径没有什么特别的要求,出现提示回车即可)

 

./install.sh

默认配置文件位置:/etc/automysqlbackup

 

默认sh文件位置:/usr/local/bin

 

4、修改配置文件

 

安装完成,默认会有两个配置文件,一个是automysqlbackup.conf,还有一个是myserver.conf。

 

实际上看了安装脚本就知道,这两个文件本来就是拷贝冗余了一个出来,猜测用途是防止二次安装或者误操作的情况下,误操作覆盖已经配置好的配置文件。不过从脚本逻辑上看起来,貌似没太大用,因为他重装,照样两个文件一块会覆盖。不过如果发现automysqlbackup.conf配置有值的话,会给出提示就是了。

 

依旧,为了偷懒期间,就直接修改automysqlbackup.conf了,毕竟这是默认配置,sh执行的时候,不用带任何参数。

 

主要需要注意的配置,有以下几个:(配置文件中,带有默认值,如果不需要更改,直接保持被注释的状态就好)

 

# Username to access the MySQL server e.g. dbuser

(数据库连接用户名)

CONFIG_mysql_dump_username='root'

 

# Password to access the MySQL server e.g. password(数据库连接密码)

 

CONFIG_mysql_dump_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(dump的时候,数据库host显示的别名,不配的话,基本就都是localhost之流了)

CONFIG_mysql_dump_host_friendly='DataBaseAlias'

 

 

# Backup directory location e.g /backups(不用多说了,重中之重,备份路径)

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(需要日备份和周备份的数据库名称)

CONFIG_db_names=('TestDB')

 

 

# List of databases for Monthly Backups.

# set to (), i.e. empty, if you want to backup all databases(需要月备份的数据库名称)

CONFIG_db_month_names=('TestDB')

 

# Which day do you want monthly backups? (01 to 31) (月备份的日期,如果配置的日期大于当月最大日期,会在当月最后一天的时候执行)

# 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)(周备份在星期几发生)

# Set to 0 to disable weekly backups.

#CONFIG_do_weekly="5"

 

# Set rotation of daily backups. VALUE*24hours

# If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.(日备份文件保留多少天)

CONFIG_rotation_daily=7

 

# Set rotation for weekly backups. VALUE*24hours(周备份文件保留多少天)

#CONFIG_rotation_weekly=35

 

# Set rotation for monthly backups. VALUE*24hours(月备份文件保留多少天)

#CONFIG_rotation_monthly=150

 

# Use ssl encryption with mysqldump?(是否使用ssl,本地的话,开ssl找抽?远程就另算了)

CONFIG_mysql_dump_usessl='no'

 

 

# 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.(表邮件了,屏幕显示下就好。问题是谁吃饱没事一天到晚盯着server屏幕看?)

# - quiet : Only send logs if an error occurs to the MAILADDR.(出错了的话,给个信儿就好)

CONFIG_mailcontent='files'

 

# Email Address to send mail to? (user@domain.com)(mail地址咯,不用多说了吧)

CONFIG_mail_address='nc@na.com'

 

 

 

5、先改个脚本的小bug吧。。不过如果你的server上mail和mutt齐备,请忽略该步骤。

 

vi /usr/local/bin/automysqlbackup

到1026行,将:

 

 

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

 

改为:

 

 

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、安装邮件客户端 mutt+msmtp

 

apt-get install mutt

安装mutt的时候,会自动安装postfix用作mail server,问题是这玩意太大,出于比较有洁癖的心态,我就主动把它干掉了。毕竟小巧玲珑的msmtp在那等着我呢。(看个人需求和喜好而定)

 

apt-get remove postfix –purge

apt-get autoremove –purge

 

安装msmtp

 

apt-get install msmtp

安装完了,来配邮件吧。

 

 

 

7、邮件客户端配置

 

vi /etc/Muttrc

最上面加上如下:

 

 

#My Mail Setting

set sendmail="/usr/bin/msmtp"

set use_from=yes

set realname="邮件地址别名"

set from=username@126.com

set envelope_from=yes

#不保留sent的本地存档

set copy = no

 

然后到~目录下,新建个.msmtprc

 

cd ~

vi .msmtprc

加上如下内容:

 

 

account 邮箱别名

host smtp.126.com

from username@126.com

auth plain

user username

password pwd

logfile ~/.msmtp.log

 

因为这里是明文密码,所以建议修改个600之流,再增加个日志文件

 

chmod 600 .msmtprc

touch ~/.msmtp.log

这全部完成了的话,可以试试邮件发不发的出去了。

 

echo "喂" |mutt -s "发出去没?" testmail@126.com

测试成功的话,就跑一下备份脚本看看吧

 

 

8、装上几个我服务器上木有的命令:

 

apt-get install pax

apt-get install pigz

 

 

9、mysql如果之前没设环境变量,只是加了个快捷方式的话,设个环境变量

 

vi  /etc/profile

在最后的位置加入

 

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

保存,然后再刷新检查下

 

source  /etc/profile 

echo $PATH

 

 

10、启动下备份脚本试试了,对了,记得要先创建备份路径

 

mkdir /srv/backup

mkdir /srv/backup/mysql

automysqlbackup

如果没什么问题的话,就会看到备份文件路径下面,自动给你创建好了几个目录:

 

daily  fullschema  latest  monthly  status  tmp  weekly

 

而且打开daily,里面应该就会有刚才备份的文件了。

 

再去check一下mail,都ok,那就配个计划任务就完事了。

 

 

 

11、配置计划任务

 

crontab –l

先查查看目前有没有任务,没有的话,就在~建个配置文件

 

cd ~

vi root-crontab

内容添上

 

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

 

表示每天23点30,自动运行备份脚本

 

然后再添加到计划任务里面去

 

crontab -u root root-crontab

齐活。。。

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

Best Practice Guide for Building IP Proxy Servers with PHP Best Practice Guide for Building IP Proxy Servers with PHP Mar 11, 2024 am 08:36 AM

In network data transmission, IP proxy servers play an important role, helping users hide their real IP addresses, protect privacy, and improve access speeds. In this article, we will introduce the best practice guide on how to build an IP proxy server with PHP and provide specific code examples. What is an IP proxy server? An IP proxy server is an intermediate server located between the user and the target server. It acts as a transfer station between the user and the target server, forwarding the user's requests and responses. By using an IP proxy server

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline Mar 13, 2024 pm 04:40 PM

What should I do if I can’t enter the game when the epic server is offline? This problem must have been encountered by many friends. When this prompt appears, the genuine game cannot be started. This problem is usually caused by interference from the network and security software. So how should it be solved? The editor of this issue will explain I would like to share the solution with you, I hope today’s software tutorial can help you solve the problem. What to do if the epic server cannot enter the game when it is offline: 1. It may be interfered by security software. Close the game platform and security software and then restart. 2. The second is that the network fluctuates too much. Try restarting the router to see if it works. If the conditions are OK, you can try to use the 5g mobile network to operate. 3. Then there may be more

How to install PHP FFmpeg extension on server? How to install PHP FFmpeg extension on server? Mar 28, 2024 pm 02:39 PM

How to install PHPFFmpeg extension on server? Installing the PHPFFmpeg extension on the server can help us process audio and video files in PHP projects and implement functions such as encoding, decoding, editing, and processing of audio and video files. This article will introduce how to install the PHPFFmpeg extension on the server, as well as specific code examples. First, we need to ensure that PHP and FFmpeg are installed on the server. If FFmpeg is not installed, you can follow the steps below to install FFmpe

Which Linux distribution is best for Android development? Which Linux distribution is best for Android development? Mar 14, 2024 pm 12:30 PM

Android development is a busy and exciting job, and choosing a suitable Linux distribution for development is particularly important. Among the many Linux distributions, which one is most suitable for Android development? This article will explore this issue from several aspects and give specific code examples. First, let’s take a look at several currently popular Linux distributions: Ubuntu, Fedora, Debian, CentOS, etc. They all have their own advantages and characteristics.

See all articles