summary:
This article provides an idea to use aspphp script to implement website file backup, which can realize daily backup of specified files.
Personal websites often have very little control over the host on virtual hosts, so they cannot use task schedules to achieve timed backups. We need to change our thinking to achieve similar automatic backups.
We can use users' access to the website to achieve daily backup of specified files.
The basic idea is: the user visits the website → reads the last backup date, reads the current date and then compares. If the two dates are inconsistent, the backup program will be called to realize the backup of the specified file. After the backup is completed, a new date mark will be written. At this time, the user visits the website again, and the date is already the latest, and the backup program will be skipped and other programs will be executed.
Analyze this idea: the backup program will be started when the first user visits the website every day, which can achieve the effect of backup by day. However, if there is no user access on this day, there will be no backup. This does not matter much, because if no user accesses the website, the content of the website will not change much. Therefore, this situation can be ignored.
It should be noted that there may be cases where two people visit the website at the same time and start the backup program at the same time, which may overwrite the backup content. In this regard, we can add judgment statements to the program, and do not overwrite the file if it already exists.
If the file names of the two files to be backed up are the same, it will also cause overwriting. We assume that the files are all different.
Another important issue is that the period formats that must be used in the backup program are 4-digit years, 2-digit months and days, and zeros must be made up for inadequate digits. For example: 2006-05-31 Only in this way can we achieve the comparison of date sizes. In Asp, we can use a small program to implement it. There is already such a date format in PHP.
The structure of the program is explained in detail below, taking asp as an example.
===bak_set.asp===