Whether under Windows or Linux, a lot of log files if not regularly deleted will fill the hard disk, so you can write a script to handle the time.
The contents of the Windows BAT file are as follows;
The code is as follows |
Copy Code |
@echo off Forfiles-p "D:\servers\apache2.2\logs"-s-m *.log-d -15-c "cmd/c del @path" Forfiles-p "D:\servers\mysql\logs"-s-m *.log-d -15-c "cmd/c del @path" |
Backup
BAT file contents are:
The code is as follows |
Copy Code |
@echo Copy d:work*.db E:bake1 Exit |
The above directory can be changed to the specified directory, *.log can filter the file format, the following-D parameter is a negative number of days before, a positive number is how many days after. Save it as a bat file, and then set the time to execute daily on the Windows planning task.
The contents of the shell file under Linux are as follows:
The code is as follows |
Copy Code |
#!/bin/bash # Delete files from 30 days ago find/var/usr/nginx/logs/-mtime +30-type f-name\*.gz | Xargs rm-f |
1. Regularly back up site code and files
Script web.sh
The code is as follows |
Copy Code |
#!/bin/bash Cd/home/wwwroot Date= ' date-i '; # Backup website /BIN/TAR-CJF./BACKUP/WEBSITE_$DATE.TAR.BZ2 website # Romove Old data Find./backup-type f-mtime +7-exec rm-f {} |
Scripting: Go to the backup directory first, then define the date format, perform a backup by day, and delete the old backup data (7 days ago).
2. Regularly back up the database
Script db.sh
The code is as follows |
Copy Code |
#!/bin/bash Cd/home/wwwroot/backup Date= ' date-i '; /usr/bin/mysqldump-u root--password=123456 website > website_$date.sql /bin/gzip-9 Website_$date.sql |
The above script-U followed the database username, –password the database password, followed by the database name,> after the backup directory.
The gzip-9 is to compress the exported database with the highest compression rate.
The same as the above directory for their own designated directory, the following \*.gz represents the file name extension,-mtime the following parameters and windows above the opposite, a positive number of days before the file. Save the above content as. SH and use chmod +x to set up executable permissions, and then put them into a timed task to execute.