Backup System Configuration
In this example, we automatically backup our system configuration.
From time to time, a system fails at pikt.org (for example, due to system disk failure), or we need to do an operating system upgrade. (Or, heaven forbid, a system might get hacked.) When we rebuild the system, after the OS reinstall, we need to restore the system to its previous configuration. For this purpose, it's handy to have a backup of the essential system configuration.
The BackupSystemConfiguration script following does just that.
BackupSystemConfiguration init status =piktstatus level =piktlevel task "Backup system configuration" input proc "echo =hostname; echo =dmesg; echo =df; echo =crontab -l" begin =execwait "=cp /dev/null /usr/local/etc/syscfg" rule =execwait "$inlin >> /usr/local/etc/syscfg" =execwait "echo >> /usr/local/etc/syscfg"
In this script, we want to 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/syscfg. (We could just as easily have placed this file in the /etc directory.) That is, we want the script input to be:
/bin/hostname /bin/dmesg /bin/df /usr/bin/crontab -l [...]
(and possibly other commands; we might add to the list over time).
One way to achieve this is by, as shown, echoing a series of commands in a Pikt 'input proc' statement.
Then, for each input command, we =execwait the command's output to the syscfg file. Very simple.
Another way to do this would be to accomplish the script objective in a single 'begin' statement (doing this in an 'end' statement would work just as well):
init status =piktstatus level =piktlevel task "Backup system configuration" begin =execwait "=hostname > /usr/local/etc/syscfg; =dmesg >> /usr/local/etc/syscfg; =df >> /usr/local/etc/syscfg; =crontab -l >> /usr/local/etc/syscfg"
(Note, since we have no rule sections, hence there is no script input loop, there is no need to specify an 'input proc' statement.)
We have a companion script, backup_nightly.sh, that backs up each system's /usr/local directory to a central backup server. So, on that backup server, we routinely save each system's /usr/local/etc/syscfg file in one central location.
This is just one program example. You could write new scripts to: backup each system's network configuration (example); backup each system's PIKT configuration (example); and so on.
For more examples, see Samples.