Linux VPS Automatic backup data to remote host FTP method _linux

Source: Internet
Author: User
Tags vps
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*

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.