[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Check Drive and Backup

Check Drive and Backup

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Check Drive and Backup

Postby gavinjb » Mon Aug 17, 2009 8:04 am

Hi,

First for some background info

I run various PocoMAil Clients One on Desktop and One on FlashDrive, but both connect to the same data source (couldn't get Sync to be that reliable on MITG) by using MyDropBox and Portable edition on flash drive.

What I am trying to do is workout how to write a script that will run on Application Quit (that parts easy :) ), that can check if Barca is running on C Drive and if it is to run a backup if not to just quit, does anyone know if this is possible and if so any help would be appreciated as I am not sure even how to start on this.

Thanks,


Gavin
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby MarkB » Tue Aug 18, 2009 4:39 am

The system variable $apppath gives you the path of the install folder of the program that is running the script. Test whether the drive in $apppath is drive C.
Code: Select all
Set $t $apppath
ChopString $t 3 9999
Lowercase $t
If $t = "c:" Then DoStuff
Exit
:DoStuff
MessageBox "This app is installed on drive C."
Exit


Or you could avoid the above by making the Barca on drive C the only one that triggers this particular OnQuit event.

Regarding the backup...
If by "run a backup" you mean the built-in backup/restore facility, there is no good way to automate it. Someone correct me if I'm wrong here. If you mean that you have a third-party synchronization program set up to do this job, you can launch it from your script with an Execute command.

I used to do an automated backup in Poco every morning by having an external program send keystrokes to the Poco UI -- Alt+FBB, the backup path, ENTER (and hope the option settings hadn't changed). This isn't reliable.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby gavinjb » Tue Aug 18, 2009 8:09 am

Hi,

Thanks for the help, I am almost there now, I have decided to create several archives of my emails as 7zip files, so far I have a script that should work but for some reason it fails to run 7zip at the end of the script.

Code: Select all
{### Backup ###}

{ Script will backup AppData to 7Zip file with date/time stamp }

{Please note this script has only been tested on Barca 2 }

{ Usage: intended to be run on Quit Event }

{ Initialize user settings: }
External $userdata1 "7Zip Application.exe" "C:\Program Files\7-Zip\7z.exe"
External $userdata2 "Application Data Path" "C:\Users\Gavin\Documents\My Dropbox\EMail\\"
External $userdata3 "Location to Store Backups" "C:\Users\Gavin\Documents\Email\Backup\\"

{ Check if running from C Drive }
Set $t $apppath
ChopString $t 3 9999
Lowercase $t
If $t = "c:" Then DoStuff
Exit
:DoStuff
{ Get and Format Date for Filename }
GetDate $mydate
SubStrings $mydate "/"
ChopString $mydate "5" "3"

{ Get and Format Time for Filename }
GetTime $mytime
SubStrings $mytime ":"
SubStrings $mytime ":"

{ Create Path }
Set $mypath $userdata3
AddStrings $mypath "BarcaBackup_" $mydate $mytime ".z7"

{ Create string to execute Backup }
Set $apptorun $userdata1
AddStrings $apptorun " a -r " $mypath " " $userdata2 "*.*"

MessageBox $apptorun

{ Run Backup }
Execute $apptorun

Exit


I don't know if Execute will only run Windows commands and not command line apps or if I have something else wrong?

Update: just had a thought that it might be that I do to put " round the paths, but not sure how to do that in PocoScript.

Also does anyone know of an app that can be set to scan a directory and delete all files older than say a week, as if not after a while my backups are going to get out of hand.

With Linux I could use and rm with grep and do it easy, but I dont know of an easy way to do it with Windows, anyone?

Thanks,


Gavin,
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby MarkB » Tue Aug 18, 2009 9:47 am

Change the double backslash at the end of userdata 2 and 3 to single backslash. The extra slash appends a quotation mark to the string.

The Execute command with parameter goes like this
Execute $userdata1 parameter

Execute is temperamental. You're in for a lot of trial and error. One suggestion is that you start by creating a Desktop shortcut to 7zip, with parameters, that does what you want. Then Execute the shortcut.
Code: Select all
Execute C:\Users\Gavin\Desktop\ZipPoco.lnk

If THAT works, then maybe try to formulate a direct Ececute.

You can put quotation mark in a string by escping them:
Code: Select all
AddStrings $t "That's \"kool\""
MessageBox $t
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby gavinjb » Wed Aug 19, 2009 5:11 am

Hi,

Thanks for the info I have used escape characters to put quotes round the paths, but it is still not working.

Does anyone know of anything else I can try or if I can use a shortcut, how I can generate the shortcut with my parameters on the fly and delete it after it has completed.

Code: Select all
{### Backup ###}

{ Script will backup AppData to 7Zip file with date/time stamp }

{Please note this script has only been tested on Barca 2 }

{ Usage: intended to be run on Quit Event }

{ Initialize user settings: }
External $userdata1 "7Zip Application.exe" "C:\Program Files\7-Zip\7z.exe"
External $userdata2 "Application Data Path" "C:\Users\Gavin\Documents\My Dropbox\EMail\\"
External $userdata3 "Location to Store Backups" "C:\Users\Gavin\Documents\Email\Backup\\"

{ Check if running from C Drive }
Set $t $apppath
ChopString $t 3 9999
Lowercase $t
If $t = "c:" Then DoStuff
Exit
:DoStuff
{ Get and Format Date for Filename }
GetDate $mydate
SubStrings $mydate "/"
ChopString $mydate "5" "3"

{ Get and Format Time for Filename }
GetTime $mytime
SubStrings $mytime ":"
SubStrings $mytime ":"

{ Create Path }
Set $mypath "\""
AddStrings $mypath $userdata3 "BarcaBackup_" $mydate $mytime ".z7" "\""

{ Create string to execute Backup }
Set $apptorun "\""
AddStrings $apptorun $userdata1 "\" a -r " $mypath " \" " $userdata2 "*.*\""

MessageBox $apptorun

{ Run Backup }
Execute $apptorun

Exit


I know the command it is generating works, as I have tried running this from a command prompt exactly as the messagebox displays it and it works fine.

Thanks,


Gavin,
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby MarkB » Wed Aug 19, 2009 7:30 am

I don't have 7zip. Here is an example shortcut with two parameters. The shortcut wouldn't have to be deleted after each use -- it could just be stuck out of the way somewhere in your Documents folder.

Target: "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://www.yahoo.com/" "http://www.google.ca/"
Start in: "C:\Program Files (x86)\Mozilla Firefox"

Here is a tested Execute line that accomplishes the same thing as the above shortcut; notice the difference in quotation marks:
Code: Select all
Execute "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://www.yahoo.com/ http://www.google.ca"


Your problem is that one of your parameters contains a space, making your two parameters (in the Execute line) look like three. At the moment, I don't see a solution for that. Anyhow, as I said earlier, Execute is temperamental, and it is entirely normal to resort to having Execute call some external assistance, such as Windows Explorer in the case of the shortcut, or a one-line batch file, etc., to accomplish what Execute is too stubborn and cantankerous to accomplish on its own.

Edit: Spaces are fine in the shortcut because each parameter is enclosed in q. marks.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby gavinjb » Wed Aug 19, 2009 7:40 am

Thanks for the help, I think for the moment I am going to give up on this and give Copian Backup a try as it might be an alternative solution, I was trying to set something up that would not mean installing something else on my Pc, but no joy.
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby MarkB » Wed Aug 19, 2009 7:43 am

Gavin wrote:Execute $apptorun


I'll repeat: An Execute line with a parameter consists of three (3) parts: the word Execute, the file name, the parameter. Your line has just two parts.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby gavinjb » Wed Aug 19, 2009 8:10 am

Sorry I must of miss ready your comments, I now have it working and the script looks as follows

Code: Select all
{### Backup ###}

{ Script will backup AppData to 7Zip file with date/time stamp }

{Please note this script has only been tested on Barca 2 }

{ Usage: intended to be run on Quit Event }

{ Initialize user settings: }
External $userdata1 "7Zip Application.exe" "C:\Program Files\7-Zip\7z.exe"
External $userdata2 "Application Data Path" "C:\Users\Gavin\Documents\My Dropbox\EMail\\"
External $userdata3 "Location to Store Backups" "C:\Users\Gavin\Documents\Email\Backup\\"

{ Check if running from C Drive }
Set $t $apppath
ChopString $t 3 9999
Lowercase $t
If $t = "c:" Then DoStuff
Exit
:DoStuff
{ Get and Format Date for Filename }
GetDate $mydate
SubStrings $mydate "/"
ChopString $mydate "5" "3"

{ Get and Format Time for Filename }
GetTime $mytime
SubStrings $mytime ":"
SubStrings $mytime ":"

{ Create Path }
Set $mypath "\""
AddStrings $mypath $userdata3 "BarcaBackup_" $mydate $mytime ".7z" "\""

{ Create string to execute Backup }
Set $apptorun "\""
AddStrings $apptorun $userdata1 "\""
Set $args "a -r "
AddStrings $args $mypath " \"" $userdata2 "*.*\""

{ Run Backup }
 Execute $apptorun $args

Exit


I could probably rewrite some bits of it to be a bit more efficient, but it works so I will leave it at that.


Thanks for your help,



Gavin,
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby MarkB » Wed Aug 19, 2009 10:19 am

You're a better man than I am, Gavin. :oops:

Let me slip in an undiscombobulating illustration, in case someone searches for help on this subject.

Execute - Double Parameter
Code: Select all
Execute "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://www.yahoo.com/ http://www.google.ca"


Execute - Double Parameter - One Parameter Contains a Space
Code: Select all
Execute "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://www.yahoo.com/ \"C:\Users\Mark\Desktop\test doc.txt\""


(That's test doc.txt.)
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 0 guests

cron