ディレクトリ構造を維持したままファイルをバックアップ

下記のように、ディレクトリ構造を維持したままファイルをバックアップする場合、

mkdir /path/to/backup/var/www/html/
cp /var/www/html/wp-config.php /path/to/backup/var/www/html/wp-config.php

rsync-Rオプションを使うとワンラインでできるぞ。

rsync -avR /var/www/html/wp-config.php /path/to/backup/
# man rsync
    .
    .
    .
       -R, --relative
              Use  relative paths. This means that the full path names specified on the command line are sent to the server rather than just the
              last parts of the filenames. This is particularly useful when you want to send several different directories at the same time. For
              example, if you used this command:

                 rsync -av /foo/bar/baz.c remote:/tmp/

              ... this would create a file named baz.c in /tmp/ on the remote machine. If instead you used

                 rsync -avR /foo/bar/baz.c remote:/tmp/

              then  a  file  named  /tmp/foo/bar/baz.c  would be created on the remote machine -- the full path name is preserved.
    .
    .
    .