Table of Contents
How to copy files \ directories \ filesystems via network.
The article describes ways of copying content over network.
When upgrading a home server, I copy all the data from the old server to a new system. In the examples below, I work from the new server and both servers are on the same subnet:
- New server (IP: 192.168.0.14)
- Old server (IP: 192.168.0.1)
scp commands communicate over a secure connection (TCP port 22). Please note that you need to enable the
sshd daemon on the remote host.
Copy Files / Directories
If you need to copy single files or directories, you can use the
scp -r -v -p email@example.com:/etc /local_dir
- -r: recursive (copy all the content of
/etcincluding its subdirectories)
- -p: preserve file attributes (eg. file creation or modification times)
- -v: verbose output
In the example above we copy the
/etc directory located on a remote host (the old server: 192.168.0.1) to
/local_dir on the local host (“new” server).
Please note that the
scp command cannot copy the whole file system hierarchy including
/lost+found. Fortunately, there is a workaround which was provided by Patrick Volkerding.
Copy whole filesystem hierarchy
The following command should successfully copy a whole filesystem hierarchy:
ssh firstname.lastname@example.org "(cd / ; tar cf - . )" | (mkdir -p /local_dir ; cd /local_dir ; umask 000 ; tar xvf -)
- Originally written by John Ciemgals 2013/02/10 03:51
- With help from Patrick Volkerding