Backup PIKT Configuration
In this example, we regularly backup our PIKT configuration.
Sooner or later, a system fails at pikt.org (a system disk gets scrambled, for example), or we need to upgrade the OS. (It could happen, too, that a system gets hacked.) When we go to rebuild the system, after the operating system reinstall, we need to restore the system's previous PIKT configuration. For this purpose, it would be convenient to have a backup of the system's essential PIKT configuration.
The BackupPIKTConfiguration script following does the PIKT backup for us.
BackupPIKTConfiguration init status =piktstatus level =piktlevel task "Backup PIKT configuration" input proc "echo =hostname; echo =egrep pikt /etc/rpc; echo =rpcinfo -p =pikthostname; echo =egrep pikt /etc/services; echo =cat =etcdir/PIKT.conf" begin =execwait "=cp /dev/null /usr/local/etc/piktcfg" rule =execwait "$inlin >> /usr/local/etc/piktcfg" =execwait "echo >> /usr/local/etc/piktcfg" end // backup /home/pikt & /var/pikt directories =execwait "=tar -czf /usr/local/etc/homepikt.taz -C /home/pikt bin etc lib var" =execwait "=tar -czf /usr/local/etc/varpikt.taz -C /var/pikt ."
In this script, we feed the standard Pikt input loop a series of commands, the output of which will be concatenated to a file, in this case /usr/local/etc/piktcfg. (We could just as easily have placed this file in the /etc directory.) That is to say, we want the script input to be:
/bin/hostname /usr/bin/egrep pikt /etc/rpc /usr/sbin/rpcinfo -p calgary [or whatever the system name is] /usr/bin/egrep pikt /etc/services /bin/cat /pikt/etc/PIKT.conf [...]
(and possibly other commands; we might add to this list over time).
We do this by echoing a series of commands in a Pikt 'input proc' statement.
Then, for each input command, we =execwait the command's output to the piktcfg file. (Note how, in the 'begin' statement, we null the piktcfg file first.)
We have a companion script, backup_nightly.sh, that backs up systems' /usr/local directories to a central backup server. So, on that backup server, we always have each system's /usr/local/etc/piktcfg file in one central location.
It can be useful, also, to backup each system's PIKT home and /var directories. We achieve that by creating compressed tar files in the 'end' statement as shown.
For more examples, see Samples.