Solved

VFP - Backup strategy

Posted on 2010-08-29
23
840 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Eduardo Fuerte
  • 8
  • 8
  • 6
  • +1
23 Comments
 

Author Comment

by:Eduardo Fuerte
ID: 33553359
Ops... before the backup, fired by RUN too,  LHA compress the files....
0
 
LVL 27

Assisted Solution

by:CaptainCyril
CaptainCyril earned 450 total points
ID: 33553738
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33554180
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
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 50 total points
ID: 33554217
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33555941
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
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 33556261
0
 

Author Comment

by:Eduardo Fuerte
ID: 33575399
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33575626
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33586916
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
 

Author Comment

by:Eduardo Fuerte
ID: 33602701
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33603482
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33603985
Efuerte,

which version of Windows are you using?

Bye, Olaf.
0
 

Author Comment

by:Eduardo Fuerte
ID: 33604710
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33604871
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33605738
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33605763
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33605802
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
 

Author Comment

by:Eduardo Fuerte
ID: 33642394
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33644203
You and users unzipping the zip files don't need Winzip or Brazip. Zip is embedded into Windows since XP.

Bye, Olaf.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33644209
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 33644239
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
 

Author Closing Comment

by:Eduardo Fuerte
ID: 33651276
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33653472
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now