LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-19-2006, 08:43 PM   #1
ajkrishock
Member
 
Registered: Jul 2003
Distribution: Linux Mint
Posts: 33

Rep: Reputation: 15
Problem with my backup script FC4


Hello All..

Pretty sure this one is easy, but for whatever reason, it's always the easy problems that get me.

I have two drives on my Linux server (running Fedora core 4). HDA is my primary boot drive (40 Gb Seagate / ext3 Filesystem). HDB is my backup drive (120 Gb WD / FAT Filesystem). HDB is mounted automatically by FSTAB in read/write mode. Furthermore, several directories on this drive and on HDA are availabe over my Windows network via SAMBA. They are used for a variety of purposes (GHOST images, e-mail backup, etc..).

The one directory that is shared on HDA is /data/Common. On my XP machines, I changed the mapping of the "My Documents" folder to point to this directory. The idea was that everyone's "My Documents" folder was mapped to the same place. Believe it or not, this is working out very well. Problem is.. I don't trust Seagate. If this drive dies, I lose all my important documents in the /data/Common drive.

This would be very bad.

So, I would like to write a backup script that tar's up the contents of the /data/Common drive and moves that tarball onto the HDB drive. I have done this (rather, I found a backup script on the web). My script looks like:

#!/bin/sh
# full and incremental backup script

#Change the 5 variables below to fit your computer/backup
DIRNAME=Documents
COMPUTER=server # name of this computer
DIRECTORIES="/data/Common" # directories to backup
BACKUPDIR=/mnt/backup/Documents # where to store the backups
TIMEDIR=/mnt/backup/Documents/last-full # where to store time of full backup
TAR=/bin/tar # name and locaction of tar

#You should not have to change anything below here

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.


# Monthly full backup
if [ $DOM = "01" ]; then
NEWER=""
$TAR $NEWER -cvzf $BACKUPDIR/$DIRNAME-$DM.tar $DIRECTORIES
fi

# Weekly full backup
if [ $DOW = "Sun" ]; then
NEWER=""
NOW=`date +%d-%b`

# Update full backup date
echo $NOW > $TIMEDIR/$DIRNAME-full-date
$TAR $NEWER -cpfv $BACKUPDIR/$DIRNAME-$DOW.tar $DIRECTORIES

# Make incremental backup - overwrite last weeks
else

# Get date of last full backup
NEWER="--newer `cat $TIMEDIR/$DIRNAME-full-date`"
$TAR $NEWER -cvzf $BACKUPDIR/$DIRNAME-$DOW.tar $DIRECTORIES
fi

The /data/Common directory contains ~2Gb of data. When the script runs, it creates a file that is about 92Mb in size. Now, that can't be right. Apparently, the tarball contains only the folders in the /data/Common directory.. not the files in those directories. What's going on here?

I obviously need the script to copy the files, too..otherwise this is a wasted effort. What am I missing here is there some tar argument I need to use to force it to copy the files in the directories, too? Man page wasn't much help..

TIA for your wisdom

Regards

Anthony Krishock
 
Old 08-19-2006, 09:35 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
( tar cf - /data/Common ) | ( cd /mnt/backup/Documents ; tar xpf - )

This would quickly and easily tar the files in one location and extract them in another. I've used it to move entire partitions.

To do incremental backup, just add the -G (--incremental) to the beginning of the command.

You could either replace your script with this one-liner, or use the one-liner to modify your script. Your choice.

You could also invesitgate DAR, which I use for backups. Easily customizable scripts for full and incremental backups. Easy to list the backup; easy to restore all or part of the backup. Lacks only one thing: the only drawback of tar that keeps me from using tar. If part of a tar archive is corrupted, you risk loosing the entire archive (that one-liner above should get around that problem). DAR archives each file individually, so that if one is corrupt, you only loose one and not the entire archive.

Last edited by bigrigdriver; 08-19-2006 at 09:45 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Backup(~) files in fc4 coolguy_iiit Linux - Newbie 9 07-30-2006 11:45 PM
Backup Script Help Canni Programming 8 06-15-2006 10:19 AM
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM
Incremental backup script - Tar problem joshheald Linux - Software 1 09-28-2004 10:02 AM
Bash backup script - If multiple files starting with a exist problem demoncheese Programming 2 07-29-2004 10:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration