A couple of links to set the scene, one from 2004, the other from 2005. Their titles relate to this post, although their content doesn't really.
While Pharo is an immersive interactive programming environment, it can also be used for operating system command line-oriented scripting. Take a freshly downloaded standard Pharo 4 image, here renamed p4cli.image:
Let's see how to use NBSQLite3's online backup functionality to back up a live SQLite database through a Pharo script.
% pharo -vm-display-null p4cli.image --list Currently installed Command Line Handlers: Fuel Loads fuel files config Install and inspect Metacello Configurations from the command line save Rename the image and changes file update Load updates printVersion Print image version st Loads and executes .st source files test A command line test runner clean Run image cleanup eval Directly evaluates passed in one line scripts
Firstly, install the current bleedingEdge version of NBSQLite3.
Now make a script of the backup code snippet seen in my previous blog post, changing the database file names. In this case, I am using the script to make a copy of my server's firewall log database, which is live and constantly updated by the logging daemon. The script is named 'sqlitebackup.st'.
% pharo -vm-display-null p4cli.image config \ http://www.smalltalkhub.com/mc/Pharo/MetaRepoForPharo40/main \ ConfigurationOfNBSQLite3 --install=bleedingEdge 'Installing ConfigurationOfNBSQLite3 bleedingEdge' Loading 1.2 of ConfigurationOfNBSQLite3... Fetched -> NBSQLite3-Core-PierceNg.7 --- ... ... ... ...finished 1.2% %
Run the script under Unix "time":
% time pharo -vm-display-null p4cli.image st --quit sqlitebackup.st pharo -vm-display-null p4cli.image st --quit sqlitebackup.st 0.26s user 0.10s system 53% cpu 0.675 total % ls -l /var/log/ulog/ulogd.db* /tmp/*.db -rw-r--r-- 1 pierce pierce 11636736 May 17 20:49 /tmp/ulogd-backup.db -rw-r--r-- 1 ulog ulog 11643904 May 17 20:50 /var/log/ulog/ulogd.db
The database files aren't identical, because the logging daemon has written yet more data since the backup was taken.