LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 04-25-2007, 08:55 PM   #1
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,192

Rep: Reputation: 120Reputation: 120
shell backup script help needed


I have a simple backup script that I use for my root drive. I don't like the way the for loop is setup. Is there a way to put these excluded directories into an array to clean it up? It would also clean up where I make the dummy directories. Heck, maybe the whole thing can be improved, I dunno? It does require a lot of disk space, but space is cheap these days.
Code:
#!/bin/sh
rm -rf tmp
mkdir tmp
cd tmp
for i in `ls / |grep -vw data |grep -vw data2 |grep -vw proc |grep -vw dev |grep -vw sys |grep -vw musem | grep -vw wendy`
do
echo /$i
cp -axu /$i .
done
mkdir data
mkdir data2
mkdir proc
mkdir dev
mkdir sys
mkdir musem
mkdir wendy
echo "tar --bzip2 -cf ../backup.tar.bz2 ."
tar --bzip2 -cf ../backup.tar.bz2 .
cd ..
 
Old 04-25-2007, 09:45 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,982

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
I don't quite get it.

It seems that you list a lot of path/file names, copy them to directories in your /tmp and then tarring them. Right.

You also say that you have an exclude list, but I only see files which are INcluded.

Anyway... if the files you want to include are easier to specify than the files you want to exclude, specify the files to backup, otherwise use --exclude for exluding patterns.

Also, it seems easier to simply specify what you want to backup:
tar -Cf mytarfile.tar /data/ /data2/ ....

The entire `ls` operation can be skipped.

You might also want to take a look at the "star" backup program, which is a sort of extended "tar". It comes with about 2654 different options to specify what you want to backup, log or skip.

Last but not least, bzipping an archive makes the process *much* slower.

jlinkels
 
Old 04-25-2007, 09:59 PM   #3
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,192

Original Poster
Rep: Reputation: 120Reputation: 120
Quote:
You also say that you have an exclude list, but I only see files which are INcluded.
The -vw option to grep excludes whatever is listed, so that the script copies everything except the /data, /data2, /proc, /dev, /sys, /musem, and /wendy directories.

Quote:
Anyway... if the files you want to include are easier to specify than the files you want to exclude, specify the files to backup, otherwise use --exclude for exluding patterns.
I didn't have any luck excluding whole directory trees with the --exclude option, but maybe I wasn't using it right. For example, how would I setup a tar to exclude the directory "/data" but not to exclude the directory "/home/data"? I just didn't understand this bit.

Quote:
Last but not least, bzipping an archive makes the process *much* slower.
Yeah, I know. The next time I run it, I'll probably switch to gzip.

The idea behind what I've done is that I can use a mindi boot CD and then just mount a backup CD and untar it onto the disk to get my running system back. This is for my test mule and I manage to bork it badly every few weeks; the latest being when I had problems with a Promise driver that wasn't recoverable.

Last edited by Quakeboy02; 04-25-2007 at 10:00 PM.
 
Old 04-26-2007, 05:35 AM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,982

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by Quakeboy02
The -vw option to grep excludes whatever is listed, so that the script copies everything except the /data, /data2, /proc, /dev, /sys, /musem, and /wendy directories.
Ah, never too old too learn.

Quote:
Originally Posted by Quakeboy02
I didn't have any luck excluding whole directory trees with the --exclude option, but maybe I wasn't using it right. For example, how would I setup a tar to exclude the directory "/data" but not to exclude the directory "/home/data"? I just didn't understand this bit.
Yes it works, but you have to put the quotes right. To the best of my knowledge it is:

tar --exclude="/data/*" --exclude="/data2/*" -cvf mytar.tar /

Using this command. you would skip /data, but not /home/data. I did not try it, but I don't think the "/" has to be escaped. (Like in \/home\/data\/*) I am extremely bad in remembering such details, but it becomes obvious fast enough when you try. I have backed up many root drives using the --exclude option though.

jlinkels
 
Old 04-26-2007, 05:20 PM   #5
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,192

Original Poster
Rep: Reputation: 120Reputation: 120
Code:
tar --exclude="/data/*" --exclude="/data2/*" -cvf mytar.tar /
Thanks. I'll have to try it. It's clearly Much quicker than the way I do it, but mine creates /proc etc as dummies that then get put in tar. This clearly requires more thought on my part. In case you're interested, here's what I wound up with where there's a clear exclusion list that's easily manipulated on a case by case basis. The resulting tar file has empty directories for each of the excluded ones.

Code:
#!/bin/sh
rm -rf tmp
mkdir tmp
cd tmp
exclude="data data2 proc dev sys musem wendy"
dirs=""
first=1
for thisdir in $exclude
do
if test $first -eq 1
then
first=0
dirs="$thisdir"
fi
dirs="$echo $dirs\|$thisdir"
done
for thisdir in `ls / | grep -vw $dirs`
do
echo /$thisdir
cp -axu /$thisdir .
done
for thisdir in $exclude
do
mkdir $thisdir
done
echo "tar --gzip -cf ../backup.tar.gz ."
tar --gzip -cf ../backup.tar.gz .
cd ..

Last edited by Quakeboy02; 04-26-2007 at 05:26 PM.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup shell script: help me improve it? PatrickMay16 General 3 12-26-2006 06:55 PM
shell backup script xtremeclones Linux - Software 3 10-03-2006 02:13 PM
Shell Script for backup BBQ_Matt Linux - Software 7 06-30-2005 05:19 PM
simple backup script needed ferret_dude Programming 4 05-24-2004 08:45 AM
Backup script needed jmirles Programming 1 09-27-2003 08:50 AM


All times are GMT -5. The time now is 02:11 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