LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-25-2007, 10:58 AM   #1
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Rep: Reputation: 32
error in a backup script


hello all i want to make a bash script that backup files from a dir to another dir ..., by the way here is the script ...

Code:
 #!/bin/bash


backupdir=/home/blackice/Desktop/backup

scriptdir=/home/blackice/Desktop/scripts

backupfile=scripts.backup.`date +%F`

tar -czvf $backupdir $backupfile $scriptdir


#end
when ever i run it i got the following error

Code:
[root@localhost backup]# ./backupscripts.sh 
tar: /home/blackice/Desktop/backup: Cannot open: Is a directory
tar: Error is not recoverable: exiting now
tar: scripts.backup.2007-08-25: Cannot stat: No such file or directory
tar: Removing leading `/' from member names/home/blackice/Desktop/scripts/
/home/blackice/Desktop/scripts/network/
/home/blackice/Desktop/scripts/network/internet_status.sh
/home/blackice/Desktop/scripts/network/insist_ping.sh
/home/blackice/Desktop/scripts/network/watching_network_service.sh
/home/blackice/Desktop/scripts/loops/
/home/blackice/Desktop/scripts/loops/until_loop.sh
/home/blackice/Desktop/scripts/loops/for_loop.sh
/home/blackice/Desktop/scripts/loops/while_loop.sh~
/home/blackice/Desktop/scripts/loops/while_loop.sh
/home/blackice/Desktop/scripts/backup/
/home/blackice/Desktop/scripts/backup/backupscripts.sh
/home/blackice/Desktop/scripts/users/
/home/blackice/Desktop/scripts/users/logins.sh
/home/blackice/Desktop/scripts/Directories/
/home/blackice/Desktop/scripts/Directories/check_for_dir.sh~
/home/blackice/Desktop/scripts/Directories/test/
/home/blackice/Desktop/scripts/Directories/loop_in_dir.sh
/home/blackice/Desktop/scripts/Directories/check_for_dir.sh
/home/blackice/Desktop/scripts/Directories/loop_throw_users_project/
/home/blackice/Desktop/scripts/Directories/loop_throw_users_project/illustration
/home/blackice/Desktop/scripts/Directories/loop_throw_users_project/illustration~
/home/blackice/Desktop/scripts/Directories/loop_throw_users_project/loop_in_users.sh
/home/blackice/Desktop/scripts/processes/
/home/blackice/Desktop/scripts/processes/control_jobs.sh
/home/blackice/Desktop/scripts/processes/junkdata.data
/home/blackice/Desktop/scripts/processes/junk1.data
 
Old 08-25-2007, 11:15 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
check your tar syntax...
 
Old 08-25-2007, 11:39 AM   #3
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
thanx for replay
but iam sure of the syntax ....... ? !
 
Old 08-25-2007, 11:48 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

tar -czvf $backupdir $backupfile $scriptdir

will translate into:

tar -czvf /home/blackice/Desktop/backup scripts.backup.2007-08-25 /home/blackice/Desktop/scripts

Which doesn't look correct.

Code:
#!/bin/bash

set -x

backupdir=/home/blackice/Desktop/backup

scriptdir=/home/blackice/Desktop/scripts

backupfile="${scriptdir}/scripts.backup.`date +%F`.tgz"

tar -czvf $backupfile $scriptdir
tar -czvf $backupfile $scriptdir

will now translate to:

tar -czvf /home/blackice/Desktop/scripts/scripts.backup.2007-08-25.tgz /home/blackice/Desktop/scripts

Hope this helps.
 
Old 08-25-2007, 12:56 PM   #5
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
thanks it works !



but i have questions what is the use of ${scriptdir}? itis something like function in braces ?

and thanks again

also the tar making this error

tar: Removing leading `/' from member names
?

Last edited by adam_blackice; 08-25-2007 at 01:12 PM.
 
Old 08-25-2007, 02:24 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Quote:
what is the use of ${scriptdir}?
$scriptdir and ${scriptdir} are basically the same, but sometimes you need the curly braces to do some bash related stuff (man bash -> Parameter Expansion).

I made it a habit to always use the curly braces.

Here's another reason why you need to use culry braces:

dirpart="/x/y/z/"
file1=${dirpart}somename.datestamp.extension
file2=$dirpartsomename.datestamp.extension

file1 will be what you wanted (=> /x/y/z/somename.datestamp.extension)
file2 will be empty, there's no variable called dirpartsomename.datestamp.extension.

Quote:
tar: Removing leading `/' from member names
This is tar's default behavior. Without the leading /, it is possible to extract the archive at any location and select yourself what file(s) needs to be restored. If the leading slash is not removed, untarring will overwrite the files that are already there (which could be good, but is a bad thing most of the time).

The -p / --absolute-names option will make sure that the leading / won't be removed (only use this if you know what the consequences are....)

Hope this helps.
 
Old 08-25-2007, 04:30 PM   #7
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
really thanx for your brief explain.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
backup script tommytomato Linux - General 6 09-22-2006 02:41 AM
Error when attempting backup with File Backup lglrgl Linux - Software 0 08-03-2006 10:38 AM
Using CP in my backup script. Echo Kilo Programming 6 06-01-2005 08:43 AM
help with backup script dennis_89 Linux - Networking 2 06-29-2004 09:47 AM
error in backup script, deleted almost all data :( ash4stuff Linux - Software 0 06-11-2004 06:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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