In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to write scripts for Vps automatic backup of web and mysql databases under linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Backup the web folder
1. Backup / home/users/public_html directory
2. Modify crontab to run at 3: 22:00 on the first day of the week
The copy code is as follows:
22 3 * 0 root run-parts / etc/cron.weekly
3. Copy the script to the / etc/cron.weekly directory
4. Modify permissions
The copy code is as follows:
Chmod 0755 / etc/cron.weekly/webbackup.sh
5. The script is as follows
The copy code is as follows:
#! / bin/sh
Filename= `date +% y% m% d`
Backup_dir= "/ root/dropbox/backup/web"
# delete all files 10 days ago
Find $backup_dir-mtime + 30-name "*"-exec rm-rf {}\
# each user you want backup
Users= "baidu sina"
For user in ${users}; do
Tar zcvf $backup_dir/$user$filename.tar.gz / home/$user/public_html
Done
6. Notice that the sentence filename is not a single quotation mark, but above the tab key
7. Fill in the public_html directory of the user to be backed up into users
Daily backup of mysql database
1. For security, create a new user backup with a strong password (automatically generated), and the global permission is select,lock tables.
2. Starting from 3:00 every day, modify the crontab
3. Copy the script to / etc/cron.daily
4. Modify permissions
5. Content of script
The copy code is as follows:
#! / bin/sh
Dbuser= "backup"
Dbpassword= "youpassword"
Datas= "db1 db2 db3"
Filename= `date +% y% m% d`
Bin_dir= "/ usr/local/mysql/bin"
Backup_dir= "/ root/dropbox/backup/mysql"
# delete all files 10 days ago
Find $backup_dir-mtime + 10-name "*"-exec rm-rf {}\
# do each database backup
For data in ${datas}; do
$bin_dir/mysqldump-- opt-u$dbuser-p$dbpassword $data | gzip > $backup_dir/$data$filename.sql.gz
Done
6. Ibid. Article 6.
7. Fill in datas for the database to be backed up
This is the end of the content of "how to write a script for Vps to automatically back up web and mysql databases under linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.