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
LVL 7
Jaroslav LatalMSPAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SStoryCommented:
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.
0
Jaroslav LatalMSPAuthor Commented:
Sstory, thanks for quick response. I need to .ZIP large folder from command line, not to sync.

Jarda
0
Bill PrewIT / Software Engineering ConsultantCommented:
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
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

Jaroslav LatalMSPAuthor Commented:
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
0
Bill PrewIT / Software Engineering ConsultantCommented:
You can take action as a result of the z-zip command by using the && and || command piping in DOS.  After a command, if you "chain" another command to it with &&, that second command will only execute if the first command completed successfully.  Similarly following it with another command after || will only execute that command if there was an error.

So you could do something like this, and then take whatever actions you want based on success of failure of the 7-zip command.

7za a -tzip files.zip && (
  echo Backup was successful>mylog.txt
) || (
  echo Backup failed!>mylog.txt
)

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jaroslav LatalMSPAuthor Commented:
Thanks, this is a solution!

Jarda
0
SStoryCommented:
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.
0
Jaroslav LatalMSPAuthor Commented:
Sstoty, thank you too. Unfortunately, I cannot accept your solution since it is already accepted Bill's answer.

Regards,
Jarda
0
Bill PrewIT / Software Engineering ConsultantCommented:
Glad that was helpful, thanks.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.