1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Having batch file backup problem...help if u can!

Discussion in 'Programming & Webmastering' started by GraveFiller, Nov 15, 2012.

  1. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    Hi there.

    Was making a batch file to do backups of my important files and it works fine for just about any folder
    except for
    My Documents.

    It copies my firefox mozilla backups fine to my c: drive.
    But if i try to copy my documents to D: drive i get invalid syntax, or file not found.

    I've tried everything, it just won't do it.

    Here's the script:

    @echo off
    cls
    echo Press Any Key to continue backup!
    pause
    xcopy /s /i d:\backups\Mozilla c:\mozillaback
    copy . c:\Documents and Settings\spear\My Documents d:\Backups\My documents
    echo Backup has now finnished !

    I've spelled the directories exaclty as you see here, no mistakes. It just won't work.
    I'm kind of new at this, thanks so much anyone.
    !:toast:
     
  2. eidairaman1

    eidairaman1

    Joined:
    Jul 2, 2007
    Messages:
    13,075 (4.88/day)
    Thanks Received:
    1,652
    Because My Documents isnt My Documents anymore. You have to point at the specific directory of the account your backing up
     
  3. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    5,270 (2.60/day)
    Thanks Received:
    2,748
    Location:
    Statesville, NC
    Try using "%USERPROFILE%\My Documents". :toast:

    EDIT: Actually that's for XP.. This is for Vista/Win7 "%USERPROFILE%\Documents"
     
    Last edited: Nov 15, 2012
    Crunching for Team TPU
  4. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    5,270 (2.60/day)
    Thanks Received:
    2,748
    Location:
    Statesville, NC
    Here is one I wrote awhile back and it puts your stuff in a folder with the days date and time, and adds a log file. Enjoy! :toast:

    Remember to set the path for the following
    • set drive=u:\Backup_Dir
    • set Stuff2Backup=%USERPROFILE%\Documents

    Code:
    @echo off
    :: variables
    :: The below varible "drive" needs to have the path where you want to save it.
    :: The below varible "Stuff2Backup" needs to be what you want to save.
    set drive=u:\Backup_Dir
    set tt=%time:~0,2%_%time:~3,2%_Backup
    set folder=%date:/=-% %tt%
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
    set Stuff2Backup="%USERPROFILE%\My Documents"
    
    
    color 9F
    echo ### Mindweaver's Backup Plain
    
    %backupcmd% "%Stuff2Backup%\*.*" "%drive%\%folder%\%file%"
    
    
    echo ### Setting Attribute's
    
    attrib +r -h %drive%\* /s /d
    
    echo This Backup was created on Date (%date%), Time (%time%). >> "%drive%\%folder%\Backuplog.txt"
    
    echo Backup Complete!
    @pause
    EDIT: Sorry mods for double post.. My back is out of wack and i'm on muscle relaxers.. :p
     
    Last edited: Nov 15, 2012
    Crunching for Team TPU
  5. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    Yes, my machine is WinXP.
    Will try the %userprofile% switch......thanks will let u know if it works!;)
     
  6. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    Hope your back gets better...jealous about the painkillers ya got! lol.
    Thanks so much for the script.
    didnt need all the colors n fonts, but will look nice....very cool of u...thanks!


     
  7. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    5,270 (2.60/day)
    Thanks Received:
    2,748
    Location:
    Statesville, NC
    No problem. I noticed something I missed last night while on the pain killers.. lol You'll need to put %USERPROFILE%\My Documents in "" like this "%USERPROFILE%\My Documents" and you'll want to remove the \ in front of Documents. I fixed the code above if you want to re-copy that code. :toast:

    EDIT: The reason you need to put it in "" is because of the space in My Documents. The batch file will break at that point and tell you it can't find the location. :toast:
     
    Crunching for Team TPU
  8. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    sTILL not working..here's how it looks

    @echo off
    cls
    echo Press Any Key to continue backup!
    pause
    xcopy /s /i d:\backups\Mozilla c:\mozillaback
    copy . c:\%USERPROFILE%\My Documents d:\Backups\My Documents
    echo Backup has now finnished !

    says: the syntax of the command is incorrect.
    it does the first back..(mozilla) fine...then again at my documents..it's f'd up.
    This is the exact directory...maybe u can edit it for me?
    c:\documents and settings\spear\my documents.
    backing up to
    D:\backups\mozilla

    if you can script it for me so i won't fuk up again???
    thanks mind!
     
  9. PopcornMachine

    PopcornMachine

    Joined:
    Aug 17, 2009
    Messages:
    1,563 (0.82/day)
    Thanks Received:
    459
    Location:
    Los Angeles/Orange County CA
    just wondering my first command is xcopy and the next is copy ...
     
  10. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    5,270 (2.60/day)
    Thanks Received:
    2,748
    Location:
    Statesville, NC
    You got a few errors in line copy . c:\%USERPROFILE%\My Documents d:\Backups\My Documents. The first one is copy needs to be xcopy and you need to remove the "." and you don't need to put the drive letter in front of Variable %USERPROFILE%. The other 2 errors are the spaces in both My Documents. When ever you refer to a folder that has spaces in the name you need to add "". Example : xcopy "%USERPROFILE%\My Documents" "d:\Backups\My Documents".

    Copy and replace what you have in your batch file with this.
    Code:
    @echo off
    cls
    echo Press Any Key to continue backup!
    pause
    xcopy /s /i d:\backups\Mozilla c:\mozillaback
    xcopy /s /c /d /e /h /i /r /k /y "%USERPROFILE%\My Documents" "d:\Backups\My Documents"
    echo Backup has now finished!
     
    Crunching for Team TPU
  11. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    Ahhh, now i understand!
    gonna put that new script in...now i know forever if there's any space use Quotes ""
    .
    And i'm gonna try it right now...hold on.

     
  12. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    it worked! thanks!

    Now i have to figure out why my documents folder is hidden on the D: drive....lol.

    i can see it thru cmd prompt....but not in explorer.

    I just un attribed it -a -h -r -s....still don't see in folder...

    But thanks again for the code brother .....bless u!

    lyndon

     
  13. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.92/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    You could use robocopy and save yourself a lot of trouble.
    It's one line in a batch file to do just about everything you want and it will only backup files that changed so you aren't running a full backup when you don't need it.
    I use it to backup my fileservers at work.
    The newer version (post-XP) will multi-thread the backup too.

    Just a tip from yer Ol' Uncle Kreij
     
    Mindweaver says thanks.
  14. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    5,270 (2.60/day)
    Thanks Received:
    2,748
    Location:
    Statesville, NC
    Yea robocopy is the shit.. hehehe I use it too. :toast:

    No problem! Paste your code in here and I'll see why it's hiding your files. My code shouldn't hind any files.. I use it quite often.
     
    Last edited: Nov 17, 2012
    Crunching for Team TPU
  15. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.92/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    Yeah, the granular control over what determines when a file should be backed up (file attributes, tweaks, etc.), the ability to specify directories to not include, ability to write the backup anywhere (Mapped drive, USB drive, etc.) and the ability to write/append logs make it easily as good as a paid backup solution.
    Someone wrote a GUI for it, but it was a bit lacking the last time I looked at it.

    Note : Robocopy is not for the faint of heart. It has more switches and options than TMM has infractions.
     
    Last edited: Nov 19, 2012
    Mindweaver says thanks.
  16. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    5,270 (2.60/day)
    Thanks Received:
    2,748
    Location:
    Statesville, NC
    Hell yea! lol
     
    Crunching for Team TPU
  17. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    i will search for it on a torrent site..
    I do like working in dos, but yea, an incremental or differential backup is preferable for sure.

    Thanks for the tip ...gonna go snatch that muthr now!



     
  18. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.92/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    Robocopy is free from Microsoft. It comes with everything after XP and is a free download for XP.
     
  19. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    i just did a search...and one guy says this:
    RichCopy is a free utility that comes to us from Ken Tamaru of Microsoft.
    Some people say richcopy is an improvement over robocopy. Guess i'll try both!

    u ever hear of richcopy?


     
  20. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.92/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    No, that is new to me. Researching now. Thanks for the info.

    update : looks like Richcopy has a GUI but has some issues and is not supported by MS (like robocopy).
    Not that you need support by MS, but I wonder how well problems/issues are dealt with if found.
     
    Last edited: Nov 17, 2012
  21. newtekie1

    newtekie1 Semi-Retired Folder

    Joined:
    Nov 22, 2005
    Messages:
    20,063 (6.14/day)
    Thanks Received:
    6,122
    They aren't, there hasn't been an update to richcopy in years, and it isn't perfect.

    I used to use robocopy backup scripts for my backups, but I'm too old/lazy to write scripts for every backup so I just use FBackup now. Plus I like that FBackup will use the volume shadow copy, so files in use still get backed up, which robocopy won't do.
     
    Crunching for Team TPU 50 Million points folded for TPU
  22. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    i uninstalled it...looks like i can only backup 1 dir. at a time.....F*k that!
    lol.

    The other one robocopy is crazy....alot of dos commands, ( i like dos) but it also installed some files i didn't liike... some extra processes that i hate using my meager 4 gb i have.

    Maybe i'll go back to backupmagic. that will backup differential, incremental...and multiple dir's.

    I was just wondering why my batchfile i tried didn't work...but i understand how it works...need quotes if there's a space in directory name.

    so what'd u find out? about richcopy?

     
  23. GraveFiller

    Joined:
    Dec 13, 2006
    Messages:
    160 (0.06/day)
    Thanks Received:
    7
    Location:
    hollywood, fla.
    cool....i will try that one out!
    is it free?

     
  24. newtekie1

    newtekie1 Semi-Retired Folder

    Joined:
    Nov 22, 2005
    Messages:
    20,063 (6.14/day)
    Thanks Received:
    6,122
    Yes, it is free.
     
    Crunching for Team TPU 50 Million points folded for TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page