Advanced

CPIO command to backup and restore in Linux

Posted by zinoune on · 8 comments
Unixmen
Mail this story
Print this story

The cpio command is one of the most commonly used Linux back up tools. The cpio command has two unusual features. Unlike tar , in which the files to back up are typed in as part of the command, cpio reads the files to work with from the standard input (in other words, the screen). This feature means that cpio must be used as part of a multiple command or with a redirection pipe.

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (8)

caitlyn ·
A while back I did some work for a company which had downsized and consolidated their six R&D locations into a single office with a much smaller team. They wanted to consolidate their servers as well which made sense under the conditions. Anyway, to make a long story short, we needed to archive the filesystems, transfer them via NFS to their new home, and unarchive them in the appropriate place. The tool that I used to do this was cpio. It was far and away the fastest and most efficient way to handle large amounts of data.

cpio has been around in *nix forever. It's a pity more people don't know about it and use it. I'm amazed how many sysadmins I've talked to who just never tried using cpio.
gus3 ·
Dumb question time.

Why not use SFTP (or FTP if it was trusted) to transfer the archives, and just run cpio locally? In my experience, even network tar/gzip pipes is more efficient than NFS for bulk transfers.

EDIT: Fixed semantic error.
caitlyn ·
@gus3: We tried it and on the network in question cpio proved to be faster. Obviously, YMMV. Their network had, um... interesting issues that may have played a part. In any case, even locally, cpio is faster than tar.
gus3 ·
Apparently, I didn't fix enough of the semantic error to be clear. Seems to be a habit lately.

My impression from your first comment, is that you had an NFS mount, and were running cpio on the NFS client, while the files you unpacked were sent via NFS to the server.

What I'm wondering is, why you didn't use a streaming (not datagram) protocol to transfer the archive to the server, then run cpio directly on the server?
caitlyn ·
I think I was the one who didn't communicate clearly. We tried what you suggest. It wasn't faster in their environment. There were a lot of issues with that network which might have contributed to that result but the fact is that using cpio across an NFS mount worked better.
Steven_Rosenber ·
What advantages does this method have over using rsync?
gus3 ·
Rsync uses TCP. The dodgy network in question apparently deals better with datagram transmission than with streams.
caitlyn ·
@Steven: In addition to the issues regarding transmission of large arcives that gus3 and I have been discussing there is the issue of creating the archive itself. cpio is much faster than tar as I mentioned before. The combination of the two speed improvements made the choice a no-brainer.

Oh, and the script to do this was two lines long: one to do the archive, transfer, and unarchive and the second to send a notification that the process was completed.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post