Linux website data and MySQL database automatic backup code

Source: Internet
Author: User

Scheduled backup of Web site data

The code is as follows Copy Code

#!/bin/bash
Path=/bin:/usr/bin:/sbin:/usr/sbin;
Export PATH;
Tar zcvf/web/backup/bak.$ (date +%y-%m-%d). tar.gz/web/www/www.111cn.net
Find/web/backup-type f-mtime +2-exec rm {};

Second line: Import environment variables

The third line, the designated directory to a compressed package/web/www/www.111cn.net/directory for a lot, save to the specified directory:/web/backup/, the file is the current month and year date

Line four: Delete backup files two days ago

MySQL Automatic backup (can delete data from a few days ago)

The code is as follows Copy Code
#!/bin/bash
Export path= $PATH:/bin:/usr/bin:/usr/local/bin
find/web/backup/mysqlbak/-mtime +7-exec rm {}; #注意: {} and a space between
mysqldump-uroot-pganggang11560. -B Blog >/web/backup/mysqlbak/www.mapenggang.com.$ (Date +%y-%m-%d-%k-%m-%s). sql

First line: I won't say it.

Second line: Import environment variables, because there is no environment variable at the time of the task, so import the next. Transmission Door

Second line: In/web/backup/mysqlbak/find the last modified time is five days before the file, and the RM command, {} is the file name of the lookup passed in!

The third line: The mysqldump command backs up the database, uses the root user connection, exports the blog table, the backup is stored in the/web/backup/mysqlbak/directory, the file name is: the blog plus the date and time of the backup

The code is as follows Copy Code

chmod 777./bak.sh# to execute permissions on scripts
Crontab-e #修改定时任务

4 * * */web/backup/bak.sh #每天的凌晨四点半执行

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.