In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how VPS automatically back up the database to FTP, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1) make sure you are in the home directory (if not, run: cd / home)
2) create a new backup folder (command: mkdir backup)
3) create a new script backup.sh
Vi backup.sh
Copy the following code (after copying: wq! To save):
#! / bin/bash
# what you want to change starts here
MYSQL_USER=root # mysql user name
MYSQL_PASS=123456 # mysql password
FTP_USER=vmvps # ftp user name
FTP_PASS=123456 # ftp password
FTP_IP=ftp.vmvps.com # ftp address
The directory on FTP_backup=backup # ftp where backup files are stored. You must build this directory on ftp.
WEB_DATA=/home/wwwroot # website data to be backed up
# the place you want to modify ends here
# define the name of the database and the name of the old database
DataBakName=Data_$ (date + "% Y%m%d") .tar.gz
WebBakName=Web_$ (date +% Y%m%d) .tar.gz
OldData=Data_$ (date-d-5day + "% Y%m%d") .tar.gz
OldWeb=Web_$ (date-d-5day + "% Y%m%d") .tar.gz
# Delete local data 3 days ago
Rm-rf / home/backup/Data_$ (date-d-3day + "% Y%m%d"). Tar.gz / home/backup/Web_$ (date-d-3day + "% Y%m%d") .tar.gz
Cd / home/backup
# Export database, one database corresponds to one compressed file
For db in `/ usr/local/mysql/bin/mysql-u$MYSQL_USER-p$MYSQL_PASS-B-N-e 'SHOW DATABASES' | xargs`; do
(/ usr/local/mysql/bin/mysqldump-u$MYSQL_USER-p$MYSQL_PASS ${db} | gzip-9-> ${db} .sql.gz)
Done
# compress the database file into one file
Tar zcf / home/backup/$DataBakName / home/backup/*.sql.gz
Rm-rf / home/backup/*.sql.gz
# compress website data
Tar zcf / home/backup/$WebBakName $WEB_DATA
# upload to FTP space and delete data from 5 days ago in FTP space
Ftp-v-n $FTP_IP
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.