Jump to content

Batch file backup and compress


Guest vaderag
 Share

Recommended Posts

Guest vaderag

I've been reading the backup using batch files wiki (http://www.hak5.org/wiki/Backup_Using_Batch_Files) and was wondering if there is a way to do this, but to compress the results of the backup. I know it can be done by compressing with some command like utility and then backing it up, but i want to be able to do it so that it only needs to update the current archive with things that have changed. Is there a way to do that?

Thanks,

andy

Link to comment
Share on other sites

presumably with out looking at the scripts i would say yes, going by what u have said ur only using batch scripts, so it would be able to be done with complements to Winrar Command (included in normal winrar package fow W32)

Edit: Just looked over the back up scripts, this now works ^_^

so pretty much as long as the back up places everythin in a given location, say 'G:Backup' then we are able to make a archive of that folder, example;

set path="C:Program FilesWinRAR";%path%

rar a [Path To Were Rar Will Be Created] [Path To Backup]

rmdir %drive% /S /Q

So If i had my backups made to 'G:Backup' and i wanted to make G:Backup.rar' i would use the code;

@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 DataMicrosoftAddress Book" "%drive%Address Book"

%backupcmd% "%USERPROFILE%Local SettingsApplication DataIdentities" "%drive%Outlook Express"



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

%backupcmd% "%USERPROFILE%Local SettingsApplication DataMicrosoftOutlook" "%drive%Outlook"



echo ### Backing up the Registry...

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

if exist "%drive%Registryregbackup.reg" del "%drive%Registryregbackup.reg"

regedit /e "%drive%Registryregbackup.reg"



echo Backup Complete!



echo Archiving



set path="C:Program FilesWinRAR";%path% 

rar a %drive%.rar %drive%

rmdir %drive% /S /Q



echo Archiving Complete!



@pause

Edited again, i just added the line 'rmdir %drive% /S /Q' pretty much just removes the folder it archives after completion.

Link to comment
Share on other sites

Guest vaderag

Thanks, I figured that it would be easy enough to do that, but wont that mean that it has to copy over everything each time (not just the stuff that has changed?), especially if we're removing the directory?

What I'd like it to do, is to only copy and archive the things that have changed (i.e. not necessarily create a new archive each time?)

Does that make sense?

Link to comment
Share on other sites

Thanks, I figured that it would be easy enough to do that, but wont that mean that it has to copy over everything each time (not just the stuff that has changed?), especially if we're removing the directory?

What I'd like it to do, is to only copy and archive the things that have changed (i.e. not necessarily create a new archive each time?)

Does that make sense?

yes it does.. you want synctoy from Microsoft it's a powertoy and very cool features theres even a way to have it run in the background I'm to tired to Google it right now if you don't find it by the time i get back I'll find it for ya.

Link to comment
Share on other sites

Guest vaderag
Thanks, I figured that it would be easy enough to do that, but wont that mean that it has to copy over everything each time (not just the stuff that has changed?), especially if we're removing the directory?

What I'd like it to do, is to only copy and archive the things that have changed (i.e. not necessarily create a new archive each time?)

Does that make sense?

yes it does.. you want synctoy from Microsoft it's a powertoy and very cool features theres even a way to have it run in the background I'm to tired to Google it right now if you don't find it by the time i get back I'll find it for ya.

Found it, but there doesnt seem to be any archiving/compression capabilities?

Link to comment
Share on other sites

hmm if u still wanna use batch and Winrar, u can simply mod the original back up to do it, also ur right about not copying everythink then adding it to the archive, so ive edited again :P here it is, instead of copying all files to a new folder, it only adds to archive files that have been modified or added to the folders. here we go;

@echo off

:: variables 

set path="C:Program FilesWinRAR";%path% 

set archive=C:Backup.rar 



echo ### Backing up My Documents... 

rar u "%archive%" "%USERPROFILE%My Documents" 



echo ### Backing up Favorites... 

rar u "%archive%" "%USERPROFILE%Favorites"



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

rar u "%archive%" "%USERPROFILE%Application DataMicrosoftAddress Book"

rar u "%archive%" "%USERPROFILE%Local SettingsApplication DataIdentities"



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

rar u "%archive%" "%USERPROFILE%Local SettingsApplication DataMicrosoftOutlook"



echo ### Backing up the Registry... 

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

if exist "%drive%Registryregbackup.reg" del "%drive%Registryregbackup.reg" 

regedit /e "C:regbackup.reg"

rar u "%archive%" "C:regbackup.reg"

del "C:regbackup.reg" /Q



echo Backup Complete!



Pause

Hope this helps.

Link to comment
Share on other sites

Guest vaderag

oh, and just one final question - is there a way to exclude a folder in this? I have my photos folder in my documents, and thats about 9GB in itself, so i'd like it to be excluded. If not, no worries, i'll cope!

Link to comment
Share on other sites

i removed the m3 because on my Machien it wasnt working correctly, just gotta check on somethink with the switch options, as for the exclusion, im rather sure it can be done just need to look into it, which ill be doing now. ill post the new version of the script when ive worked out the bugs ^_^U

Link to comment
Share on other sites

Guest vaderag

Got the exclusion working with a -x"*path*"

Quite strange you need the * before, however it just wouldnt do it without. Guess i'll just have to make sure i dont make a folder called My Pictures as a subfolder of anything else ;)

Link to comment
Share on other sites

Guest vaderag

Right, ok, got one final question now.

Is there a way to check whether outlook or firefox are running at the start of the backup process, and if they are to exit them (or kill the process), since the PST files wont actually backup when outlook is open, and I usually end up going to bed with it open overnight!

Thanks!

EDIT: Hell, i'm getting good at this - solved that one myself too!

taskkill /F /IM firefox.exe /FI "STATUS eq RUNNING"

Link to comment
Share on other sites

Was just wondering if there was a way to do this for unknown drive letters (USB device) as at home my USB device is F: and at college it is either G: or I: (annoying I know).

To clarify, is there any way in a batchfile to pickup an unkown drive letter. I do however know the name of the device when plugged in, 'JUKE BOX' (excluding single quotes).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

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