1.

Solve : Backup script help?

Answer» HELLO all,

I was wondering could I get help with my backup script.

I have got my XCOPY working well. Copies all the files from A to B and only copy's the new or updated files from there on (this backup runs every day).

However when I delete a file from A (or move it to another folder) when the script runs again it keeps the original file in B or even makes another copy of the file in B if it was moved ELSE where.

What I want to do is to check ALL files and folders in B to see if they exist in A. If they dont exist in A then delete them from B.

(basiclly B is a direct mirror copy of A).

How would I code it?

I know I could simply delete the B files and xcopy the files again from A but that means I will be copying every file again and some of my backups are very big. What I want to do is to keep my incrimental xcopy command and then to have a loop that checks all B files if they exist at A and to ether leave them alone or delete them from B.

What I have been trying to do is export a .txt file with all files / directories from B then input each line as a variable -> check veriable exists in A then to ether ignore or delete the file from B then to move to the NEXT line in the text file (therefore the next file in the directory) and save that as the variable and start the loop again until all files (lines) have been processed but so far I have had no luck.

Hopefully there is a easier way.

Thanks in advance!Quote from: jokenno14 on January 26, 2010, 04:33:15 PM
What I have been trying to do is export a .txt file with all files / directories from B then input each line as a variable

Compare file names and contents with the Comp command:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/comp.mspx?mfr=true


C:\batch>comp /?
Compares the contents of two files or sets of files.

COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[liNE]]

data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII CHARACTERS.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[liNE] Do not skip files with offline attribute set.

To compare sets of files, use wildcards in data1 and data2 parameters.

C:\batch>


Code: [Select]dir /b c:\*.bat > batfiles.txt

dir /b c:\batch\*.bat > batfiles2.txt

comp batdiles.txt batfiles2.txt



I have not tested the comp command.Quote from: jokenno14 on January 26, 2010, 04:33:15 PM
(basiclly B is a direct mirror copy of A).

Since you appear to be using Windows 7, try ROBOCOPY with the /MIR option.

e.g.

Code: [Select]ROBOCOPY A B /MIRQuote from: oldun on January 26, 2010, 06:10:55 PM
Since you appear to be using Windows 7, try ROBOCOPY with the /MIR option.

e.g.

Code: [Select]ROBOCOPY A B /MIR

Wow! Never heard of ROBOCOPY! looks fantastic!

I should only need one line then:

robocopy A B /MIR / E /Z right? That will keep both destination and SOURCE the same but will it also act as a incremental backup?

Thanks for the help!You do not need /E with /MIR. Also, you only really need /Z when backing up to a network share.


Discussion

No Comment Found