This is the MySQL backup script of cainiao-level O & M. I wrote it here to take notes, and I got to know two gadgets: mysqldumppdumpfs.
This is the MySQL backup script of cainiao-level O & M. I wrote it here to take notes, and I got to know two gadgets: mysqldump/pdumpfs.
This is the MySQL backup script of cainiao-level O & M. I wrote it here to take notes, and I got to know two gadgets: mysqldump/pdumpfs.
The first part is mysql Data Backup.
[Root @ localhost ~] # Mkdir-p/usr2/backup/mysql
[Root @ localhost ~] # Vi mysqldump. sh
#! /Bin/bash
# Author XXX time 2011-10-17
# The backup of localhost mysql data
X = 'date + % Y % m % d'
M =/usr/local/mysql/bin
B =/usr2/backup/mysql
$ M/mysqldump-uroot -- all-databases> $ B/$ X. SQL // mysql on the local machine sets the logon password. If you need to change the password, ($ M/mysqldump-uroot-ppassword -- all-databases> $ B/$ X. SQL)
Tar zcvf $ B/$X.tar.gz $ B/$ X. SQL
Rm-rf $ B/$ X. SQL
[Root @ localhost ~] # Chmod a + x mysqldump. sh
[Root @ localhost ~] #./Mysqldump. sh
Tar: Removing leading '/' from member names
/Usr2/backup/mysql/20111015. SQL
The above script can be added to the cron scheduled task to perform the backup action at the scheduled time!
[Root @ localhost ~] # Echo "***** root path/XX. sh &>/dev/null">/etc/crontab
The disaster recovery statement can be written in this way.
[Root @ localhost ~] #/Usr/local/mysql/bin/mysqldump-uroot-ppassword <$ path/'date + % Y % m % d'
The weekly backup data volume is large. The following statement can be written to cron. weekly to clear overlapping data.
[Root @ localhost ~] # Find/usr2/backup/mysql-mtime + 6-exec rm {}\;
The second part is web data backup.
Here we use a new discovered tool, pdumpfs.
[Root @ localhost ~] # Yum-y install ruby (install the required package)
[Root @ localhost ~] # Wget
[Root @ localhost ~] # Rpm-ivh pdumpfs-1.3-1.rh9.rf.i386.rpm
[Root @ localhost web] # mkdir/usr2/backup/web
[Root @ localhost ~] # Vim web. sh
#! /Bin/bash
# Author XXX time 2011-10-17
Pdumpfs/var/www/usr2/backup/web>/usr2/backup/web/message. log 2>/usr2/backup/web/error. log
[Root @ localhost ~] # Chmod a + x web. sh
At the same time, you can put this script into cron's scheduled tasks for regular execution.
[Root @ localhost ~] # Echo "***** root path/XX. sh &>/dev/null">/etc/crontab
[Root @ localhost ~] # Ls/usr2/backup/web/(Zhe is the backup data part)
2011 error. log latest message. log
The third part is the remote password-free replication settings for ssh.
Two linux Hosts, one ip address (that is, the server itself) and the other ip address (as the remote backup host)
First, perform operations on the remote backup host.
[Root @ localhost ~] # Ssh-keygen (generate public keys)
[Root @ localhost ~] # Ssh-copy-id-I/root/. ssh/id_rsa (send to the server. In this step, enter the 192 password)
[Root @ localhost ~] # Scp:/usr2/backup/mysql/20111015.tar.gz. Replace this with a script to implement many operations)
Summary: The main backup methods include full backup, Incremental backup, differential backup, and local and remote backup! This is just a small instance of file backup, and we look forward to further learning!