quick bash script for datewise backup of directory
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.
Related articles
Related Articles:
- 2012/05/07 Array of all possible colors in bash script
- 2012/04/30 colors in bash scripts
- 2011/06/11 faster bash operations on files with File Descriptors.
- 2010/06/06 colors in bash – script to display all the possible colors.
- 2010/04/11 Linux Shell Scripting Tutorial – A Beginner\’s handbook
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.