As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Simple batch file for backup?

ThanatosThanatos Registered User regular
edited November 2010 in Help / Advice Forum
Is there a way to write a batch file or something simple that will copy a file from one location to another, overwriting the old file there with no prompting?

I want something like this to do a simple backup of a couple locally-stored files on one of my boss' laptops, because he just lost some stuff and would really appreciate a solution like this, I think.

Thanatos on

Posts

  • Options
    DrFrylockDrFrylock Registered User regular
    edited November 2010
    Yes.
    copy /y source destination
    

    will overwrite without prompting. xcopy (which has more options) also supports this, but can copy directories and such. If you want to copy over a network, obviously you'll need to have some way of mounting the remote drive. If the Z: drive isn't in use on the machine, you can do that with something like:
    net use z: \\computername\sharename password /USER:user /PERSISTENT:no
    copy /y C:\Somedirectory\Somefile.ext Z:\Backups
    net use z: /DELETE
    

    If the remote host is UNIX and supports ssh/sftp, you can get rsync or scp for Windows or something to do it.

    You can put anything you want in a batch file, just put it in a text file with extension .bat or .cmd. If you want to suppress the output of the actual commands, put:
    @echo off
    

    as the first line.

    DrFrylock on
  • Options
    ThanatosThanatos Registered User regular
    edited November 2010
    So, I feel like a retard, because I can't get this to work.

    I've tried it down to the most basic (just the copy C:\directory\file.ext X:\other directory) and it still doesn't do shit.

    I'm directing it to a mapped network drive; that should be okay, right? Or do I have to do something different?

    Thanatos on
  • Options
    urahonkyurahonky Registered User regular
    edited November 2010
    I'm assuming you have read/write privileges on the X:\ drive? Do you get an error? Can you cd to the drive? (eg 'cd X:\')

    urahonky on
  • Options
    urahonkyurahonky Registered User regular
    edited November 2010
    Seems silly, but also make sure you don't have spaces in the first/second directory. You can put ' around them, and it'll be fine.

    urahonky on
  • Options
    ThanatosThanatos Registered User regular
    edited November 2010
    urahonky wrote: »
    Seems silly, but also make sure you don't have spaces in the first/second directory. You can put ' around them, and it'll be fine.

    Ah, I did not know that (the directory names have spaces in them, so I was putting spaces in them). Thanks!

    Thanatos on
  • Options
    urahonkyurahonky Registered User regular
    edited November 2010
    Thanatos wrote: »
    urahonky wrote: »
    Seems silly, but also make sure you don't have spaces in the first/second directory. You can put ' around them, and it'll be fine.

    Ah, I did not know that (the directory names have spaces in them, so I was putting spaces in them). Thanks!

    Yeah I hate that about command-line. I normally just put the ' around them even if they don't so I don't have to deal with it.

    urahonky on
Sign In or Register to comment.