Log in

View Full Version : TUTORIAL: Periodically & automatically backing up an important file to a memcard


Menneisyys
10-28-2006, 06:50 PM
I’ve received (http://pocketpcmag.com/forum/topic.asp?TOPIC_ID=25195) the following question in the Smartphone & Pocket PC Magazine forums:

“I have a HX4700 with a Garmin CF620 Compact Flash GPSr unit.
This unit uses the Garmin QUE software for navigational purposes.
The active track-log is saved in a single file in the installation directory (program files) and on two occasions I've lost the tracklog and almost got myself in an emergancy situation due to either a battery issue or the necessity to do a hard reset.

My question is if you perhaps know of a 3rd party software that I can use to either in real-time or given time intervals mirror / sync the file to the Ipaq file store or external memory .

I'll even be happy if its a program that I have to run to copy the file to another location, then I can at least assign it to a button, and press it every so often.”

The answer to this question is a big YES, you can do this, without having to use a full system backup. What is more, you can do this with a free (!) and fully automatic tool – I’ve custom-written an nScriptm script which does exactly what you want.

I’ve already elaborated a lot on the possible usages of the excellent nScriptm; please see for example this (http://www.pocketpcmag.com/blogs/index.php?blog=3&p=513&more=1&c=1&tb=1&pb=1) and this (http://www.pocketpcmag.com/blogs/index.php?blog=3&p=1201&more=1&c=1&tb=1&pb=1) article, along with the links. (Search for “nScriptm” with Ctrl-F if you don’t want to read the entire article. I, however, as usual, recommend reading these articles in their entirety if you want to know how Pocket PC screenshots can be taken and how calls can be (automatically) recorded.)

To solve the problem asked by my reader, as I've already stated, I’ve written an nScriptm script. It’s available here (http://www.winmobiletech.com/sekalaiset/nscriptm/102006/PeriodicallyBackupAFile.ns) for download. After you edit it to point to the source and the target files (they are \Program Files\source.txt and \SD-MMCard\backup.txt by default; you can, in general, leave the latter filename intact and only change the storage card path), you MUST put it in the \Program Files\ns\ directory (you must create it at first) so that the executable link file, which is available here (http://www.winmobiletech.com/sekalaiset/nscriptm/102006/PeriodicallyBackupAFile.lnk), can find it. You must do the same with the executable file (ns.exe) of nScriptm available here (http://www.winmobiletech.com/sekalaiset/nscriptm/102006/ns.exe) – that is, put it in \Program Files\ns\.

Note that, along with the source and, possibly, the target filenames, you can also modify the interval of the backup. It’s 120 seconds by default. If you want to set it to another value, just modify the parameter in sleep(120).

You can, of course, put the executable link file, PeriodicallyBackupAFile.lnk, to \Windows\Start Menu\Programs for easy access.

Now, just start the backup tool by executing the latter executable link file and minimize nScriptm. It’ll continue running in the background and backing up your file.

Other alternatives

Note that you can also do the same with the excellent SKScheMa (http://www.s-k-tools.com/index.html?skschema/m_skschema.html), which is another product of the excellent S-K people also written (more precisely, ported) nScriptm and a lot of other, high-quality tools like SKTools. With it, you can for example backup your stuff every, say, hour. The advantage of the SKScheMa-based solution that it doesn’t need to be always run in the background. That way, you can lower the CPU / memory usage.

Also, if you know how you can manually add timed, recurring events with, say, SKTools, you can manually execute a simple filecopy (without periodicity – that is, modify script to the following:

function main() {CopyFile("\\Program Files\\source.txt","\\SD-MMCard\\backup.txt");}

and just configure your event queue to execute the link file it, say, every hour.)

For geeks

For programmers or anyone that would like to know how it works and how easy nScriptm is to use, the script is as follows:

function main()
{

while(1<2)
{CopyFile("\\Program Files\\source.txt","\\SD-MMCard\\backup.txt");
sleep(120);}

}

(Note that there is no “true” symbolic constant in nScriptm and, therefore, I couldn’t use while(true) and you must escape backslash characters as with all C-like languages / regexps; this is why there are "doubled" backslash characters.)