Backup Linux System

#!/bin/bash

# Global Variables
INFO_FILE="info_`hostname`_`date +%Y-%m-%d`"
BACKUP_DIRECTORY="/mnt/backup/Linux"
DIRECTORY_NAME="`hostname`"

# Create backup directory
mkdir -pv $BACKUP_DIRECTORY/$DIRECTORY_NAME

# Output commands backup
echo -e "`hostname` > cat /etc/issue" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
cat /etc/issue >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > uname -a" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
uname -a >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > free -m" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
free -m >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > fdisk -l" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
fdisk -l >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > df -h" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
df -h >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > cat /etc/fstab" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
cat /etc/fstab >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > ifconfig" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
ifconfig >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > netstat -nr" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
netstat -nr >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > cat /etc/rc.local" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
cat /etc/rc.local >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > netstat -tunpl" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
netstat -tunpl >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > pstree" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
pstree >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > crontab -l" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
crontab -l >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > for i in cat /etc/passwd|awk -F: '($3>999 && $3 < 10000 ) {print $1}'; do crontab -l -u $i;done" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
for i in `cat /etc/passwd|awk -F: '($3>999 && $3 < 10000 ) {print $1}'`; do crontab -l -u $i; done >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > iptables -nvL" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
iptables -nvL >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > cat /proc/cpuinfo" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
cat /proc/cpuinfo >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > dmidecode" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
dmidecode >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > lspci" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
lspci >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > lsusb" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
lsusb >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "`hostname` > ls /etc/rc*.d" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
ls /etc/rc*.d >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE
echo -e "\n" >> $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE

# Backup all directories excluding /proc /sys /dev
tar cf $BACKUP_DIRECTORY/$DIRECTORY_NAME/$INFO_FILE.tar / --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/mnt
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s