Link to home
Start Free TrialLog in
Avatar of Jaroslav Latal
Jaroslav LatalFlag for Czechia

asked on

zip backup script

Dear experts,

I spent  several hours searching for suitable method of data backup.
One of my customers needs to offsite backup 100GB folder with thousands of small files. I decided to daily zip and copy over the internet.
Windows Server 2008, unfortunately, I cannot upgrade PowerShell to 3.0.

I found few ways to do it:
- 7zip command line, but there is not possible to modify log output.
- PowerShell "write-zip" from PowerShell Comunity Extension, but it is terribly slow.


Any ideas?

Regards,
Jarda
Avatar of SStory
SStory
Flag of United States of America image

Beyond Compare(http://www.scootersoftware.com/) software is really awesome and can do a sync between two folders, even if one is an FTP site. You could buy it and then run a sync each day to get the differences. That would work unless you are wanting multiple backup copies, in which case each would need to be a separate backup and syncing would do little good.  The bottom line is that if you just need a single copy offsite, syncing is better than copying because you only copy what is different. There is also robocopy.exe.
Avatar of Jaroslav Latal

ASKER

Sstory, thanks for quick response. I need to .ZIP large folder from command line, not to sync.

Jarda
Avatar of Bill Prew
Bill Prew

With 7zip you should be able to do this.  You can redirect the "log" via standard DOS redirection, so something like this:

7za a -tzip files.zip *.* >mylog.txt 2>&1


~bp
Hi Bill,

You are absolutely right with 7za a -tzip files.zip *.* >mylog.txt
In this particular folder are thousands of small files, so MyLog.txt will be messed up with thousands of Compressing  FolderExample\File0001.jpg

I just need "backup is OK" Info in MyLog.txt


Regards,
Jarda
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, this is a solution!

Jarda
Well as mentioned above you can redirect standard error
2>mylog.txt and not redirect other messages. Then your log would only include the errors.

I suppose you could write a batch file and test the errorlevel, i.e. exit code of the 7zip command and decide to output
"backup is OK", or NOT

Here are the Possible Exit codes from 7zip
0      No error
1      Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
2      Fatal error
7      Command line error
8      Not enough memory for operation
255      User stopped the process

So if errorlevel=0 it is good....


Example:
@ECHO OFF
CALL put your 7zip command here
IF ERRORLEVEL 0 GOTO BACKUP_OK
REM Backup is not OK

REM write message to screen
echo Backup is not OK

REM append to log file
echo Backup is not OK >>mylog.txt

:BACKUP_OK
GOTO END_ALL

:END_ALL


Put the above in a .bat file and run that.  You can redirect errors using the 2>backuperrs.log method with the 7zip call, or whatever.
I haven't tested this, but assuming that 7ZIP does report exitcodes correctly, it should work.
Sstoty, thank you too. Unfortunately, I cannot accept your solution since it is already accepted Bill's answer.

Regards,
Jarda
Glad that was helpful, thanks.

~bp