A simple and easy way to copy a file system between two Linux servers


During my tenure as a SysAdmin, I can’t recall how many times I’ve needed to duplicate the contents of a file systems between systems. I’ve used a variety of solutions to do this, including array-based replication, database replication and tools such as rsync and tar piped to tar over SSH. When rsync and tar where the right tool, I often asked myself why there wasn’t a generic file system replication tool when I completed my work. Well, it appears there is. The cpdup utility provides an easy to use interface to copy a file system from one system to another. In it’s most basic form you can call cpdup with a source and destination file system:

$ cpdup -C -vv -d -I /data 192.168.56.3:/data

root@192.168.56.3's password:
Handshaked with fedora2
/data
Scanning /data ...
Scanning /data/conf ...
/data/conf/main.cf.conf copy-ok
/data/conf/smb.conf copy-ok
/data/conf/named.conf copy-ok
Scanning /data/www ...
Scanning /data/www/content ...
Scanning /data/www/cgi-bin ...
Scanning /data/dns ...
/data/lost+found
Scanning /data/lost+found ...
cpdup completed successfully
1955847 bytes source, 1955847 src bytes read, 0 tgt bytes read
1955847 bytes written (1.0X speedup)
3 source items, 8 items copied, 0 items linked, 0 things deleted
3.8 seconds 1007 Kbytes/sec synced 503 Kbytes/sec scanned

This will cause the entire contents of /data to be migrated through SSH to /data on the remote server. It appears cpdup picks up everything including devices and special files, so this would be a great utility to clone systems. There are also options to replace files that are on the remote end, remove files that are no longer on the source, and various others that can be used to customize the copy operation. Nifty utility, and definitely one I’ll be adding to my utility belt.

This article was posted by Matty on 2011-01-01 23:14:00 -0400 -0400