RHEL5 Backup Shell Script

Below is a link to a RHEL5 shell backup script. Below is a summary of what the script does :

  • Creates a tgz of all the major RHEL 5 operating system files to ${backup_name}.
  • All the installed rpms are saved to a text file named /var/log/installed_rpms.txt.
#!/bin/sh
#
# RHEL 5 Backup Script v1.1
#
#  - Creates a tgz of all the major RHEL 5 operating system files to ${backup_name}.
#  - All the installed rpms are saved to a text file named /var/log/installed_rpms.txt.
#

PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
backup()
{
backup_name=Backup-`hostname`-`date "+%Y%m%d"`
backup_loc=/backup

rpm -qa > /var/log/installed_rpms.txt
tar cf - \
        /var/log/installed_rpms.txt \
        /etc/cron* \
        /etc/ftp* \
        /etc/group* \
        /etc/hosts* \
        /etc/init.d/*  \
        /etc/rc3.d/* \
        /etc/passwd \
        /etc/resolv.conf \
        /etc/sasl2* \
        /etc/shadow \
        /etc/snmp/* \
        /etc/ssh/* \
        /etc/sysconfig/* \
        /etc/sysctl.conf \
        /etc/syslog.conf \
        /etc/yum* \
        /root/.bash_profile \
        /root/.bashrc \
        /root/.ssh* \
| gzip -6c > ${backup_loc}/${backup_name}.tgz

if [ $? != 0 ]
then
        logger -t os_backup -p daemon.err "Backup unsuccessful."
        exit 1
else
        logger -t os_backup -p daemon.info "Backup successful."
        exit 0
fi
}

backup
Rick Donato