digital adj. Having digits.     peer n. A comrade; a companion; a fellow; an associate. inmotion    
   
Recent Articles
Stop DNSMasq From Forwarding Local Hostnames
Saturday, September 25, 2010
Securing your Wireless LAN
Wednesday, August 18, 2010
Some tips and things you might not know about your wireless network.
Using Different Subversion Client Versions
Wednesday, August 18, 2010
Handling a Subversion Repository URL Change
Sunday, May 3, 2009
If your repository URL changes, you can use the following command to fix existing snapshots.
vfat Mounts Default to Lowercase Shortnames
Tuesday, April 21, 2009
I want a "this is brain-damage" quote from Linus for this mess.
VirtualBox or VMWare Virtual Machine at Login
Sunday, April 12, 2009
How to start a virtual machine in X when a user logs in.
Dialog Progress Bar Through Pipe
Sunday, April 12, 2009
How to use dialog to display a script progress bar and communicate progress to it through a named pipe.
Mount JFFS2 Image
Saturday, October 25, 2008
Example of how to mount a JFFS2 image using mtdblock.

Don't regret things you do, cause at one point what you did was what you wanted.

Sys Admin-Linux...-General Tips-Backup...

Backup Script Using tar

Saturday, July 17, 2004 by digitalpeer

A simple backup script that performs monthly, weekly, and daily incremental backups. This is a handy little script that backs up to a single tgz file no matter how many different filesystems you give it to backup.

#!/bin/sh
#
# Backup Script by digitalpeer
# Original:  www.linuxgazette.com/issue47/misc/pollman/run-backup
#
# each_dir_under_here Space delimited list of directories to backup.  If 
#     multiple directories are listed use quotes around the argument.
# dump_to The directory to save files to.
# [key] An optional parameter (hostname is used if not specified) that is 
#     used to name the backup files.  Particularly necessary if you have 
#     multiple computers backing up to the same dump_to path.

if [ $# -lt 3 ]
then
   echo "usage: backup.sh each_dir_under_here dump_to [key]"
   exit;
fi

COMPUTER=`hostname`

if [ $# -gt 3 ]
then
   COMPUTER=$3
fi

DIRECTORIES=$1
BACKUPDIR=$2
TAR=/bin/tar		    # name and locaction of tar

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a`              # Day of the week e.g. Mon
DOM=`date +%d`              # Date of the Month e.g. 27
DM=`date +%d%b`             # Date and Month e.g. 27Sep

# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.


if [ $DOM = "01" ]; then  # monthly full backup
	NEWER=""
	$TAR $NEWER -z -c -f $BACKUPDIR/$COMPUTER-$DM.tgz $DIRECTORIES
fi

if [ $DOW = "Sun" ]; then # weekly full backup
        NEWER=""
	NOW=`date +%d-%b`
	echo $NOW > $BACKUPDIR/$COMPUTER-full-date #update full backup date
	$TAR $NEWER -z -c -f $BACKUPDIR/$COMPUTER-$DOW.tgz $DIRECTORIES --ignore-failed-read

else    # make incremental backup - overwrite last weeks
	NEWER="--newer `cat $BACKUPDIR/$COMPUTER-full-date`" #get date of last full backup
	$TAR $NEWER -z -c -f $BACKUPDIR/$COMPUTER-$DOW.tgz $DIRECTORIES --ignore-failed-read
fi


Comment Wednesday, August 10, 2011 by  krushna
Thanks for sharing ,Really helpful

Submit Comment to This Article
Please post a comment if you have something to add, find something wrong, or would like more information on the topic at hand. Do not use the comment form to contact the author about unrelated concerns!

Name: Email (optional):
Enter verification number here: