VFP - Backup strategy

Hi experts !

Do you know a way to fire a backup routine from inside a VFP application ? I've done one but it's unsatisfactory because I could not configure drivers since I use "RUN" - accordingly to the code furnished

*-- Procura os drivers mais prováveis
LOCAL m.drv

m.drv = m.driver + ":" + m.diretor

IF DISKSPACE("E:\") = -1
      IF DISKSPACE("F:\") = -1
            IF DISKSPACE("G:\") = -1
                  IF DISKSPACE("H:\") = -1
                        MESSAGEBOX("Não há disco no Drive H",48,"Erro")
                  ELSE
                        RUN lha u gecc_dbf *.dbf
                        RUN lha u gecc_fpt *.fpt
                        RUN copy C:\livesp\gecc_dbf.lzh H:\
                        RUN copy C:\livesp\gecc_fpt.lzh H:\
                  ENDIF
            ELSE
                  RUN lha u gecc_dbf *.dbf
                  RUN lha u gecc_fpt *.fpt
                  RUN copy C:\livesp\gecc_dbf.lzh G:\
                  RUN copy C:\livesp\gecc_fpt.lzh G:\
            ENDIF
      ELSE
            RUN lha u gecc_dbf *.dbf
            RUN lha u gecc_fpt *.fpt
            RUN copy C:\livesp\gecc_dbf.lzh F:\
            RUN copy C:\livesp\gecc_fpt.lzh F:\
      ENDIF
ELSE
      RUN lha u gecc_dbf *.dbf
      RUN lha u gecc_fpt *.fpt
      RUN copy C:\livesp\gecc_dbf.lzh E:\
      RUN copy C:\livesp\gecc_fpt.lzh E:\
ENDIF

RETURN


Any suggestion ?

Thanks in advance
Eduardo FuerteAsked:
Who is Participating?
 
Olaf DoschkeSoftware DeveloperCommented:
Besides that foxpro has a copy file comand, like Cyril shows, why RUN copy? The Shell.Application will support Zipping the way Cyril shows in Win XP and above. For Win2k and older you may stay with your lha compression.

Bye, Olaf.  

0
 
Eduardo FuerteAuthor Commented:
Ops... before the backup, fired by RUN too,  LHA compress the files....
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
You can use WinZip.

I use Windows API to send DBF files to a zip file.


cSource = ADDBS(SET('PATH')) && This is data path
cDestination = "c\zfoxbackup\20102908.bak"
cTempZip = cTempPath + SYS(3) + '.zip'
oThermometer = CREATEOBJECT('thermometer','Compressing')
DECLARE INTEGER Sleep IN kernel32 INTEGER
IF FILE(cTempZip)
      DELETE FILE (cTempZip)
ENDIF
= STRTOFILE(CHR(80) + CHR(75) + CHR(5) + CHR(6) + REPLICATE(CHR(0),18),cTempZip)
DIMENSION aDBFs(1,5)
nCount = ADIR(aDBFs,cSource+"*.*")
oShell = CREATEOBJECT("Shell.Application")
FOR i = 1 TO nCount
      oThermometer.update(i/nCount*100)
      cFileName = aDBFs(i,1)
      IF UPPER(RIGHT(cFileName,3)) $ "DBF|FPT"
            cFile = cSource + cFileName
            nCount1 = oShell.NameSpace(cTempZip).Items.Count
            oShell.NameSpace(cTempZip).CopyHere(cFile)
            DO WHILE oShell.NameSpace(cTempZip).Items.Count = nCount1
                  = Sleep(1000)
            ENDDO
      ENDIF
ENDFOR
RELEASE oShell
COPY FILE (cTempZip) TO (cDestination)
DELETE FILE (cTempZip)
CLEAR DLLS
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Olaf DoschkeSoftware DeveloperCommented:
Why not let the user choose where to store the backup? Why do you need to autodetect the drive? Also, once you determined which drive, use macro substitution to not have copies of the code for each different drive letter eg

lcDrive = "H:\"
RUN lha u gecc_dbf *.dbf
RUN lha u gecc_fpt *.fpt
RUN copy C:\livesp\gecc_dbf.lzh &lcDrive
RUN copy C:\livesp\gecc_fpt.lzh &lcDrive

A second and more evil problem is, that lha has no chance to know what the current directory is within foxpro. So to compress the gecc table you need to specify the full path to the dbf and fpt. See DBF() on how to get the path of a dbf. Also Sys(5)+Sys(2003) or fullpath(curdir()) will give you the path of the current directory foxpro looks for a file, but lha does not.

Bye, Olaf.
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
You can add the files to be backed up in a text file and then send that text file to a compression utility. I used to do it with pkzip. I am sure there are much newer ones out there.
0
 
Eduardo FuerteAuthor Commented:
Sorry the delay...

Could you please detail

oShell = CREATEOBJECT("Shell.Application")

What could be ?

To make it corecctly runs....
          nCount1 = oShell.NameSpace(cTempZip).Items.Count

By the way it's not strictly necessary to compress the files.

Thanks
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
oShell is invoking the Shell Application which is like working in Windows Explorer so I can move or copy the files into the newly created zip file.

In my code snippet I am copying DBF and FPT files to a zip file. You just wish to copy the files as they are? If yes then use

COPY FILE &cSource TO &cDestination.
0
 
Olaf DoschkeSoftware DeveloperCommented:
Further Explanation: The Shell.Application (The Windows Explorer in fact) does treat a new empty ZIP file as a folder, so you can copy files into it, which actually zips them, that's the trick. You can't do that way of zipping with COPY FILE, but you can also remain with lha or use Craig Boyds VFPCompression FLL, tushar points to. There are several ways to compress files, that's all.

Bye, Olaf.
0
 
Eduardo FuerteAuthor Commented:
Hello

Thanks for all help until now.

I'm probably missing/ misunderstodd  something...

Could you take a look on the picture ?
img-040910.JPG
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
If cTempZip a valid file?

cTempZip is a filename I use in the temporary folder of the user where I create the zip file and then I copy it elsewhere.

So cTempZip = "c:\users\captain\temp\temp.zip" or d:\temp.zip.

If it's not a valid file then the error you are getting is telling you that there was no NameSpace object available for that file.
0
 
Olaf DoschkeSoftware DeveloperCommented:
Efuerte,

which version of Windows are you using?

Bye, Olaf.
0
 
Eduardo FuerteAuthor Commented:
Hello, Olaf - Windows XP

Hello Cyril

I've done some modifications in the code and at least it runs, but something remains obscure to me - the .zip need be created before the process  and the is actualized when program runs ?

(I'm currently using Brazip a Winzip similar)

The archive .bak is created with only 1 KB  - another thing  It's not clear for me the relation between .bak and .zip

Thanks for your patience...

LOCAL cTempZip, cTempPath

cTempZip=""
cTempPath=""

cSource = ADDBS(SET('PATH')) && This is data path

*--cDestination = "c\zfoxbackup\20102908.bak"
*--cTempZip = cTempPath + SYS(3) + '.zip'

cDestination = "c:\geccvfp\20100904.bak"
cTempZip = 'C:\geccvfp\temp'+  '.zip'

*oThermometer = CREATEOBJECT('thermometer','Compressing')
DECLARE INTEGER Sleep IN kernel32 INTEGER
IF FILE(cTempZip)
      DELETE FILE (cTempZip)
ENDIF
= STRTOFILE(CHR(80) + CHR(75) + CHR(5) + CHR(6) + REPLICATE(CHR(0),18),cTempZip)
DIMENSION aDBFs(1,5)
nCount = ADIR(aDBFs,cSource+"*.*")
oShell = CREATEOBJECT("Shell.Application")
FOR i = 1 TO nCount
*      oThermometer.update(i/nCount*100)
      cFileName = aDBFs(i,1)
      IF UPPER(RIGHT(cFileName,3)) $ "DBF|FPT"
            cFile = cSource + cFileName
            nCount1 = oShell.NameSpace(cTempZip).Items.Count
            oShell.NameSpace(cTempZip).CopyHere(cFile)
*!*	            DO WHILE oShell.NameSpace(cTempZip).Items.Count = nCount1
*!*	                  = Sleep(1000)
*!*	            ENDDO
      ENDIF
ENDFOR
RELEASE oShell
COPY FILE (cTempZip) TO (cDestination)
DELETE FILE (cTempZip)
CLEAR DLLS

Open in new window

0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
cTempZip is the temporary place where you are adding the files.
The Final file goes into cDestination.

You can do it in one step and replace cTempZip by cDestination if it has a .zip extention.
0
 
Olaf DoschkeSoftware DeveloperCommented:
Efuerte,

I'm not sure but the Namespace() method of Shell.Application may fail before some SP. But as you got it going, the reason was the file not existing.

Yes, the empty zip must exist before copying to it. As I already said - please read and you'd already got the answer - the ZIP support of the OS (without any Zip programm installed!) handles ZIP files as folders of the file system, therefore an empty zip file is just an empty folder and you can copy to it with the CopeyHere() method of the Shell.Application object.

The StrToFile() line is creating the zip file header that make it a zip file with no content.

Regarding  .bak, sorry, what are you talking about? Cyrils code does not create a .bak file.

Bye, Olaf.
0
 
Olaf DoschkeSoftware DeveloperCommented:
Okay, now I see.

 Cyril has put the final destination as cDestination = "c:\geccvfp\20100904.bak" COPY FILE (cTempZip) TO (cDestination) then copies the zip file and renames it as .bak file at the same time, but nothing changes in the file, it remains a zip.

That's simply a possibility of the COPY FILE command of foxpro, you cannot only determine a folder as the destination but also determine how the copy of a file should be named. To me that's some kind of a quirk, as you can also do something like COPY FILE d:\sourcefolder\*.* to d:\destinationfolder\destinatipn.bak and then would not concatenate all files of the source folder into the destination.bak file, but the destination.bak file would simply be the last file copied, it would be overwritten several times for each file of the source folder. I rather only use COPY FILE with a destination folder, but it's working to name the destination file, if you are sure the source just is one file. And it has the advantage, that the temp.zip can always be named the same, while the destination file could be named according to the date the bakup is made.

You can also define cDEstination as a folder eg cDestination = "c:\geccvfp\" and the COPY FILE program would then simply copy the zip file into that folder as a normal file copy does.

Bye, Olaf.
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
This code that I have supplied exports datasets on my program to a zip file to be give to another user elsewhere in the world.

You may ask why it is written as such:

Thermometer is a custom made progress bar. Some data is big and it takes up to 1 minute to compress.
I use sleep because of Vista. Vista uses so many effects and info while copying and the sleep prevents the timeout. The codes works fine on XP without the sleep.
I copy to a temp folder since the zip utility in Windows has access to the temp folders and Vista and 7 don't fuss about it. At the end I copy the file in the name I wish to the destination.
0
 
Eduardo FuerteAuthor Commented:
Hello

After your replies the logic is much more clear for me and runs very well with Brazip.

The point is since Winzip/ Brazip... demands an authorized copy and I need a solution using a free compression software how could I workaround it ?

1. Do you now any other free file compressor that ressembles WinZip ? (to keep the same logic)
or
2. A suggestion to change the code and logic to permit to use LHA in a suitable manner.

Thanks in advance....
0
 
Olaf DoschkeSoftware DeveloperCommented:
You and users unzipping the zip files don't need Winzip or Brazip. Zip is embedded into Windows since XP.

Bye, Olaf.
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
The code I supplied uses the compression utility of Windows and that is for free. It's like opening a zip folder in Windows Explorer and programatically copying into a zip file.

I never worked with a third party tool on this one. Sorry!
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
You might be interested in these:

Free VFP Compression Library
http://www.tek-tips.com/viewthread.cfm?qid=1284772

How to Add Compression to a VFP Program Without ActiveX, Without $
http://www.tek-tips.com/faqs.cfm?fid=2070
0
 
Eduardo FuerteAuthor Commented:
Clever and elegant solution !

Thanks for all the attention.

(I need to try to guess the driver the user will put his pen drive to copy the .bak so I keep the diskspace part - usually the machines have more than one possibility and every machine "decides" the drive letter)
0
 
Olaf DoschkeSoftware DeveloperCommented:
there is a way to find out which drive is a usb pen drive, take a look at the solutions sample on windows events called "Binding to Windows Message events". Within it you can choose "media events", which means media in the sense of data storage media and it shows how to detect usb drive attaching and detaching.

Also you can check the drivetype() of a drive letter, loop from d to z and see if the drivetype is a removable drive (4). Unfortunately that can also be a network drive.

But last not least, why not let the user simply choose what drive, if you list all driveletters of drivetype 4. Besides that a network drive may also be a good candidate for a backup, it's an external drive in the first place.

Bye, Olaf.
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.