Questions

Backup a Hard drive using xcopy

+
0 Votes
Locked

Backup a Hard drive using xcopy

lmkk
I ran a batch script to copy all the files on an internal hard drive to an external hard drive using the following script;
cd c:\
xcopy /s /e /d /y /c C:\ H:\Backup

The first thing I did was to create the folder Backup on the H: drive then I ran the script. When it ran the folder disappeared from the H: drive. Checking the properties of the drive the usage increased by the size of all the files that should have been copied. I searched for the folder on the drive but it could not be found.

Any help?

Thanks
  • +
    0 Votes
    cto

    Please make sure that you have enabled " show hidden files and folders option in windows explorer"

    +
    0 Votes
    lmkk

    Tried showing hidden files even ran a search for the folder and another for some of the files that were copied. None were found

    +
    0 Votes
    ---TK---

    when I ran xcopy /? its showing me that you list your source then destination then the switches....

    xcopy c:\ h:\backup /s /e /d /y /c

    +
    0 Votes
    lmkk

    So what your saying is that I have the switches backward or on the wrong side of the string correct?

    +
    0 Votes
    lmkk

    I tried the line you provided. Oddly enough the same thing happened, the folder disappeared.

    +
    0 Votes
    Jacky Howe

    You have to have the syntax right. :: 'command' 'source directory...' 'destination dir...' Switches' Here are a couple of samples using Variables. The first one will copy data to wherever it is run from.

    @echo off
    :: variables
    set path=%~dp0Backup;%path%
    set drive=%~dp0Backup
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

    %backupcmd% "C:\" "%drive%\"

    ======================================
    @echo off

    :: variables

    set drive=g:\Backup

    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

    echo ### Backing up My Documents...

    %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

    echo ### Backing up Favorites...

    %backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

    echo ### Backing up email and address book (Outlook Express)...

    %backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"

    %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

    echo ### Backing up email and contacts (MS Outlook)...

    %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

    echo ### Backing up the Registry...

    :: if not exist "%drive%\Registry" mkdir "%drive%\Registry"

    :: if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"

    :: regedit /e "%drive%\Registry\regbackup.reg"

    :: use below syntax to backup other directories...

    :: %backupcmd% "...source directory..." "%drive%\...destination dir..."

    echo Backup Complete!
    =============

    Edit: to add a bit

    +
    0 Votes
    lmkk

    I'm not looking to just backup files, but I want a true copy of the files that are on my hard drive. I would like to be able to take my portable hard drive to any computer and have access to any of my files. I'm not sure but the samples you provided look like a backup and not a true copy. Worst yet I'm not that good with batch commands so, ok lets face it I got really lost in the string.
    With the string I used it did copy the files to the drive I wanted, but the folder that I created on that drive disappeared when the command was run. I set folder options to view hidden folders and ran a search for the folder on that drive and it's not there. If I try and make a folder with the same name I get an error saying can not rename folder folder name already exsists.

    +
    0 Votes
    Jacky Howe

    the entire drive you only need to copy the files from the folder that you normally save them into. If you look at the directory structure in the second example you will notice that it will copy the My Documents folder. This batch file will copy the folder and everything that is in it. In say 3 weeks time you need to update your files all you need to do is run the batch file again and it will only copy anything that was added or modified in the source folder.

    @echo off
    :: variables
    set drive=g:\Backup
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
    echo ### Backing up My Documents...
    %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

    or a standalone

    xcopy "%USERPROFILE%\My Documents" "D:\My Documents" /s /c /d /e /h /i /r /k /y

    or if you just have a folder on C: where you save your files to it will look like this.

    xcopy C:\Data "D:\My Documents" /s /c /d /e /h /i /r /k /y

    +
    0 Votes
    lmkk

    You are correct I only really want to save my documents. I was haveing trouble getting it to go into the directory to copy just those files, this might work I'll give it a try.
    Have one item in the string I need clearified first. The "%USERPROFILE% in the string use it as it is or do I put the computer name in there or something like that? For example this is the directory I really would like to copy "C:\Documents and Settings\US\My Documents" is this what should go in "%USERPROFILE%?

    xcopy "%USERPROFILE%\My Documents" "D:\My Documents" /s /c /d /e /h /i /r /k /y

    +
    0 Votes

    Yep

    Jacky Howe

    %USERPROFILE% = C:\Documents and Settings\US and the My Documents is a sub folder so using the commands exactly like this you will have a copy of My Documents.

    xcopy "%USERPROFILE%\My Documents" "D:\My Documents" /s /c /d /e /h /i /r /k /y

    %USERPROFILE% is known as a variable and it is part of the set command. If you open a command prompt and type in set you will see on the left hand side all of the variables that are built in. If you type set /? you will see more information and examples.

    <i>Keep us informed as to your progress if you require further assistance.</i>
    <HR>
    <i>If you think that any of the posts that have been made by all TechRepublic Members, have solved or contributed to solving the problem, please Mark them as <b>Helpful</b> so that others may benefit from the outcome. </i> :-bd

    +
    0 Votes
    lmkk

    Your pervious post did just what I wanted it to do Thanks so much for helping me through this.

    +
    0 Votes
    Jacky Howe

    we all had to start somewhere. I try not to forget that.

  • +
    0 Votes
    cto

    Please make sure that you have enabled " show hidden files and folders option in windows explorer"

    +
    0 Votes
    lmkk

    Tried showing hidden files even ran a search for the folder and another for some of the files that were copied. None were found

    +
    0 Votes
    ---TK---

    when I ran xcopy /? its showing me that you list your source then destination then the switches....

    xcopy c:\ h:\backup /s /e /d /y /c

    +
    0 Votes
    lmkk

    So what your saying is that I have the switches backward or on the wrong side of the string correct?

    +
    0 Votes
    lmkk

    I tried the line you provided. Oddly enough the same thing happened, the folder disappeared.

    +
    0 Votes
    Jacky Howe

    You have to have the syntax right. :: 'command' 'source directory...' 'destination dir...' Switches' Here are a couple of samples using Variables. The first one will copy data to wherever it is run from.

    @echo off
    :: variables
    set path=%~dp0Backup;%path%
    set drive=%~dp0Backup
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

    %backupcmd% "C:\" "%drive%\"

    ======================================
    @echo off

    :: variables

    set drive=g:\Backup

    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

    echo ### Backing up My Documents...

    %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

    echo ### Backing up Favorites...

    %backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

    echo ### Backing up email and address book (Outlook Express)...

    %backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"

    %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

    echo ### Backing up email and contacts (MS Outlook)...

    %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

    echo ### Backing up the Registry...

    :: if not exist "%drive%\Registry" mkdir "%drive%\Registry"

    :: if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"

    :: regedit /e "%drive%\Registry\regbackup.reg"

    :: use below syntax to backup other directories...

    :: %backupcmd% "...source directory..." "%drive%\...destination dir..."

    echo Backup Complete!
    =============

    Edit: to add a bit

    +
    0 Votes
    lmkk

    I'm not looking to just backup files, but I want a true copy of the files that are on my hard drive. I would like to be able to take my portable hard drive to any computer and have access to any of my files. I'm not sure but the samples you provided look like a backup and not a true copy. Worst yet I'm not that good with batch commands so, ok lets face it I got really lost in the string.
    With the string I used it did copy the files to the drive I wanted, but the folder that I created on that drive disappeared when the command was run. I set folder options to view hidden folders and ran a search for the folder on that drive and it's not there. If I try and make a folder with the same name I get an error saying can not rename folder folder name already exsists.

    +
    0 Votes
    Jacky Howe

    the entire drive you only need to copy the files from the folder that you normally save them into. If you look at the directory structure in the second example you will notice that it will copy the My Documents folder. This batch file will copy the folder and everything that is in it. In say 3 weeks time you need to update your files all you need to do is run the batch file again and it will only copy anything that was added or modified in the source folder.

    @echo off
    :: variables
    set drive=g:\Backup
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
    echo ### Backing up My Documents...
    %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

    or a standalone

    xcopy "%USERPROFILE%\My Documents" "D:\My Documents" /s /c /d /e /h /i /r /k /y

    or if you just have a folder on C: where you save your files to it will look like this.

    xcopy C:\Data "D:\My Documents" /s /c /d /e /h /i /r /k /y

    +
    0 Votes
    lmkk

    You are correct I only really want to save my documents. I was haveing trouble getting it to go into the directory to copy just those files, this might work I'll give it a try.
    Have one item in the string I need clearified first. The "%USERPROFILE% in the string use it as it is or do I put the computer name in there or something like that? For example this is the directory I really would like to copy "C:\Documents and Settings\US\My Documents" is this what should go in "%USERPROFILE%?

    xcopy "%USERPROFILE%\My Documents" "D:\My Documents" /s /c /d /e /h /i /r /k /y

    +
    0 Votes

    Yep

    Jacky Howe

    %USERPROFILE% = C:\Documents and Settings\US and the My Documents is a sub folder so using the commands exactly like this you will have a copy of My Documents.

    xcopy "%USERPROFILE%\My Documents" "D:\My Documents" /s /c /d /e /h /i /r /k /y

    %USERPROFILE% is known as a variable and it is part of the set command. If you open a command prompt and type in set you will see on the left hand side all of the variables that are built in. If you type set /? you will see more information and examples.

    <i>Keep us informed as to your progress if you require further assistance.</i>
    <HR>
    <i>If you think that any of the posts that have been made by all TechRepublic Members, have solved or contributed to solving the problem, please Mark them as <b>Helpful</b> so that others may benefit from the outcome. </i> :-bd

    +
    0 Votes
    lmkk

    Your pervious post did just what I wanted it to do Thanks so much for helping me through this.

    +
    0 Votes
    Jacky Howe

    we all had to start somewhere. I try not to forget that.