Backup Script in Linux
Script for taking backup of logs stored by syslog-ng at folder "/var/log/HOSTS" & "/var/log/Firewalls" to a backup folder "/var/log/backup" as defined by you and then removing the original files for accommodating more space. Backup files will be generated with the time stamp and zipped to the backup location for easy searching and saving space.
Script will run every morning at 08:30 AM with the help of cron job.
#mkdir /var/log/backup
#cd /var/log/backup
#vi backup.sh
#!/bin/bash
PATH=/usr/bin:/bin:/usr/sbin/:/sbin
#Purpose = Backup of Important Data
#Created on 04-10-2012
#Author = Sharmith Ramesh S
#Version 1.0
#START
TIME=`date +"%b-%d-%y"` # This Command will add date in Backup File Name.
FILENAME1="backup-HOSTS-log-$TIME.tar.gz" # Here I define Backup file one name format.
FILENAME2="backup-Firewalls-log-$TIME.tar.gz" # Here I define Backup file second name format.
SRCDIR1="/var/log/HOSTS/" # Location of Source one Data Directory (Source of backup).
SRCDIR2="/var/log/Firewalls/" # Location of Source two Data Directory (Source of backup).
DESDIR="/var/log/backup/" # Destination of backup file.
tar -cpzf $DESDIR$FILENAME1 $SRCDIR1
tar -cpzf $DESDIR$FILENAME2 $SRCDIR2
rm -Rf $SRCDIR2/*
rm -Rf $SRCDIR1/*
#END
Save and Exit
#crontab -e
30 8 * * * /var/log/cron/backup.sh
Save and Exit
Other Blogs:
http://sharmith.blogspot.in/2012/08/installing-elasticsearch-on-fedora-1.html
http://sharmith.blogspot.in/2012/08/v-behaviorurldefaultvmlo.html
No comments:
Post a Comment