quick bash script for datewise backup of directory

2012-12-12 199 words 1 min read

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

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it