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?
 
Bill PrewCommented:
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
 
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
On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

 
Bill PrewCommented:
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
 
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
 
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 PrewCommented:
Glad that was helpful, thanks.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.