LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
  Search this Thread
Old 06-04-2009, 12:56 AM   #1
camry
LQ Newbie
 
Registered: May 2008
Posts: 27

Rep: Reputation: 15
Backup script


Hi all
I want to make a simple backup script to compress my directories under parent directory "servers" and make the backup with there names.tar.gz and then remove the old data, I make the following just for bigining:
-----------
dires=`ls servers`
for i in $dires
do tar -czf $i.tar.qz $i
done
-----------
But It doesn't work , can u help
 
Old 06-04-2009, 01:51 AM   #2
minimol
LQ Newbie
 
Registered: Aug 2006
Distribution: Fedora
Posts: 10

Rep: Reputation: 0
Try this

dires=`ls servers`
for i in $dires
do tar -czf ${i}.tar.gz $i
done

to debug scripts use sh -x <script_name>
 
Old 06-04-2009, 03:20 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by camry View Post
But It doesn't work
That's an incredible amount of info you give there

Which is what doesn't work? How do you use it? What results do you get? What did you expect it to do? Any error message? Please, info. Otherwise we can only guess which is what "doesn't work".

Just a note, when dealing with dir and file names use quotations around them. Otherwise if a name has spaces you are screwed.

Another note, I usually disregard the usage of the "ls" command for this purpose. It creates more trouble than it's worth. If you want to do so, use find with -exec instead.

Code:
find servers -exec tar -czf '{}'.tar.gz '{}' \;
If you are in bash you can just do this:

Code:
for i in servers/*
  do tar -czf "$i".tar.gz "$i"
done
Curly brackets, as someone suggested, won't harm. But they are not needed in this case since the dot is not a character that can be used in an identifier (variable name in this case).
 
  


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
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
backup script stuaz Linux - General 6 01-14-2009 04:17 AM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
Backup script rcmonroig Linux - Newbie 4 04-21-2007 12:58 AM
Backup Script? drmjh Linux - Newbie 12 10-09-2006 12:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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