Is the busybox cpio THAT different from GNU cpio

busyboxcpio

I'm trying to do an incremental backup using cpio but it seems that the busybox version doesn't work the same as the normal one? This is what I've got so far:

find data/Backup -mtime -2 | cpio -cm media/USB_FLASH_2

I origianlly used:

find . -mtime -2 | cpio -cm /media/USB_FLASH_2

However, I've seen people say busybox doesn't like definitive paths while using cpio. Unsure about that though.

It returns an error that basically says I'm using cpio wrong. I can't find anyone using the busybox cpio to do things like this, does that mean i can't do it? I've looked at using rsync as well but again, it doesn't do what i would expect.

For reference I'm using PuTTY to connect through SSH to a ReadyNAS 102.

After using find . -mtime -2 | cpio -o | { cd /media/USB_FLASH_2 && cpio -imd; }

i get the output:

BusyBox v1.20.2 (Debian 1:1.20.0-7) multi-call binary.

Usage: cpio [-dmvu] [-F FILE] [-H newc] [-tio] [EXTR_FILE]...

Extract or list files from a cpio archive, or
create an archive using file list on stdin

Main operation mode:
        -t      List
        -i      Extract EXTR_FILEs (or all)
        -o      Create (requires -H newc)
        -d      Make leading directories
        -m      Preserve mtime
        -v      Verbose
        -u      Overwrite
        -F FILE Input (-t,-i,-p) or output (-o) file
        -H newc Archive format

Best Answer

The options that the BusyBox commands have depends a lot on the options that BusyBox is compiled with. BusyBox aims to be highly configurable so that very small cut down versions can be compiled for systems where resources are very limited. Larger, more full featured versions can be built where this isn't an issue.

In your case cpio needs the -p or --pass-through (long form) option enabled. Normally cpio behaves more like an archive utility like tar, however it also has an extra function which allows it to copy files. To enable this in BusyBox, it needs to be built with FEATURE_CPIO_P defined (also LONG_OPTS for long form options to be enabled for any program).

From your last question, I strongly recommend that you use rsync for what you are doing. You are probably better off asking another question detailing exactly what you are doing with rsync and why it doesn't do what you expect. rsync is an extremely versatile tool and can no doubt be configured to do what you want.

That said, you could try the following with cpio, this will create an archive and then extract it again (somewhat less efficient, but still the same result):

find . -mtime -2 | cpio -o | { cd /media/USB_FLASH_2 && cpio -imd; }

Unfortunately the -o option can also be disabled in BusyBox (FEATURE_CPIO_O build option), so this may not work either.

Update

Based on this line of output, you need to add an extra option when creating an archive:

    -o      Create (requires -H newc)

This changes the command to:

find . -mtime -2 | cpio -oH newc | { cd /media/USB_FLASH_2 && cpio -imd; }

This time I have tested with the cpio in the BusyBox for my own system and it works for me, however in some cases the mtimes for directories won't be preserved. rsync should be the best way to do this.

Related Question