Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-17-2004, 11:19 PM   #1
LQ Newbie
Registered: Nov 2003
Location: near DC, USA
Distribution: Slackware 9.1
Posts: 14

Rep: Reputation: 0
Backup script to tar

Hi, I was attempting to write my first 'real' script today and had an issue with it. The script is suposed to take a directory, go through all the files in it and place the files into several 1 Gig sized tar files. It seems to divide the files up ok, but when it gets to where it runs the tar ... tar gives me errors about not being able to find the files. When i echo the tar command the script creates and then just copy the command into the console, the tar runs without a problem. Thanks for your time.


check=$1                # directory to check
backdir=$2              # directory for backupfiles
maxsize=1000000         # size in KB of one tar

tarlist=""              # will contain space delimited file names
comsize=0               # total (complete) size of all files
i=1                     # file count

for files in $check/*
        size_w=`du -s "$files"`
        cursize=${size_w%*$files*}      # find the size of the current file
        if [ `expr $comsize + $cursize` -ge $maxsize ]
                tarlist="$tarlist $files"
                totar="$backdir/$i.tar $tarlist"
                cmd="tar -cf $totar"
                echo $cmd
                i=`expr $i + 1`
                comsize=`expr $comsize + $cursize`
                tarlist="$tarlist \"$files\""
                i=`expr $i + 1`

totar="$backdir/$i.tar $tarlist"
cmd="tar -cf $totar"
echo $cmd
Old 05-18-2004, 06:38 PM   #2
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,571

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
just replace your last line by:
eval $cmd
and it will work better.
Old 05-20-2004, 04:03 PM   #3
LQ Newbie
Registered: Nov 2003
Location: near DC, USA
Distribution: Slackware 9.1
Posts: 14

Original Poster
Rep: Reputation: 0
thanks much, that did it


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash backup script failing using tar and --newer option saldkj Programming 3 03-12-2005 01:03 PM
Incremental backup script - Tar problem joshheald Linux - Software 1 09-28-2004 11:02 AM
Basic backup script using Tar GraemeK Linux - General 1 09-17-2004 06:19 AM
Using tar for backup. TheRealDeal Linux - General 2 08-11-2004 12:46 AM
tar as backup imsajjadali Red Hat 4 02-07-2004 04:46 PM

All times are GMT -5. The time now is 09:42 PM.

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