LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can you spot the error in my tar command? (https://www.linuxquestions.org/questions/linux-newbie-8/can-you-spot-the-error-in-my-tar-command-776090/)

just a man 12-16-2009 09:08 AM

Can you spot the error in my tar command?
 
I'm using the following command in a script run by crontab to backup my server...

Code:

#!/bin/bash

tar -cvpzf server.tar.gz --exclude=/home/jam/server.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/home/jam/backup --exclude=/home/jam/stuff /

HOST='backupbox.net'
USER='jam'
PASSWD='marmalade'
FILE='server.tar.gz'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit

#rm -rf /home/jam/server.tar.gz

END_SCRIPT
exit 0

/home/jam is my home directory, and backupbox.net is another server on which I have an account that I access via ftp to store the backup, and those "--exclude" directories are just directories I don't want in the backup. Aside from them everything under "/" is supposed to be backed up.

The command does actually create the file server.tar.gz, and sends it to the backup server ok. But if I try to open the archive on the Ubuntu Desktop of the server making the backup, I get this error:

Quote:

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Exiting with failure status due to previous errors
If I run
Code:

tar -tv ./server.tar.gz
on the command line in Terminal to just list the contents of the archive, it just hangs.

Any body can give me a clue what I'm doing wrong? Or is there just a limit to the size of archive that tar can reliably create?

mlev 12-16-2009 09:33 AM

I don't think tar -tv lists files in a .gz archive. Instead use:

tar -ztvf server.tar.gz

(The "z" and "f" inform tar that it is working with a gzip file? Anyway, it should work.)

Your tar command looks OK to me, but I can't see the entire line in the post. (Looks like the words didn't wrap.)

just a man 12-16-2009 09:44 AM

Quote:

Originally Posted by mlev (Post 3793777)
I don't think tar -tv lists files in a .gz archive. Instead use:

tar -ztvf server.tar.gz

(The "z" and "f" inform tar that it is working with a gzip file? Anyway, it should work.)

Your tar command looks OK to me, but I can't see the entire line in the post. (Looks like the words didn't wrap.)

Thanks for the response, if you scroll-bar along to the end it ends "--exclude=/home/jam/stuff /", that is the last exclude, and to archive "/", trying to archive everything else under root except that which is excluded.

I tried your command, and now get a consistent error message, that being the same one as when I try to view the archive via Ubuntu Desktop:

Quote:

sh-4.0$ tar -ztvf server.tar.gz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Exiting with failure status due to previous errors
sh-4.0$

business_kid 12-16-2009 10:15 AM

humour me, and try
tar -zcpf etc. or even
tar -c -z -p -f etc.

Reasons: the '-v' option isn't implemented for making archives, only for extracting; The tar info page (a contender for the most obscure document on the planet) suggests that clustering options is bad news, and they would like if getopt actually threw that out as an invalid format. My guess is they have problems there. The '-z' option is fussy if it's not at the beginning.

mlev 12-16-2009 10:55 AM

I don't think there's an error in your tar command. I created a script like yours and it runs fine. (The "v" causes the list of files being compressed to scroll on the terminal.)

Maybe a corrupt file or directory is throwing tar into a tizzy.

business_kid 12-17-2009 03:58 AM

Tar -tz never works - try it people.

The -z option likes to be near the front of a string of options or it doesn't work.
I don't think -cvpzf is ok, use -cz -pvf or the like

evo2 12-17-2009 04:26 AM

Quote:

Originally Posted by business_kid (Post 3795048)
Tar -tz never works - try it people.

The -z option likes to be near the front of a string of options or it doesn't work.
I don't think -cvpzf is ok, use -cz -pvf or the like

"tar -tz" and "tar -cvpzf" work fine for me.
Code:

% tar --version
tar (GNU tar) 1.22
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.

What version of tar are you using?

Evo2.

evo2 12-17-2009 04:27 AM

Quote:

Originally Posted by just a man (Post 3793753)
I'm using the following command in a script run by crontab to backup my server...

I think paths can get a bit screwy with cron. Have you tried just running the script manually?

Cheers,

Evo2.

evo2 12-17-2009 04:30 AM

Quote:

Originally Posted by just a man (Post 3793753)

If I run
Code:

tar -tv ./server.tar.gz
on the command line in Terminal to just list the contents of the archive, it just hangs.

You need z and f
Does this work?
Code:

tar -tzvf ./server.tar.gz
Evo2.

just a man 12-17-2009 06:49 AM

Quote:

Originally Posted by evo2 (Post 3795102)
You need z and f
Does this work?
Code:

tar -tzvf ./server.tar.gz
Evo2.

Woah, yes it does!

If this works, then maybe the archive is ok?

gottymann 12-17-2009 06:51 AM

installing xfce on ubuntu 9.10
 
installing xfce on ubuntu 9.10

evo2 12-17-2009 06:52 AM

Quote:

Originally Posted by just a man (Post 3795274)
Woah, yes it does!

If this works, then maybe the archive is ok?

Try it. Just replace the t with x.

Evo2.

kofucii 12-17-2009 07:16 AM

I don't think you can tar the special files like /dev, /proc/, /sys. To do so, try with command "cpio".


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