Tuesday, July 26, 2011

how to get backup in Linux server

for this problem i use shell script to get incremental and daily backups.In this cause i use cron tab for run that script at that time.

shell script 1 - daily backup(test.sh)


####################################



echo "Starting to get incremental backup"
date=`date +%Y%m%d`
rsync --delete -avh /home/kasun/Desktop/new /home/kasun/Desktop/back-$date

Long listing of files in $dest to check file sizes.
ls -lh $dest

echo "Full Backups_done.." | mail -s "incremental Done at kasun " kasunmanduraeng@gmail.com
sendmail -q
##############################################

test2.sh....full backup

###############################################
# What to backup.
backup_files="/home/kasun/Desktop/new"

# Where to backup to.
dest="/home/kasun/Desktop/test"

# Create archive filename.
day=$(date +%Y%m%d)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
day1=$(date +%d)
yday1=$((day1-1))
date1=$(date +%Y%m)


remove="$hostname-$date1$yday1.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files ###daily back up
#remove after 2 days backups

echo $dest/$archive_file $backup_files
rm $dest/$remove

# Print end status message.
echo
echo "Backup finished"
date


echo "Full Backups_done.." | mail -s "daily full Done at kasun " kasunmanduraeng@gmail.com
sendmail -q
##################################

after getting back receive notification mail.


Edit cron tab........

in command line type..


crontab -e

then edit crontab(you can edit /etc/crontab also)

00 00 * * * root /root/test.sh ##every hour ur incremental backup process running
00 00 00 * * root /root/test2.sh## every day for bacup running

No comments:

Post a Comment