Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using this command to backup some important configuration files:

tar -czvf /var/backups/201102121202.tgz -C / etc/crontab etc/httpd/conf.d/* etc/httpd/conf/httpd.conf etc/httpd/passwords etc/httpd/vhost/* etc/php.ini etc/my.cnf etc/ssh/* etc/hosts etc/sysconfig/iptables var/spool/cron/* etc/passwd etc/group root/iptables_config etc/postfix/main.cf etc/postfix/master.cf etc/postfix/transport etc/postfix/valid_recipients etc/postfix/virtual etc/sysconfig/memcached etc/php.d/apc.ini etc/selinux/config etc/yum.repos.d/* etc/list_of_installed_packages.txt etc/safe-rm.conf home/*/.bash* home/*/.ssh usr/local/bin/* usr/local/sbin/* /etc/pki/tls/certs/mysite.com.crt /etc/pki/tls/private/mysite.key /etc/pki/tls/certs/gd_bundle.crt

When I run it, I get:

tar: etc/httpd/conf.d/*: Cannot stat: No such file or directory
tar: etc/httpd/vhost/*: Cannot stat: No such file or directory
tar: etc/ssh/*: Cannot stat: No such file or directory
tar: var/spool/cron/*: Cannot stat: No such file or directory
tar: etc/yum.repos.d/*: Cannot stat: No such file or directory
tar: home/*/.bash*: Cannot stat: No such file or directory
tar: home/*/.ssh: Cannot stat: No such file or directory
tar: usr/local/bin/*: Cannot stat: No such file or directory
tar: usr/local/sbin/*: Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: Error exit delayed from previous errors

It seems I can't use wildcards in the paths.
How can I fix or workaround that?

Thanks,
Dan

share|improve this question
    
What shell are you using? –  Hello71 Feb 16 '11 at 1:45
    
I am using bash –  dan Feb 16 '11 at 1:47
add comment

4 Answers

up vote 2 down vote accepted

The likely problem is that you are not in the root directory (/), but your wildcards assume that you are. Remember that the shell expands wildcards on the command-line before envoking the program. So you etc/ssh/* is relative to your current working directory, which likely doesn't exist. Run (cd /; tar ... etc/ssh/* ...) instead.

share|improve this answer
add comment

your command:

tar -czvf /var/backups/201102121202.tgz -C / etc/crontab etc/httpd/conf.d/* etc/httpd/conf/httpd.conf etc/httpd/passwords etc/httpd/vhost/* etc/php.ini etc/my.cnf etc/ssh/* etc/hosts etc/sysconfig/iptables var/spool/cron/* etc/passwd etc/group root/iptables_config etc/postfix/main.cf etc/postfix/master.cf etc/postfix/transport etc/postfix/valid_recipients etc/postfix/virtual etc/sysconfig/memcached etc/php.d/apc.ini etc/selinux/config etc/yum.repos.d/* etc/list_of_installed_packages.txt etc/safe-rm.conf home/*/.bash* home/*/.ssh usr/local/bin/* usr/local/sbin/* /etc/pki/tls/certs/mysite.com.crt /etc/pki/tls/private/mysite.key /etc/pki/tls/certs/gd_bundle.crt

You make simple mistake like me in the past :)

  1. -C tar option 'moves' only tar command to '/' as you do.
  2. First is shell. This expands asterisks using current directory. When you write /etc/* , this expand /etc/* for names. When you write etc/* , this begins not from /root, but from current directory. You can repair this adding '/' or cd /. Then -C is not needed.
  3. You can prevent expanding by the shell, using notation 'etc/*'. But tar will use this 'as is'. If you dont want that, use --wildcards option.
  4. What for you use 'etc/*', you can use simply 'etc/'. option --recursion is default.

See man tar . But in older systems this manual is incomplete, then use info tar .

share|improve this answer
add comment

Try dropping the * (or maybe /*).


Remainder Syntax ...

When file is the path name of a directory, the action applies to all of the files and (recursively) subdirectories of that directory.

http://www.computerhope.com/unix/utar.htm

share|improve this answer
    
-1 for linking to computerhope and not the manpage. –  Hello71 Feb 16 '11 at 1:51
add comment

You're missing a / before the beginning of the names. The shell will only glob names if they're absolute paths. Also, if you do that, there's no need for the use of -C.

share|improve this answer
    
Good point. I think I did it for a reason. Probably because if I use absolute paths, when I uncompress the package I may be in danger of overwriting the /etc directory of the host system. Did I make myself clear? –  dan Feb 16 '11 at 1:50
    
the shell will glob any filename that exists, relative or absolute. And adding a / to the paths will anchor them and force an overwrite on extraction of system files and will not allow the files to be extracted into, say, /tmp (not without using chroot anyway). –  Arcege Feb 16 '11 at 1:53
    
@Arcege: The shell, however, will not magically figure out that -C causes tar to change directory. –  Hello71 Feb 16 '11 at 1:55
    
Which is why alternatives from the -C option alone must be made, like (cd /; tar czf ...) or find /etc/httpd/conf.d /etc/ssh /home/*/.ssh ... -print | sed 's;^/;;' > /tmp/tar.lst && tar czfCI $tarfile / /tmp/tar.lst && rm /tmp/tar.lst. But patently saying that "the shell will only glob names if they're absolute paths" is incorrect. If it were correct, then echo * or even echo ./* would not work. –  Arcege Feb 16 '11 at 15:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.