I have been using cpio many times and never settled on my favorite combination between operating system, hard drive block size, and best options to use. So I think its about time I dedicate some space to recording down my personal preferences so I do not have to keep reading the manual page once every blue moon while holding my elbow at a 45 degree angle. Update (20080923 15:14:39): In an attempt to transfer some files via FTP I found out a problem during an attempt to transfer RPM files. I tried using TAR but with no success. CPIO to the rescue!

Making the archive

I to use this method for archiving a directory for transportation to another server or for archiving purposes: find /path/to/start -type f | cpio -ovcBO /path/to/archive.cpio This says to find the files in the path of /path/to/start and look for only the file type of “file” (as opposed to block, character, directories, named pipes, symbolic links, sockets or doors) and then send that list off to cpio that says to:

  • -o accept incoming from the find command
  • -v be verbose and tell us what file it is reading
  • -c use the new SRV4 portable format
  • -B set the I/O block size to BLOCK-SIZE * 512 bytes
  • -O save to the archive file of /path/to/archive.cpio

I think this would be nice to bzip up as well to save time in transferring, but I will save that for a later update of this article.

Storing the archive on MSDOS partition that will be larger than 2GB

The file size limitation of MSDOS is annoying and old. To get around this problem, I used the program called split. But using split on a already existing file is boring. Lets use the output from gzip! Use the -b 1000m to limit each split to 1gb of data find /files/to/find/ -depth -print | cpio -oaV | gzip -c | split -d -b 1000m >  /mnt/target

Transferring between two hosts via ssh

If you need to copy files between two hosts via ssh. I came to find that this was my best option for keeping the modification times and permisssions: ssh [email protected] “cd /to/path && find dir -depth -print | cpio -oacV” | cpio -imVd What the above does is ssh to the remote host, change directory to where you have your data, find files in “dir” and copy them to the current directory of where you initiate this command.

Error messages

If you receive this error message:

truncating inode number

I have found that using the -c option will help allow for being compatible with your system.

Restoring

To restore your cpio archive, use the following: cpio -ivcI <archive path name>

comments powered by Disqus