cd to the parent of the source directoryUse the following command:
tar -cf - sourcedir | "cd destdirparent && tar -xf -"
where:
sourcedir is the directory to copy
destdirparent is the parent directory to copy the directory to
The -f - option tells tar to write the archive to stdout or read the archive from stdin as the case may be.
Placing the command after the pipe in quotes causes it to run in a subshell. This means that the two halves to the command can operate in different directories. The && means that if the cd command fails the tar won’t run either.
For example:
cd /home/fred tar -cf - Maildir | "cd /d02/backup/fred && tar -xf -"
Note also that the source directory could be the current directory.
2 Comments
“Note also that the source directory could be the current directory.”
The results from doing this could be interesting…
Depending on the OS and circumstances I tend to use either cpio:
sudo find /home/fred | sudo cpio -pmduV /d02/home
or rsync:
sudo rsync -vaPHx /home/fred /d02/home/
The latter will preserve hardlinks.
Post a Comment