Jump to content

Win7x86 Batch File Backup


Recommended Posts

I'd appreciate constructive criticism on my little xcopy .cmd batch files below. I made it myself as a batch file I can run real quick before I go to bed or whatever every night. I realize that there is other software to take an image of the whole drive that would be a lot more thorough, but I'm mainly looking at just doing a quick "incremental" backup here and there which would only check for files that have changed since the last backup (based on the archive bit being set to 1 = A or 0 = N).

The file names of each of the 10 files are numbered 0 through 9. Just look at the first character of the names (like 1ExportRegistry.cmd for example). I removed my username from the script and replaced it with "ROCKHPC". My computer's name is Snowflake. My OS is Win 7 x86.

I realize some of the system files in the WINDOWS folder and whatnot which are running probably wouldn't copy properly. I figure that as long as the system being restored with this backup was at least up to date with windows 7 service pack 1 and all the same updates, it would come out right. I'm not sure.

So here's the problem: With the below script, I ended up only backing up 16.8 GB when it should have been closer to 70 GB. It totally skipped my C:\users\ROCKHPC\ folder which is 52.1 GB and contains most of the stuff that's really important (and changes most frequently) which probably happened because my documents/pictures/videos/other important folders are under my admin account. I was wondering what would be the best way to "xcopy" my music and pictures and whatnot out of my user folder. I am the only user on this computer, but also the administrator account.

Here it is, and by the way it all executes and runs properly and smoothly. It just doesn't catch "locked/restricted/protected" folders like I actually want it to. That's what I'm asking about, here. Thanks for reading!

0 here's the one that initiates everything

Code:

@echo off
title "Snowflake System Backup In 9 Steps"

Start "Step 1: Export Registry Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\1ExportRegistryData.cmd"
echo Step 1 Completed!
echo.

Start "Step 2: Assure Registry Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\2AssureRegistryData.cmd"
echo Step 2 Completed!
echo.

Start "Step 3: Assure Downloads Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\3AssureDownloadsData.cmd"
echo Step 3 Completed!
echo.

Start "Step 4: Assure Drivers Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\4AssureDriversData.cmd"
echo Step 4 Completed!
echo.

Start "Step 5: Assure Program Files Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\5AssureProgramFiles.cmd"
echo Step 5 Completed!
echo.

Start "Step 6: Assure ProgramData Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\6AssureProgramData.cmd"
echo Step 6 Completed!
echo.

Start "Step 7: Assure User Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\7AssureUserData.cmd"
echo Step 7 Completed!
echo.

Start "Step 8: Assure Windows Data" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\8AssureWindowsData.cmd"
echo Step 8 Completed!
echo.

Start "Step 9: Assure You!" /wait "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\9AssureYou.cmd"
echo Step 9 Completed!
echo.
echo.
echo.
echo.
echo.

echo Hit any Key to close Snowflake System Backup In 9 Steps!
echo.
echo.
pause

exit


1
Code:

@echo off
title "Step 1: Export Registry Data"

reg export HKLM HKLMbackup.reg /y
echo HKLM Exported Successfully!
echo.
reg export HKCU HKCUbackup.reg /y
echo HKCU Exported Successfully!
echo.
reg export HKCR HKCRbackup.reg /y
echo HKCR Exported Successfully!
echo.
reg export HKU HKUbackup.reg /y
echo HKU Exported Successfully!
echo.
reg export HKCC HKCCbackup.reg /y
echo HKCC Exported Successfully!
echo.
exit


2
Code:

@echo off
title "Step 2: Assure Registry Data"

xcopy /M /E /I /Q /H /Y "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\HKLMbackup.reg" "D:\SnowflakeBackup\Registry"
xcopy /M /E /I /Q /H /Y "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\HKCUbackup.reg" "D:\SnowflakeBackup\Registry"
xcopy /M /E /I /Q /H /Y "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\HKCRbackup.reg" "D:\SnowflakeBackup\Registry"
xcopy /M /E /I /Q /H /Y "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\HKUbackup.reg" "D:\SnowflakeBackup\Registry"
xcopy /M /E /I /Q /H /Y "C:\Users\ROCKHPC\Desktop\Documents\SnowflakeBackup\HKCCbackup.reg" "D:\SnowflakeBackup\Registry"

exit


3
Code:

@echo off
title "Step 3: Assure Downloads Data"

xcopy /M /E /I /Q /H /Y "C:\Downloads" "D:\SnowflakeBackup\Downloads"

exit


4
Code:

@echo off
title "Step 4: Assure Drivers Data"

xcopy /M /E /I /Q /H /Y "C:\drivers" "D:\SnowflakeBackup\drivers"

exit


5
Code:

@echo off
title "Step 5: Assure Program Files Data"

xcopy /M /E /I /Q /H /Y "C:\Program Files" "D:\SnowflakeBackup\Program Files"

exit


6
Code:

@echo off
title "Step 6: Assure ProgramData Data"

xcopy /M /E /I /Q /H /Y "C:\ProgramData" "D:\SnowflakeBackup\ProgramData"

exit


7
Code:

@echo off
title "Step 7: Assure User Data"

xcopy /M /E /I /Q /H /Y "C:\Users" "D:\SnowflakeBackup\Users"
echo UBER FAIL - DOES NOT COPY ANYTHING (USEFUL)

exit


8
Code:

@echo off
title "Step 8: Assure Windows Data"

xcopy /M /E /I /Q /H /Y "C:\Windows" "D:\SnowflakeBackup\Windows"

exit


9
Code:

@echo off
title "Step 9: Assure You!"

echo Your Backup Is Completed And Your Data Is Safe!
echo.
echo Hit Any Key To Close This Window!
Echo.
pause
exit

Edited by Tripredacus
code tags
Link to comment
Share on other sites


I would use robocopy instead of xcopy to have good logging options and better choice for incrementals copies (for example filtering). Also the "/B" switch of robocopy might help copying some more files.

Edited by allen2
Link to comment
Share on other sites

Does your win7 has only one user (you)? The problem you are having is most likely to occur because you lack authority. Even if you are an admin, you cannot access some files because they are owned by microsoft, wheather there are in use or not.

Try studying takeown and icacls commands and try your batch again.

Link to comment
Share on other sites

I am the only account (other than the 'safe mode' Administrator account which I obviously renamed to some strange set of characters) on the computer - and yes I am in the "Administrators" group as well. The thing is that windows 7 automatically runs in less-than-administrator mode by default most of the time, so that's probably what has me locked out. I was thinking that if I saved all my pictures/music/documents and stuff on another partition and just accessed them there, I wouldn't be having this problem. It's probably best to have 1 partition (like 25 or 30 GB maybe) for the system files and OS (WINDOWS folder and whatnot) and another partition for user files. That would probably make the backup a lot easier. Comments?

I'll take a look at your commands anyway when I get time, Hybrid. I haven't really taken a look yet.

Edited by tyraelshammer777
Link to comment
Share on other sites

I was thinking that if I saved all my pictures/music/documents and stuff on another partition and just accessed them there, I wouldn't be having this problem.

Highly unlikely. If you can't copy them from where they are now, the same result would apply if they were on any other partition/drive.

It's probably best to have 1 partition (like 25 or 30 GB maybe) for the system files and OS (WINDOWS folder and whatnot) and another partition for user files. That would probably make the backup a lot easier.

No the best choice because:

1. windows 7 uses approx 8GB of space. Once you'll update the system, the size will increase drastically. Plus (depending on your settings and usage): hibernation file/page file size/programs and games/temporary files (ex: extracting an 4 gb file with winrar)/logs and memory dumps (I've seen dmps of 500mb) . Think carefully.

Unless you want to learn how to move system folders from one drive to another and correct their paths in the registry, i would recommend that you do not try to install a programs/games on another partition. The reason is simple: it will be installed in both places (half on program files in c: and other parts in your defined drive).

Beside the ownership problem, xcopy could also not copy folders because they have spaces.

xcopy /M /E /I /Q /H /Y "C:\Program Files" --> only program files is enclosed in quotes. I'm thinking, if it reaches a folder in program files with spaces, then it'll skip that folder and move to the next. Just a theory.

Perhaps a loop would be better:

for /f "tokens=*" %%a in ('dir/b/ad "%programdata%"') do (

robocopy.exe /e "%%a" SOMEWHERE>nul 2>&1

)

and see how it goes. i hope this is the correct syntax for robocopy.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...