File copy program that will make a zip archive and automatically send to a network location.

I need some help in finding a program or method:

I have a request from the company that I am working with.  

               
Once a month, make a copy of a network share
               
Send it to another location on the network of choice
               
Delete the contents of the share
               
60 days for copies be available

I wold like to copy the network share and make a zip file.  That zip file would get copied out to another place on the network. If I have zip files, I can easily determine how old the zip archive is and delete it.  After the copy of the zip is done, then delete the contents of the directory.  

The network share is like a holding place for an engineering department, dumping ground.  that is cleaned up every thirty days, but they would like the ability to go back in time and get something from the dump if they have to.

They are working windows 2008R2 file server

Thanks,

Rick Arnold
RickArnoldAsked:
Who is Participating?
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.

NVITCommented:
Hi,

Maybe this can help you.
@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a 
REM    MakeZipArchive.bat below, which zips the files and deletes the contents 
REM    of the share 

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set SrcDir=\\server\share\source
set TgtDir=\\server\share\target

set ZipEXEDir=C:\Program Files\7-Zip

>>"%LogFN%" echo %date% %time% START %0
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
>>"%LogFN%" (move "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%TgtDir%" && rd /s /q "%SrcDir%")
>>"%LogFN%" echo %date% %time% END %0
goto :eof

Open in new window

0
RickArnoldAuthor Commented:
I think we are both on the right track.  I was doing some digging around and came to the same conclusion.  

In the set commands, I am not a programmer, it looks like I need to populate some data.

Thanks,

Rick
0
NVITCommented:
- To make the zip files, you need a 3rd party program like 7-zip (free). Windows doesn't have a built-in command-line zipping functionality

- For the monthly copy, you can setup a Scheduled Task to call the .bat code which zips the files and deletes the contents of the share. It creates a .zip file like 2015_22_04_10_22_AM.zip

The code works for me here.

In the set commands, I am not a programmer, it looks like I need to populate some data.
set SrcDir=\\server\share\source
set TgtDir=\\server\share\target

Open in new window


Change \\server\share\source to your source folder, which has the files.
Change \\server\share\target to your target folder, which will hold the .zip files.

I think 7-zip will install into the "C:\Program Files (x86)" folder. So, you have to edit line 20 accordingly
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

PcGod718Commented:
here is a quick n dirty batch file.  this assumes you have 7z.exe (from 7zip) in the path.
it does NOT auto-delete the source folder/files, but thats an easy mod.
This will zip from the source directory to the destination directory in .zip format.
it will set the filename as networkbackup-TODAYSDATE.zip
All the variables are simple to change from the batch.
This allows you to zip directly to the destination without having to make any redundant copies of files.  As long as none of the source files are locked, you will have a full zip of the current source directory.

:start

@echo off

:init

REM setup date variables
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set todaysdate=%month%-%day%-%year%

REM setup folder variables - Change them to suit your needs
set dirA=C:\sourcefolder
set dirB=C:\destfolder

REM Validate source and destination folders
if not exist "%dirA%" echo "%dirA%" not found! & goto :EOF
if not exist "%dirB%" echo "%dirB%" not found! & goto :EOF

REM visual validation of date (can be removed)
echo .
echo The Year is %year%
echo The Month is %month%
echo The Day is %day%
echo .


echo ..Compressing %dirA% to %dirB%\%todaysdate% ..

7z.exe a -tzip %dirB%\networkbackup-%todaysdate%.zip %dira%

echo.
echo Operation Completed
echo.

pause

:eof
0
RickArnoldAuthor Commented:
NewVillageIT,

Made the Changes  to the script:

This is what happens
               
Source test directory is deleted not put into the zip file
               
A zip file is created, but it is of the desktop of the source system, the Icons however data and time is     on           the directory.
               
The zip file is sent to the destination computer with the date and time.

The data is deleted that works, but the data that is deleted needs to be put inside the zip and sent to the destination.

Thanks very much for help,

This works can you modify to make the data go into the zip file and get transferred to the Source.

Again thanks very much!

Rick
0
RickArnoldAuthor Commented:
PcGod718,

Ran the Bat file and made the changes this is what I got

see the attachment
Capture.PNG
0
RickArnoldAuthor Commented:
PCGod718,

it seemed like it would have worked but it was getting hung up on the EXE.  7- zip is installed on the server.

thanks,

Rick
0
NVITCommented:
@Rick,

If you don't mind posting your code, that would help a lot.
0
RickArnoldAuthor Commented:
NewVillageIT,

here you go thanks very much!

@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a
REM    MakeZipArchive.bat below, which zips the files and deletes the contents
REM    of the share

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

set ZipEXEDir=C:\Program Files\7-Zip

>>"%LogFN%" echo %date% %time% START %0
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "*.*" -r
(>>"%LogFN%" move "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%TgtDir%") && (>>"%LogFN%" del /q "%SrcDir%\*.*")
>>"%LogFN%" echo %date% %time% END %0
goto :eof
0
NVITCommented:
OK. Yeah. You were using an older code. I edited that post. Try this one:

@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a 
REM    MakeZipArchive.bat below, which zips the files and deletes the contents 
REM    of the share 

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

set ZipEXEDir=C:\Program Files\7-Zip

>>"%LogFN%" echo %date% %time% START %0
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
>>"%LogFN%" (move "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%TgtDir%" && rd /s /q "%SrcDir%")
>>"%LogFN%" echo %date% %time% END %0
goto :eof

Open in new window

0
NVITCommented:
This one revised. I removed the MOVE the .zip file. Instead, it makes the .zip directly into TgtDir
@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a 
REM    MakeZipArchive.bat below, which zips the files and deletes the contents 
REM    of the share 

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set ZipEXEDir=C:\Program Files\7-Zip

set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

>>"%LogFN%" echo %date% %time% START %0
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
>>"%LogFN%" (if exist "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" rd /s /q "%SrcDir%")
>>"%LogFN%" echo %date% %time% END %0
goto :eof

Open in new window

0
RickArnoldAuthor Commented:
NewVillageIT,

I am very happy 99% there.  The only thing that BAT file did incorrectly is it deleted the whole, E:\Eng_Sharing_Files on the source.  I really need that file folder intact and only the contents deleted

The first iteration deleted the contents and left the folder intact.  If I can get the contents deleted, we are there.

Thanks again very Much!!!

@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a
REM    MakeZipArchive.bat below, which zips the files and deletes the contents
REM    of the share

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

set ZipEXEDir=C:\Program Files\7-Zip

>>"%LogFN%" echo %date% %time% START %0
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
>>"%LogFN%" (move "%SrcDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%TgtDir%" && rd /s /q "%SrcDir%")
>>"%LogFN%" echo %date% %time% END %0
goto :eof
0
NVITCommented:
@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a 
REM    MakeZipArchive.bat below, which zips the files and deletes the contents 
REM    of the share 

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set ZipEXEDir=C:\Program Files\7-Zip

set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

>>"%LogFN%" echo %date% %time% START %0
if not exist "%SrcDir%\." (
  >>"%LogFN%" echo Missing "%SrcDir%"
  >>"%LogFN%" echo %date% %time% END %0
  goto :eof
)
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
>>"%LogFN%" (if exist "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" rd /s /q "%SrcDir%" && md "%SrcDir%")
>>"%LogFN%" echo %date% %time% END %0
goto :eof

Open in new window

0
PcGod718Commented:
looks like newvillage is getting you where you need to go.
as an aside,   for my Lil script to work,  7z.exe has to be in the path [I usually just copy it into c:\windows],  or a variable can be set in the batch as shown in new village's script.
0
RickArnoldAuthor Commented:
NewVillageIT,

Weird thing happened ran it one worked like a charm.  Ran it again, testing, but the second time it deleted the folder.  Ran it a third time it not delete the folder.  Will do more testing tomorrow.

Thanks very very much for the help!!!!!

@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a
REM    MakeZipArchive.bat below, which zips the files and deletes the contents
REM    of the share

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set ZipEXEDir=C:\Program Files\7-Zip

set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

>>"%LogFN%" echo %date% %time% START %0
if not exist "%SrcDir%\." (
  >>"%LogFN%" echo Missing "%SrcDir%"
  >>"%LogFN%" echo %date% %time% END %0
  goto :eof
)
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
>>"%LogFN%" (if exist "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" rd /s /q "%SrcDir%" && md "%SrcDir%")
>>"%LogFN%" echo %date% %time% END %0
goto :eof
0
NVITCommented:
Hi Rick,

This should do it...
@echo off
REM - To make the zip files, you need a 3rd party program like 7-zip (free).
REM - For the monthly copy, you can setup a Scheduled Task to call a 
REM    MakeZipArchive.bat below, which zips the files and deletes the contents 
REM    of the share 

SETLOCAL ENABLEDELAYEDEXPANSION

set LogFN=%temp%\MakeZipArchive.txt
set ZipEXEDir=C:\Program Files\7-Zip

set SrcDir=E:\Eng_Sharing_Files
set TgtDir=\\Archive\Eng_Data

>>"%LogFN%" echo %date% %time% START %0
if not exist "%SrcDir%\." (
  >>"%LogFN%" echo Missing "%SrcDir%"
  >>"%LogFN%" echo %date% %time% END %0
  goto :eof
)
for /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(Set Day=%%A&Set Month=%%B&Set Year=%%C)
for /F "tokens=1-4 delims=: " %%A in ('time /t') do @(Set HH=%%A&Set MM=%%B&Set AM=%%C)

>>"%LogFN%" "%ZipEXEDir%\7z.exe" a "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" "%SrcDir%\*.*" -r
if exist "%TgtDir%\%Year%_%Month%_%Day%_%HH%_%MM%_%AM%.zip" (
  >>"%LogFN%" echo Cleanup "%SrcDir%"...
  del /s /q "%SrcDir%\*"
  for /d %%a in (%SrcDir%\*) do (rd /s /q "%%a")
)
>>"%LogFN%" echo %date% %time% END %0
goto :eof

Open in new window

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
RickArnoldAuthor Commented:
NewVillageIT,

Many thanks solved a very big problem for me from one very grateful IT guy to another thanks!

Rick Arnold
ArnoldConsult
0
NVITCommented:
You're welcome, Rick. It was fun helping. Take care.
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 Server 2008

From novice to tech pro — start learning today.