quick bash script for datewise backup of directory

2012-12-12 1 min read bash Linux

I was working on something and the data was very critical and needed backup. I wrote a bash script to back up the data every 5 hours with cron and bash script. Thought I will share that with you. Here is the script.

#!/bin/bash - 
#===============================================================================
#
#          FILE:  backup.sh
# 
#         USAGE:  ./backup.sh 
# 
#   DESCRIPTION:  Backup all the current files.
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 08/19/2011 02:43:32 PM IST
#      REVISION:  ---
#===============================================================================
backupf=( a b c d) #Here you need to specify the directory you need to backup.
bkupdir="/tmp/backup/$(date +%Y)/$(date +%m)/$(date +%d)" #Here you can change the basedir for the backups
mkdir  -p $bkupdir
sudo tar cvfz $bkupdir/bkup_$(date "+%Y%m%d_%H%M").tgz $backupf[*] #Remove sudo if you do not need it.
echo "Backup created in dir $dir"

And then just add it to cron as “00 */5 * * * /home//bin/backup.sh”. Change the path if it does not match what is given here.

Enhanced by Zemanta
comments powered by Disqus