Disclosure of Invention
In order to solve the technical problems, the invention aims to provide a method for complete and incremental backup and recovery of a file directory, and the final aim of the method is to backup and recover file directory data.
The aim of the invention is achieved by the following technical scheme:
a method of full and incremental backup and restore to a file directory, comprising:
a, carrying out complete backup on the file catalogue, namely copying the file catalogue to a designated position for backup, and recording all files in the file catalogue;
b, performing incremental backup on the file catalogue, generating a new file catalogue record in the incremental backup process, comparing the new file catalogue record with the old file catalogue record, storing the newly added, modified and deleted file information, and replacing the old file catalogue with the new file catalogue;
copying the file directory data of the previous complete backup to replace the original file directory;
and D, deleting the files to be deleted according to the deleted file information recorded by the incremental backup data, and copying and replacing the stored newly added and modified files to the original files.
One or more embodiments of the present invention may have the following advantages over the prior art:
the invention only stores the newly added, modified and deleted file information during incremental backup by utilizing the simple file directory record (file path and MD5 value), thereby avoiding occupying a large amount of storage resources.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail with reference to the following examples and the accompanying drawings.
As shown in fig. 1, the method flow for complete and incremental backup and recovery of file directory comprises the following steps:
step 10, carrying out complete backup on the file catalogue, namely copying the file catalogue to a designated position for backup, and recording all files in the file catalogue;
step 20, performing incremental backup on the file catalogue, generating a new file catalogue record in the incremental backup process, comparing the new file catalogue record with the old file catalogue record, storing the newly added, modified and deleted file information, and replacing the old file catalogue with the new file catalogue;
step 30, copying the file directory data of the previous complete backup to replace the original file directory;
and step 40, deleting the files to be deleted according to the deleted file information recorded by the incremental backup data, and copying the stored newly added and modified files to replace the original files.
Step 10 is a full backup, copying the file directory to a designated location, and generating a file directory record in the original file directory, namely: oldAbllLog. Txt file (key is file path, value is MD5 value), as shown in FIG. 2, is a full backup schematic.
The step 20 is incremental backup, and specifically includes: generating a new file directory record according to the file path in the file directory and the MD5 value generated by using the file information, and comparing the new file directory record with the old file directory record: if the MD5 values of the same file path are different, indicating that the file is modified, and recording modified file information (file path and file); if there is a file path in the new file directory record and there is no file path in the old file directory, the file is a newly added file, and the information (file path and file) of the newly added file is recorded; if there is no file path in the new file directory record, but there is a file path in the old file directory, the file is a deleted file, and deleted file information (file path) is recorded.
The first embodiment is as follows:
generating a new record newLog. Txt (key is a file path and value is an MD5 value) file for the file directory;
judging whether the oldAddLog.txt file exists,
if the file information does not exist, comparing the newLog. Txt with the oldAbllLog. Txt, recording the newly added and modified file information, and generating delLog. Txt in the incremental backup file for recording the deleted file information. And renaming the newLog.txt file to oldAddLog.txt, and storing the newLog.txt file in the original file directory. FIG. 3 is a schematic diagram of a first embodiment incremental backup.
The second embodiment is as follows:
if so, the dates of oldAddLog. Txt and oldAllLog. Txt are determined.
If the oldAddLog.txt time is earlier than the oldAllLog.txt time, comparing the newLog.txt with the oldAllLog.txt, recording newly added, modified and deleted file information, renaming the newLog.txt file to oldAddLog.txt, replacing the original oldAddLog.txt, and storing the new log information and the old oldAddLog.txt in the original file directory.
If the oldAddLog.txt time is later than the oldAllLog.txt time, comparing the newLog.txt with the oldAddLog.txt, and recording newly added, modified and deleted file information. And renaming the newLog.txt file to oldAddLog.txt, replacing the original oldAddLog.txt, and storing the file in the original file directory. FIG. 4 is a schematic diagram of a second embodiment incremental backup.
Step 30 is complete restoration, i.e. the original file directory is replaced by copying the previously stored complete backup data. A full recovery schematic is shown in fig. 5.
The step 40 is incremental recovery, and specifically includes: acquiring file information stored in the incremental backup data, and deleting files to be deleted according to the file deleting information (file path) recorded by the incremental backup data; copying and replacing the saved file according to the modified file information (file and file path); and copying the saved newly added file to the designated file path according to the newly added file information (file and file path). An incremental recovery schematic is shown in fig. 6.
Although the embodiments of the present invention are described above, the embodiments are only used for facilitating understanding of the present invention, and are not intended to limit the present invention. Any person skilled in the art can make any modification and variation in form and detail without departing from the spirit and scope of the present disclosure, but the scope of the present disclosure is still subject to the scope of the appended claims.