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 #每天的凌晨四点半执行