#!/usr/bin/perl
# Backup useful system configuration files to the specified directory.
# This is for backing up system configuration files, not user configuration 
# files that should be backed up as part of any user partition backups.

# Note:  don't copy everything from /etc - just those files you actually
# modified for your host.

# Files that used to get backed up but now are easily managed by the
# distro after an upgrade.
# /etc/sysconfig/network-scripts/ifcfg-eth0
# /etc/sysconfig/network-scripts/ifcfg-eth1
# /etc/sysconfig/network-scripts/ifcfg-ppp0
# /etc/sysconfig/network-scripts/ifcfg-ppp1
# /etc/sysconfig/network-scripts/chat-ppp0
# /etc/sysconfig/network-scripts/chat-ppp1
# /etc/software/*
# /etc/modules.conf

# The list of files to be backed up.  Some of these are directories.
$filelist = <<EOF;
/etc/passwd
/etc/shadow
/etc/group
/etc/fstab
/etc/hosts
/etc/issue
/etc/printcap
/etc/exports
/etc/resolv.conf
/etc/mail/sendmail.cf
/etc/ld.so.conf
/etc/X11/xorg.conf
/etc/php.ini
/etc/my.cnf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/local.conf
/etc/rc.d/rc.local
/etc/sysconfig/network-scripts
/etc/modprobe.conf
EOF

# Check command line arg
if ( "$ARGV[0]" eq "" )
{
	print "You must specify the backup directory to use.\n";
	exit (1);
}

@configfiles = split('\n', $filelist);

for (@configfiles)
{
	if (-e $_)
	{
		$files = join(" ", $files, $_);
	}
	else 
	{
	   if (index($_, "*") >= 0)
	   {
			$files = join(" ", $files, $_);
		}
	}
}

# Tar them up into a file under the specified directory.
if ( -d $ARGV[0] )
{
	print "Creating archive...\n";
	print "files: $files\n";
	`tar Pczf $ARGV[0]/systemfiles.tar.gz $files`;
}
else
{
	print "Can't find directory: $ARGV[0]\n";
}


