2

To backup my document root (/var/www/html/ I can execute):

zip -r ~/backups/all_zipped-$(date +\%F-\%T).zip /var/www/html/

The problem is that inside the created zip file, I get 3 base directories instead of 1:

  1. var.
  2. www.
  3. html.

The desired end state is to have only 1 base directory (the last one). In this case, of course, html (and its inodes).

Using zip -r ~/backups/all_zipped-$(date +\%F-\%T).zip /var/www/html/* (note the *), didn't help.

How to zip current directory without its entire path?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • is there any particular reason why you're using zip rather than tar? do you need to share the backups with windows systems? – cas Jan 28 '18 at 08:32
  • Comfortability. Indeed, it's shared with Windows systems, there it's extracted by WinRAR. – Arcticooling Jan 28 '18 at 08:36
  • Add output of unzip -l ~/backups/all_zipped-$(date +\%F-\%T).zip to your question. If necessary, reduce the number of lines to the important lines. – Cyrus Jan 28 '18 at 09:14

1 Answers1

4

By default, zip stores relative paths, not absolute ones, so if you perform the zip operation from the /var/www directory, you should get what you want. In the one-liner below, cd - returns you to whatever directory you were in before.

cd /var/www && zip -r ~/backups/all_zipped-$(date +\%F-\%T).zip html/ && cd -
Cyrus
  • 12,309
user1404316
  • 3,078
  • I don't see how my edit https://unix.stackexchange.com/review/suggested-edits/228048 does not improve the post even a little bit. Downvoting for the poor formatting you chose to retain. – Olorin Jan 28 '18 at 07:41
  • Current formatting is fine and your formatting didn't improve anything. – xenoid Jan 28 '18 at 15:05
  • @xenoid OP used GitHub-style triple-backtick formatting. That's not a proper code block in Stack Exchange Markdown. See how Cyrus's edit has changed. That's exactly what I tried to do. Please read https://unix.stackexchange.com/editing-help/#code and familiarize yourself with the formatting here. – Olorin Jan 29 '18 at 01:31