Backup Network Configuration

In this example, we routinely backup our network configuration.

Occasionally, a system might fail at pikt.org (for example, due to hardware failure), or we might need to do an operating system upgrade.  (Or, perish the thought, a system might get hacked.)  When we rebuild the system, after the OS reinstall, we need to restore the system to its previous configuration, in particular its network configuration.  For this purpose, it's useful to have a backup of the system's essential network configuration.

The BackupNetworkConfiguration script following will do exactly that.

BackupNetworkConfiguration

        init
                status =piktstatus
                level =piktlevel
                task "Backup network configuration"
                input proc "echo =hostname; echo =ifconfig; echo =cat /etc/hosts;
                            echo =route; echo =cat /etc/resolv.conf"

        begin
                =execwait "=cp /dev/null /usr/local/etc/netcfg"

        rule
                =execwait "$inlin >> /usr/local/etc/netcfg"
                =execwait "echo >> /usr/local/etc/netcfg"

#if firewall
        end
                =execwait "=cat /etc/init.d/iptables >> /usr/local/etc/netcfg"
#endif

In this script, we want to feed the standard Pikt input loop a series of commands.  We will concatenate their output to a file, in this case /usr/local/etc/netcfg.  (We could just as easily have located this file in the /etc directory.)  That is, we want the script input to be:

/bin/hostname
/sbin/ifconfig
/bin/cat /etc/hosts
/sbin/route
/bin/cat /etc/resolv.conf
[...]

(and possibly other commands; we might add to this list over time).

We could accomplish this by, as shown, echoing a series of commands in a Pikt 'input proc' statement.

Another way we could do this is by, using an 'input file' statement,

                input file "=objdir/BackupNetworkConfiguration.obj"

feeding the contents of an external PIKT objects file, BackupNetworkConfiguration.obj, defined in our objects.cfg file as

BackupNetworkConfiguration
        =hostname
        =ifconfig
        =cat /etc/hosts
        =route
        =cat /etc/resolv.conf
        [...]
#if firewall
        =cat /etc/init.d/iptables
#endif

Either way, for each input command, we =execwait the command's output to the netcfg file.  Very straightforward.

We have another script, backup_nightly.sh, for backing up each system's /usr/local directory to a central backup server.  So, on that backup server, we regularly save each system's /usr/local/etc/netcfg file in one central place.

This is just one program example.  You could write new scripts to:  backup other, non-network system configurations (example); backup PIKT configurations (example); and so on.

Open Hand For more examples, see Samples.

 
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software
Developer's Notes | Licensing | Authors | Pikt-Users | Pikt-Workers | Related Projects | Site Index | Privacy Policy | Contact Us
Page best viewed at 1024x768 or greater.   Page last updated 2010-04-15.   This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.   Copyright © 1998-2010 Robert Osterlund. All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title
View sample
backup system
configuration
Pikt script