4

How to copy all files from /var/www onto a flash disk without changing owners of folders in the /var/www folder? (Or how to insert the whole /var/www folder into an archive and put it onto a flash disk)

My system:

Debian 6 (Linux PSB1 2.6.32-5-686 #1 SMP Mon Sep 23 23:00:18 UTC 2013 i686)

Raphael Ahrens
  • 9,701
  • 5
  • 37
  • 52
PSSGCSim
  • 145
  • 1
  • 1
  • 5

4 Answers4

8
cp -rp /var/www/ /path/to/flash/disk/

From cp manpage:

-p     same as --preserve=mode,ownership,timestamps

--preserve[=ATTR_LIST]
      preserve the specified attributes (default: mode,ownership,timestamps),
      if possible additional attributes: context, links, xattr, all
Tobias
  • 567
  • 3
  • 10
2

First mount your usb.

 $ mkdir -p /mnt/myusb
 $ mount -t vfat -o rw,users /dev/sda1 /mnt/myusb
 $ mount

After that you can use rsync command to do this wirh -avz arguments

rsync -avz /var/www /mnt/myusb

This will keep permissions, owner and links of /var/www .

klerk
  • 2,779
  • 2
  • 16
  • 15
1

You must be root (or have CAP_CHOWN and CAP_FOWNER and probably also CAP_DAC_OVERRIDE, and CAP_DAC_READ_SEARCH) in order to do that. Then it is simple: cp -a

Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
0

If your filesystem is capable of preserving the ownership information, then cp -a (archive) preserves all parameters (permission, ownership, links, extended attributes).

orion
  • 12,302
  • 2
  • 31
  • 41