Cannot create an archive with .tar command (Permission Denied)

  • Amadeus Bachmann

    Fİrst of all I am sorry for my noob question. I am really new to Unix based OS. I need to to create a archive from my ftp server (all of the /usr/src/ directory) using tar command. However I keep getting permission denied error. Here is step by step what I am doing:

    canserhan@embserv:~$ cd /usr/src/
    canserhan@embserv:/usr/src$ ls
    kernel-headers-2.6.8-2       linux                rtlinux-3.2-pre3
    kernel-headers-2.6.8-2-386   linux-2.4.21         rtlinux3.2-move
    kernel-kbuild-2.6-3          linux-2.6.9-rtlfree
    kernel-source-2.6.8.tar.bz2  rtlinux
    canserhan@embserv:/usr/src$ tar cvf rtl_archive.tar /usr/src/
    tar: rtl_archive.tar: Cannot open: Permission denied
    tar: Error is not recoverable: exiting now

    What I am doing wrong? Seems like the problem is with my output archive file. But I could not exactly figure out what should I do.

    Thank you for your help.

  • Answers
  • 0xC0000022L

    The problem is that you are executing the command inside /usr/src to which you do not have write permissions with your credentials. Therefore you do not have write permissions for the .tar file you are trying to create. Use tar cvf /tmp/rtl_archive.tar /usr/src to create a tar-file where writing is possible.

    Generally you can give any path that you have write access to, such as:

    tar cvf $HOME/rtl_archive.tar /usr/src

    to create the .tar file in.

  • Related Question

    backup - (tar: /dev/nst0: Cannot read: Cannot allocate memory) with tar, pv and tape drive
  • Andrew

    I'm trying to use pv (pipeviewer) along with tar to do tape backups in order to see the progress and eta like so:

    du -s /home/myuser
    115630916   /home/myuser
    tar -cf - /home/myuser/ | pv -s 115630916 > /dev/nst0

    Which works fine, it writes to tape successfully. But once I try and test the tar archive:

    mt -f /dev/nst0 rewind
    tar -tvf /dev/nst0

    I get the following errors:

    tar: /dev/nst0: Cannot read: Cannot allocate memory
    tar: At beginning of tape, quitting now
    tar: Error is not recoverable: exiting

    I've googled around and there have been suggestions that I use --blocking-factor=128 when creating my backup and restoring. I still get the same error.

    It's also worth noting that if I just use tar, everything works 100%, including the restore, so perhaps pv is breaking it?

  • Related Answers
  • N.N.

    Solved it, pv was creating a different block / buffer size ...

    From the pv man page:

    The default buffer size is the block size of the input file’s filesystem multiplied by 32 (512kb max), or 400kb if the block size cannot be determined.

    From the tar man page:

    block size of Nx512 bytes (default N=20)

    So give the correct buffer size to pv as (20 x 512 = 10240)

    tar -cf - /home/myuser/ | pv -B 10240 -s 142524k > /dev/nst0

    Now if you test the archive with tar -tvf /dev/nst0, it should work.