Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I'm trying to do an incremental backup of all files on my NAS box that where modified in the last 24 hours (or so, can be more flexible).

I'm using PuTTY to connect through SSH to a ReadyNAS 102 which has BusyBox v1.20.2 and uses Bash.

I origianlly used:

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

And then tried:

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

which got me the error:

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.

share|improve this question

marked as duplicate by Graeme, Anthon, slm, Braiam, terdon Mar 7 at 17:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
This doesn't add anything new from your last tow questions, as such the answers are largely the same. You say that rsync is not working as expected, if you want to get help with it you should explain what you have tried and how it doesn't work instead of reiterating what you have already asked. –  Graeme Mar 7 at 16:44

2 Answers 2

Great! Rsync is your beast and is is well worth the learning curve, (there are many options). I wouldn't bother with worrying about your find modified last 2 days requirement either, since rsync will check for modification (which achieves more or less the the same, cuts down on what is transfered and only copies files that have been updated compared to destination).

rsync -va srcdir destdir

I added the -v for verbosity only so you can see what's going on. if your were copying remotely (over internet to a remote computer) then --progress will show progress during the copy of each individual file.

If you want to exactly match your directory, ie. if you want rsync to remove files on destination that are no longer on source (because they've been deleted) this is possible as well with --delete, but I think you are creating an archive so I didn't use that in the example.

Further options depend on your specific requirements (follow links ? etc). I'll leave that to you to choose man rsync

You can give it include lists, exclude lists, as well in case you're copying a development area which might contain backup files from editors.

Summary of archive options

-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
-r recursive
-l copy symbolic links as symbolic links
-p preserve attributes
-t preserve times
-g preserve group
-o preserve owner
-D preserver devices (must be super user to work)

If you are copying between machiens then your need to consider time synchronisation or fuzzy time matching but you are copying onto sd card on one computer so no need to worry.

If you really want to use find then rsync can take a list of files from a file with --files-from in which case the -r (recursive) option of archive mode is not respected.

find . -mtime 2 | rsync -av --files-from - srcdir destdir

But please read the manual page since --files-from has side affects, and I thought there was too much to copy into this answer.

If your destination might be updated somewhere else you can add,

-u, --update                skip files that are newer on the receiver
share|improve this answer
    
The -u option is only necessary if the files at the destination may change - this is usually not the case with a backup. If it is the case, then unison is a much better tool to use. –  Graeme Mar 7 at 16:36
    
@Graeme tks have updated to reflect your comment. –  X Tian Mar 7 at 17:15

It's not clear to me where you want the output to go, but:

find . -mtime -2 | cpio -co > whatever.cpio

Should work. Apparently -m "is meaningless with" -o (note I don't know why you want -c here, but I left it in). If you want the stuff mirrored to a directory instead (i.e., no cpio file), use -p with an argument instead:

find . -mtime -2 | cpio -mp /backup/path
share|improve this answer
    
The idea here was to create and extract an archive since the OP's BusyBox cpio isn't built with a -p option. It doesn't work since creating an archive with BusyBox cpio needs -H too. See unix.stackexchange.com/questions/118558/… –  Graeme Mar 7 at 16:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.