hi i'am usin Ubuntu server 14.04 I want to backup all data in /mnt/backups/(pictures music etc.) i use:

tar -cvpzf backup.tar.gz /mnt/backups/

and i want recover into /home/john/recover/ i use:

tar –xvpzf backup.tar.gz –C /home/john/recover/

but then I recover in /home/john/recover it looks like:

/home/john/recover/mnt/backups/(and all my data,pictures music etc.)

Is there a way to make /home/john/recover/(and all my data,pictures music etc.) or I do something wrong or its just what tar does? Thanks. P.S. sorry for any spelling mistakes :))

1 Answer 1


tar cares about your present working directory at invocation time.

What you want to do is:

cd /mnt/backups/
tar -cvpzf backup.tar.gz *
cd /home/john/recover/
tar –xvpzf backup.tar.gz
  • still after recover i get mnt, i'am using tar with cron
    – AbsentasLT
    May 22, 2014 at 19:35
  • I'd made a typo on the second line. Instead of specifying the full path, just a shellglob wildcard should be sufficient.
    – James S.
    May 22, 2014 at 19:39
  • it worked with tar -cvpzf backup.tar.gz * tar –xvpzf backup.tar.gz -C /home/john/restore
    – AbsentasLT
    May 22, 2014 at 19:44
  • Awesome. I tested it here before posting, but had typed incorrectly. Sorry for the initial confusion.
    – James S.
    May 22, 2014 at 19:48
  • 1
    The --file option can specify a file anywhere, so tar -cvpzf /testing/backup.tar.gz /mnt/backups/ will work, but you will get the /mnt/backups/ directory structure, because the files in the directory will always be archived relative to the working directory, and the directory will be re-created along with its contents when the archive is extracted. So if you don't want the /mnt/backups/ part, your script must change into that directory first, like: cd /mnt/backups/ && tar -cvpzf /testing/backup.tar.gz *
    – James S.
    May 22, 2014 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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