0

I have a backup of a website that I created using the tar command below:

tar -cvpzf backup.tar.gz /var/www/vhosts/example.com/httpdocs

I see that in the archive file, it has saved the entire path (/var/www...) and when I try to restore it, all these folders are created in the destination folder. Should I use the below command instead to backup the website?

tar -cvpzf backup.tar.gz -C /var/www/vhosts/example.com/httpdocs .

and restore the backup using this?

tar -xvpzf backup.tar.gz -C /var/www/vhosts/example.com/httpdocs --numeric-owner

You may also suggest a better backup method for my situation - I need to backup the files and database dump of a website to a single .tgz file and store in my external HDD.

Note: I'm also considering Duplicity. http://duplicity.nongnu.org/

melvincv
  • 5
  • 4
  • For future backups the trivial solution would would be `cd /var/www/vhosts` followed by `tar -cvpzf /my_backups/backup.tar.gz example.com/httpdocs`. – Hennes Feb 21 '15 at 15:18
  • Won't that store the path example.com/httpdocs in the archive? – melvincv Feb 21 '15 at 15:26
  • Yes. If you wish you can trim the path down further. I left that in because I assumed multiple vhost might be backupped and this would keep some of the structure, yet it will allow you to extract the file in any place you want because it does not start with a leading slash. Speaking of a leading slash in a pathname. [see this link](http://www.gnu.org/software/tar/manual/html_node/absolute.html) about gnu tar. (not sure how other tars behave, but I suspect most will complain/warn when you use that command with a leading slash. Running into this problem requires ignoring that warning. – Hennes Feb 21 '15 at 15:31

1 Answers1

0

If I understand correctly, you want to unpack the files without the directory structure. Looking at this question - tar – extract discarding directory structure - I've found the option that works for me:

zcat backup.tar.gz | pax -v -r -s '/.*\///p'
bushi
  • 26
  • 3
  • Looks complicated... I want to backup and restore using tar alone. – melvincv Feb 21 '15 at 13:33
  • Or I could use an alternative, but better and simple solution. – melvincv Feb 21 '15 at 13:34
  • Edited the code so you just need to paste the command into the terminal (if you're in the file folder). Tar itself doesn't have such option (according to the question page). You can unpack normally, then remove direcory structure with several commands, but I think this is simplier. – bushi Feb 21 '15 at 14:36