LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-17-2004, 10:19 PM   #1
untoldone
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.

Code:
#!/bin/bash

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/*
do
        size_w=`du -s "$files"`
        cursize=${size_w%*$files*}      # find the size of the current file
        if [ `expr $comsize + $cursize` -ge $maxsize ]
        then
                tarlist="$tarlist $files"
                totar="$backdir/$i.tar $tarlist"
                cmd="tar -cf $totar"
                echo $cmd
                $cmd
                tarlist=""
                comsize=0
                i=`expr $i + 1`
        else
                comsize=`expr $comsize + $cursize`
                tarlist="$tarlist \"$files\""
                i=`expr $i + 1`
        fi
done

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

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
just replace your last line by:
eval $cmd
and it will work better.
 
Old 05-20-2004, 03:03 PM   #3
untoldone
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
 
  


Reply


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 12:03 PM
Incremental backup script - Tar problem joshheald Linux - Software 1 09-28-2004 10:02 AM
Basic backup script using Tar GraemeK Linux - General 1 09-17-2004 05:19 AM
Using tar for backup. TheRealDeal Linux - General 2 08-10-2004 11:46 PM
tar as backup imsajjadali Red Hat 4 02-07-2004 03:46 PM


All times are GMT -5. The time now is 03:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration