The backed-up data, if not particularly large, is not recommended for compression, preventing the possibility of corrupted files that have been compressed several times.
The way to back up the database is to back up the data directory after the MySQL service is stopped, during which time MySQL aborts for a few seconds to dozens of seconds. Please weigh the pros and cons yourself.
If there is no FTP command on the system, perform the Yum install-y FTP installation first.
You need to create a/home/backup/directory that cannot be used for other purposes.
Copy Code code as follows:
#!/bin/bash
#FTP信息
ftp_ip=
ftp_user=
ftp_pass= The
#备份数据库
/etc/init.d/mysqld stop
mysqlbakname=mysql_$ (date +%y%m%d). tar.gz
Tar Zcf/home/back up/$MySQLBakName/var/lib/mysql
/etc/init.d/mysqld start
#备份网站
webbakname=web_$ (date +%y%m%d). Tar
Tar cf/home/backup/$WebBakName/home/www
#操作FTP
oldmysql=mysql_$ (date-d -1day + "%y%m%d"). tar.gz
oldweb=web_$ (date-d -1day + "%y%m%d"). Tar
cd/home/backup/
/usr/bin/ftp-v-n $FTP _ip << EOF
User $FTP _user $FTP _pass
Type binary
put $MySQLBakName
put $WebBakName
Delete $OldMySQL Br>delete $OldWeb
Bye
EOF
rm-rf/home/backup/*.tar*