Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need backup/restore script

51 views
Skip to first unread message

M.L.

unread,
Nov 7, 2011, 1:40:27 PM11/7/11
to

I need a backup script that allows me to backup the Documents, Desktop
and Favorites folders for each account on a Vista/Win 7 system
(assuming they use the same directory paths). If possible, I'd like it
to be usable for XP. Otherwise I'd like tips on modifying the script
to be used for a separate XP script.

All the backup scripts I've found via Google only allow backup to the
current %USERPROFILE% account. I'd like to feed the script the
external backup directory path, and the account names of specific
users I'd like to backup. Then I want the script to create separate
backup subfolders for each given account name to store their backup
into.

The restore process could be either a flag within the backup script
that performs the same process by reversing the output directories, or
it could simply be a separate script altogether.

I'd like to use it as a one-time backup/restore before reinstalling
Windows on a single self-contained computer, so there is no need for
incremental or differential backup processing, no need for scheduling
and no need for network processing. Any help toward my goal will be
greatly appreciated. Thanks.

foxidrive

unread,
Nov 7, 2011, 2:36:35 PM11/7/11
to
On 8/11/2011 05:40, M.L. wrote:
>
> I need a backup script that allows me to backup the Documents, Desktop
> and Favorites folders for each account on a Vista/Win 7 system
> (assuming they use the same directory paths). If possible, I'd like it
> to be usable for XP. Otherwise I'd like tips on modifying the script
> to be used for a separate XP script.
>
> The restore process could be either a flag within the backup script
> that performs the same process by reversing the output directories, or
> it could simply be a separate script altogether.

> I'd like to use it as a one-time backup/restore before reinstalling
> Windows on a single self-contained computer,

Batch files are helpful for recurring tasks, and complicated once-off tasks.

Your backup task is a once-off file copy, with backup permissions, and isn't really suited for a batch file where you have to write it and test it to see if it functions correctly - and then throw it away.


If you want to go ahead, you need to parse the user list folder, and reject the standard system folders, and then xcopy from the rest of the user folders after prepending the user name. You will probably also need to run under an account with backup permissions.

This is something I had squirreled away - the tests will need to be changed from NT to Win7 and the copy destination/target changed, and some logic to ignore the system folders.

I don't think it is tested.


@echo off
:: reads serverlist.txt - one server\share per line in \\mypc\c format
:: copies non-hidden/system favorites from
:: c:\windows\profiles\user\favorites\
:: and
:: c:\Documents and Settings\user\favorites\
:: to the local drive, and recreates the folder structure
:: using the c:\server\share\ as the container for that machines items.
:: IE: for \\mypc\c it will place all favorites in c:\mypc\c\windows\blah blah\

:: additionally will read extlist.txt and copies all files matching the filespecs
:: one filespec per line
:: into the \\server\share container, maintaining folder structure.


for /f "delims=" %%z in (serverlist.txt) do (
echo server "%%~dpz"

if exist "%%~dpz\windows\profiles\" (
echo NT
for /f "delims=" %%a in ('dir "%%~dpz\windows\profiles\" /b /ad') do (
for /f "delims=" %%b in ('dir "%%~dpz\windows\profiles\%%a\favorites\" /b /ad') do (
xcopy /x /h /e /r /k /f /c "%%~dpz\windows\profiles\%%a\favorites\%%b" "C:\%%~pz\windows\profiles\%%a\favorites\%%b\")
)
)

if exist "%%~dpz\Documents and Settings\" (
echo W2K/XP
for /f "delims=" %%a in ('dir "%%~dpz\Documents and Settings\" /b /ad') do (
for /f "delims=" %%b in ('dir "%%~dpz\Documents and Settings\%%a\favorites\" /b /ad') do (
xcopy /x /h /e /r /k /f /c "%%~dpz\Documents and Settings\%%a\favorites\%%b" "C:\%%~pz\Documents and Settings\%%a\favorites\%%b\")
)
)


for /f "delims=" %%a in (extlist.txt) do (
for /f "delims=" %%b in ('dir "%%~dpz\%%a" /b /s /a-d') do (
xcopy /x /h /r /k /f /c "%%b" "c:\%%~pb")
)

)




--
Regards,
Mic

foxidrive

unread,
Nov 7, 2011, 3:11:41 PM11/7/11
to
On 8/11/2011 06:36, foxidrive wrote:
> On 8/11/2011 05:40, M.L. wrote:
>>
>> I need a backup script that allows me to backup the Documents,
>> Desktop and Favorites folders for each account on a Vista/Win 7
>> system (assuming they use the same directory paths). If possible,
>> I'd like it to be usable for XP. Otherwise I'd like tips on
>> modifying the script to be used for a separate XP script.
>>
>> The restore process could be either a flag within the backup
>> script that performs the same process by reversing the output
>> directories, or it could simply be a separate script altogether.
>
>> I'd like to use it as a one-time backup/restore before
>> reinstalling Windows on a single self-contained computer,
>
> Batch files are helpful for recurring tasks, and complicated once-off
> tasks.
>
> Your backup task is a once-off file copy, with backup permissions,
> and isn't really suited for a batch file where you have to write it
> and test it to see if it functions correctly - and then throw it
> away.
>
>
> If you want to go ahead, you need to parse the user list folder, and
> reject the standard system folders, and then xcopy from the rest of
> the user folders after prepending the user name. You will probably
> also need to run under an account with backup permissions.

Here's a basic framework you can use to backup, perhaps (untested). It only echos the commands atm.

@echo off
if exist "%systemdrive%\users\" set source="%systemdrive%\users"
if exist "%systemdrive%\Documents and Settings\" set source="%systemdrive%\Documents and Settings"

for /f "delims=" %%a in ('dir %source% /b /ad') do (
for %%b in (
"UpdatusUser"
"NetworkService"
"LocalService"
) do if "%%a"=="%%~b" goto :EOF

echo %%a
echo xcopy /x /h /e /r /k /f /c "%source%\%%a\favorites\*.*" "z:\%%a\favorites\"
echo xcopy /x /h /e /r /k /f /c "%source%\%%a\desktop\*.*" "z:\%%a\desktop\"

)







--
Regards,
Mic


M.L.

unread,
Nov 7, 2011, 4:07:25 PM11/7/11
to
Thank you for your prompt reply. Before I test your script, I'd like
to know what the UpdatusUser, NetworkService and LocalService
variables are doing. I only want to backup the
Documents/Desktop/Favorites folders and not those related to the
current Windows system install.

foxidrive

unread,
Nov 7, 2011, 4:13:31 PM11/7/11
to
They are users in XP that you don't want to backup. You may find more in Win7 that you need to exclude.

The script is not complete, nor will it do anything but show you the users/xcopy commands with echo statements.




--
Regards,
Mic

M.L.

unread,
Nov 8, 2011, 10:39:16 PM11/8/11
to
Thanks foxdrive. So the script scans and saves all specified accounts
folders except UpdatusUser, NetworkService and LocalService?

At best I'd like to specify to save for specific users such as John,
Mary, and Owner, then skip the All Users, Default User XP accounts, as
well as the Default and Public Vista/Win7 accounts.

foxidrive

unread,
Nov 8, 2011, 11:21:02 PM11/8/11
to
On 9/11/2011 14:39, M.L. wrote:

> Thanks foxdrive. So the script scans and saves all specified accounts
> folders except UpdatusUser, NetworkService and LocalService?

Yep.

> At best I'd like to specify to save for specific users such as John,
> Mary, and Owner, then skip the All Users, Default User XP accounts, as
> well as the Default and Public Vista/Win7 accounts.

You could have copied them all in the time it has taken to post these messages. :)


I suspect your task has more to it than you have stated. It's not just two machines, is it??



--
Regards,
Mic

M.L.

unread,
Nov 9, 2011, 10:53:26 AM11/9/11
to
Sorry for previously misspelling your screen name, foxidrive.

I'm not understanding the nature of your suspicion. I simply want a
generic single script or separate multiple scripts that allows me to
save specific folders for specific accounts on XP/Vista/Win7 systems
so that I can safely reinstall those systems without losing important
document and configuration data.

I want to feed the script the account names and destination folder,
then let the script create the necessary subfolders for each account.
No networking, no scheduling and no incremental backup processing
needed. Just copying.

There is no more to my task than what I've stated above.

BTW, I've found free software that appears to do what I need called
Backup Utility.
http://www.addictivetips.com/windows-tips/create-backup-of-windows-user-profile-folders-with-backup-utility

It backs up one account at a time. My only concern is that I think
executing a script would be more reliable than installing an app if
the system is unstable.

foxidrive

unread,
Nov 9, 2011, 11:05:39 AM11/9/11
to
On 10/11/2011 02:53, M.L. wrote:
>
>
>>> Thanks foxdrive. So the script scans and saves all specified accounts
>>> folders except UpdatusUser, NetworkService and LocalService?
>>
>> Yep.
>>
>>> At best I'd like to specify to save for specific users such as John,
>>> Mary, and Owner, then skip the All Users, Default User XP accounts, as
>>> well as the Default and Public Vista/Win7 accounts.
>>
>> You could have copied them all in the time it has taken to post these messages. :)
>
>> I suspect your task has more to it than you have stated. It's not just two machines, is it??
>
> Sorry for previously misspelling your screen name, foxidrive.

No problemo.

> I'm not understanding the nature of your suspicion. I simply want a
> generic single script or separate multiple scripts that allows me to
> save specific folders for specific accounts on XP/Vista/Win7 systems
> so that I can safely reinstall those systems without losing important
> document and configuration data.


This is what I saw in your original post.

> I'd like to use it as a one-time backup/restore before reinstalling Windows on a single self-contained computer


> I want to feed the script the account names and destination folder,
> then let the script create the necessary subfolders for each account.
> No networking, no scheduling and no incremental backup processing
> needed. Just copying.
>
> There is no more to my task than what I've stated above.

Except it's not a one time backup on a single computer.



--
Regards,
Mic

Todd Vargo

unread,
Nov 10, 2011, 4:55:05 PM11/10/11
to
For one time backup/reinstall/restore process, I would just select the
individual account folders and drag&drop them on the backup drive. Perform
the OS reinstall and then follow the same process to restore. There is not
much point in sinking a lot of time in writing and testing code for a
one-time task when drag&drop works just as well.

M.L.

unread,
Nov 10, 2011, 8:33:37 PM11/10/11
to


>> I need a backup script that allows me to backup the Documents, Desktop
>> and Favorites folders for each account on a Vista/Win 7 system
>> (assuming they use the same directory paths). If possible, I'd like it
>> to be usable for XP. Otherwise I'd like tips on modifying the script
>> to be used for a separate XP script.

>For one time backup/reinstall/restore process, I would just select the
>individual account folders and drag&drop them on the backup drive. Perform
>the OS reinstall and then follow the same process to restore. There is not
>much point in sinking a lot of time in writing and testing code for a
>one-time task when drag&drop works just as well.

I understand your point, but still I thought a script would be nice to
automate that task.

M.L.

unread,
Nov 10, 2011, 8:37:37 PM11/10/11
to


>>> I suspect your task has more to it than you have stated. It's not just two machines, is it??

>> I'm not understanding the nature of your suspicion. I simply want a
>> generic single script or separate multiple scripts that allows me to
>> save specific folders for specific accounts on XP/Vista/Win7 systems
>> so that I can safely reinstall those systems without losing important
>> document and configuration data.

>This is what I saw in your original post.
>
>> I'd like to use it as a one-time backup/restore before reinstalling Windows on a single self-contained computer

>> I want to feed the script the account names and destination folder,
>> then let the script create the necessary subfolders for each account.
>> No networking, no scheduling and no incremental backup processing
>> needed. Just copying.
>>
>> There is no more to my task than what I've stated above.
>
>Except it's not a one time backup on a single computer.

Sorry for not making myself clear.

M.L.

unread,
Dec 13, 2011, 11:35:36 AM12/13/11
to


>> I need a backup script that allows me to backup the Documents, Desktop
>> and Favorites folders for each account on a Vista/Win 7 system
>> (assuming they use the same directory paths). If possible, I'd like it
>> to be usable for XP. Otherwise I'd like tips on modifying the script
>> to be used for a separate XP script.
>>
>> The restore process could be either a flag within the backup script
>> that performs the same process by reversing the output directories, or
>> it could simply be a separate script altogether.
>
>> I'd like to use it as a one-time backup/restore before reinstalling
>> Windows on a single self-contained computer,

Thanks to Foxdrive and all others who replied. With additional help, I
settled on the following script. It doesn't restore. For some reason
xcopy demanded a double set of quotes to accommodate a quoted account
name.

@echo off
REM Account names must be separated by a space.
REM User must set backup directory drive path.

setlocal
set drive=k:\Backups\test
set backupcmd=xcopy /s /c /d /e /i /r /y

if exist "c:\users" goto startvis7
if exist "c:\documents and settings\" goto startxp

:startxp
for %%a in ("Default User" Owner) do (
if exist "c:\documents and settings\%%a" (
echo ### Backing up XP Desktop for %%a...
%backupcmd% ""c:\documents and settings\%%a\desktop""
""%drive%\%%a\desktop""
echo ### Backing up XP Favorites for %%a...
%backupcmd% ""c:\documents and settings\%%a\favorites""
""%drive%\%%a\favorites""
echo ### Backing up XP My Documents for %%a...
%backupcmd% ""c:\documents and settings\%%a\my documents""
""%drive%\%%a\my documents""
) else (echo ### Account %%a not found.)
)
goto eof

:startvis7
for %%a in ("Default User" Owner) do (
if exist "c:\users\%%a" (
echo ### Backing up Vista/7 Desktop for %%a...
%backupcmd% ""c:\users\%%a\desktop"" ""%drive%\%%a\desktop""
echo ### Backing up Vista/7 Documents for %%a...
%backupcmd% ""c:\users\%%a\documents"" ""%drive%\%%a\documents""
echo ### Backing up Vista/7 Favorites for %%a...
%backupcmd% ""c:\users\%%a\favorites"" ""%drive%\%%a\favorites""
echo ### Backing up Vista/7 Music for %%a...
%backupcmd% ""c:\users\%%a\music"" ""%drive%\%%a\music""
echo ### Backing up Vista/7 Pictures for %%a...
%backupcmd% ""c:\users\%%a\pictures"" ""%drive%\%%a\pictures""
echo ### Backing up Vista/7 Videos for %%a...
%backupcmd% ""c:\users\%%a\videos"" ""%drive%\%%a\videos""
) else (echo ### Account %%a not found.)
)
:eof

echo Backup Complete!
@pause
endlocal

Todd Vargo

unread,
Dec 13, 2011, 12:51:59 PM12/13/11
to
In your code, the %%a in the 'if exist' line would expand to this...
if exist "c:\documents and settings\"Default User"" (

and in the 'backupcmd' line to this...
%backupcmd% ""c:\documents and settings\"Default User"\desktop""
""%drive%\"Default User"\desktop""

To avoid this mess, you simply add a ~ to %%a remove the quotes like this...
if exist "c:\documents and settings\%%~a" (

and like this...
%backupcmd% "c:\documents and settings\%%~a\desktop"
"%drive%\%%~a\desktop"


--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

M.L.

unread,
Dec 14, 2011, 7:27:18 AM12/14/11
to
Thanks Todd, that worked perfectly. Don't understand why it works, but
it certainly does.

Todd Vargo

unread,
Dec 14, 2011, 4:41:15 PM12/14/11
to
On 12/14/2011 7:27 AM, M.L. wrote:
<snip>
>>> :startxp
>>> for %%a in ("Default User" Owner) do (
>>> if exist "c:\documents and settings\%%a" (
>>> echo ### Backing up XP Desktop for %%a...
>>> %backupcmd% ""c:\documents and settings\%%a\desktop""
>>> ""%drive%\%%a\desktop""
>>
>> In your code, the %%a in the 'if exist' line would expand to this...
>> if exist "c:\documents and settings\"Default User"" (
>>
>> and in the 'backupcmd' line to this...
>> %backupcmd% ""c:\documents and settings\"Default User"\desktop""
>> ""%drive%\"Default User"\desktop""
>>
>> To avoid this mess, you simply add a ~ to %%a remove the quotes like this...
>> if exist "c:\documents and settings\%%~a" (
>>
>> and like this...
>> %backupcmd% "c:\documents and settings\%%~a\desktop"
>> "%drive%\%%~a\desktop"
>
> Thanks Todd, that worked perfectly. Don't understand why it works, but
> it certainly does.

Type the following command at prompt for details.

FOR/?|MORE
0 new messages