Pages

Backup Script


Backup Script

This backup script will backup  /root directory to /backup directory. You can change the source and destination according to your wish. Once the backup is over the report will be mailed.

# mkdir  /backup
# cd  /backup
# vi   backup.sh


#!/bin/bash
NOWDATE=`date +%m%d%y`    # Sets the date variable format for zipped file: MMddyy
clear       # clears terminal window
echo
echo "Hi, $USER!" > $NOWDATE.log
echo
echo "Beginning backup of files @ `date`" >> $NOWDATE.log
echo
echo "Zipping directory structure..." >> $NOWDATE.log
echo
echo
tar   -cvzf   /backup/$NOWDATE.tar.gz    /root/* >> $NOWDATE.log
echo
echo
echo "Backup Complete!" >> $NOWDATE.log
sleep 2
SUBJECT="BACKUP REPORT"
EMAIL="admin@ittables.com"
ATTACH="/backup/$NOWDATE.log"
mail -s "$SUBJECT" "$EMAIL" < $ATTACH

:wq!  -------->  save and exit

# chmod  +x  /backup/backup.sh


You can also schedule the backup using cron  e.g

# crontab  -e

#################### backup runs on 1:01am###################
01  01  *  *  *    sh    /backup/backup.sh 
#########################################################

:wq!  ---------->  save and exit

NOTE :-  Postfix or Sendmail should be configured to receive mail......


6 comments:

  1. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!
    henrystickmangames.com
    Friv.Pro

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

Note:- Comment as: Option available to post without login select "Anonymous" from the drop down...........