We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Batch backup file help

Hi saw a program called Intellisync and thought I could write a batchfile to do its job instead - all I want to do is keep a folder on one computer synced with one on another, all changes going in one direction (not both) e.g. if all the data gets wiped on pc b pc a will send it all again when it runs.

However my solution isn't very good so far, I've written this:

xcopy z:\* i:\* /E /Y > C:\Documents and Settings\Tony\Desktop\confirmation.txt

Which copies everything in network drive j to network drive i, cant remember why its xcopy of /E or /Y exactly but anyway the problem Ive got is if i delete something on the z drive it doesnt get deleted in the i drive the next time i backup

also, everytime i backup everything gets sent, even though its already there.

I want to run this script every 10 mins (so ive created a suitable task in task scheduler).

Any help'd be great (on howto copy delete commands if u see how i mean, without deleting the backup folder at the beginning of each backup and starting over (this'd take too much network resources by far!!)

Thanks muchos

Duncan

Comments

  • scotty
    scotty Posts: 159 Forumite
    Xcopy is a powerful version of the copy command with additional features has the capability of moving files, directories, and even whole drives from one destination to another.

    E - Copies directories and sub directories, including empty ones. Same as /S /E. May be used to modify /T.

    Y - Overwrites existing files without prompting

    To avoid copying all files again:

    /D:date - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time

    XCOPY will not copy delete commands. If you must have this facility, I would suggest a batch file which you run at the end of the day to synchronise the two directories. This would delete all files (DEL) then copy (XCOPY) all files again.

    Have you considered other solutions for back-up e.g. RAID configured drives to maintain two identical copies of data?
  • drlight_2
    drlight_2 Posts: 292 Forumite
    Could someone check this I'm a bit rusty, I think this would work but it could delete the wrong files.

    l:\
    cd\
    for %%a in (*.*) do if not exist z:\%%a del l:\%%a /y

    ....I remembered Xcopy is the only command in dos that processes current & sub folders in one command, you could look on old dos boards for "del" with extended features.
  • ManAtHome
    ManAtHome Posts: 8,512 Forumite
    Part of the Furniture Combo Breaker
    Plenty of commercial and free software about - some useful links:
    http://www.canadiancontent.net/tech/freeware/Backup+Utilities/
    http://www.nonags.com/nonags/filesync.html
    http://www.fileware.com/products.htm

    XCOPY alternative to /D: is /M which will only copy files which have changed since the last XCOPY (ie Modified). Note that most other backup programs will affect this (works using the 'archive bit' which is set when a file is created or modified, reset when backed-up). Still won't handle deletes though - this used to be a good thing before the recycle bin was 'invented'.!!
  • charlieheard
    charlieheard Posts: 525 Forumite
    Part of the Furniture 500 Posts Combo Breaker Mortgage-free Glee!
    Don't know what version of Windows you're running, but have you thought of using the Briefcase functionality? I haven't used it for a few years, but it's still on WindowsXP.

    Another way is to use a "Norton Commander" clone (now I'm showing my age!). The one I've used is the free version of xplorer² from http://zabkat.com/. This allows you to compare two folders side-by-side and to update them with a keypress
    Jumbo

    "You may have speed, but I have momentum"
  • Cool thanks for all your replies, only just remembered I'd posted this and had to search the forums for it!! (oops hehe) reading and investigating your answers now :)
  • drlight wrote:
    Could someone check this I'm a bit rusty, I think this would work but it could delete the wrong files.

    l:\
    cd\
    for %%a in (*.*) do if not exist z:\%%a del l:\%%a /y

    ....I remembered Xcopy is the only command in dos that processes current & sub folders in one command, you could look on old dos boards for "del" with extended features.

    This looks very promising, could anyone tell me what each part does (it seems to say look for file in originating folder, if it doesn't exist delete it in backup directory) which'd be great! but I don't know the syntax at all
  • drlight_2
    drlight_2 Posts: 292 Forumite
    These are basic dos commands that come with windows,

    I'm using three commands
    del (del oldfile.doc)

    introduced
    if/if not exist - condition you can ad to any command eg
    if exist newfile.doc del oldfile.doc
    if exist newfile.doc xcopy oldfile.doc /y (the /y will overwrite without asking)
    if "newfile.doc" dosn't exist it will finish running this line, and goto the next


    for do
    for will run the command for every file that is in brackets (you can use wildcards eg *.*)
    %%a - will be replaced by what is written in the brackets (oldfile.doc, oldfile2.doc) or every file in the current directory (*.*)

    the for do wil keep running the command (after "do") until it has processed every file contained in the brackets (*.*)

    eg
    for %%a in (oldfile1.doc oldfile2.doc) do del %%a
    This will replace "%%a" with "oldfile1.doc" and will do:

    del oldfile1.doc
    del oldfile2.doc

    But this only works in the directory you are in. to run in other directories it would have to run in each directory you wanted.
  • Ah if only my Dad ran Linux... then I could just tap in Man, Apropos, Info or whatever, and string together a few pipes in no time! Oh well I'll have to blunder on with my complete unknowledge of DOS.
    Looks like it'd be easier to spend £15 on a tool to do this for me like UtiliSync, else I'll have to write a huge batch file with these if commands for each and every folder (theres hundreds upon hundreds, with folders in folders and everything!), and amend another x number of lines to it every time a new folder was created (albeit perhaps I could automate that process using batch haha).

    Thanks for all the help guys, looks like batch is gonna be rubbish for this apparently not so simple task though.
  • Godders
    Godders Posts: 2,913 Forumite
    1,000 Posts Combo Breaker
    Just use Robocopy (Robust File Copier)

    I think it does exactly what you want:

    robocopy j:\*.* i:\ /E /PURGE /XO /R:3

    copy all from j:\ to I:, include subfolders even if empty, Purge file from destination if not in source(ie. deleted), Exclude Older Files, maximum retries 3

    You may have to play with the syntax to get the exact result you want but it works - we use it for shunting large amounts of data around on the Windows platform, the beauty being it retries as many times as you ask it too rather than just falling down, will handle deletions and doesn't copy files that already exisit (this is to do with the Exclude parameters and I cant remember them all offhand)

    Get the Resource kit for Windows 2000 here, it's part of it and includes documentation:

    http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351.7K Banking & Borrowing
  • 253.4K Reduce Debt & Boost Income
  • 454K Spending & Discounts
  • 244.7K Work, Benefits & Business
  • 600.1K Mortgages, Homes & Bills
  • 177.3K Life & Family
  • 258.4K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.