0

I am working on the incremental backup to backup files that were modified in the last 24 hours. I am trying to avoid copying all the directories as can be seeing from the tree command. Maybe it's cpio that is doing it. Don't know the alternative of ignoring all the folders. The backup works perfectly fine but its just that it copies all the directories as well starting from the root and to the destination of the files. What can I do to copy just the files and not the directories within the entire $bksource.

#!/bin/bash
bkdest="/home/user/backup/incremental"
bksource="/home/user/Documents"
                target=${bkdest}/bk.inc.$(date +%Y_%m_%d_%H_%M_%S)
                mkdir -p $target
                find "$bksource" -type f -mtime 0 | cpio -mdp "$target"

Here is the tree after the backup. I am seeing all the last 24 hours modified files but it brought folders directories with it as but only backups last modified files in the Documents which is good.

[user@localhost bk.inc.2015_08_02_21_56_41]$ tree
   .
    └── home
        └── user
            └── Documents
                ├── newinc1
                ├── newinc2
                    └── newinc3

If someone has a solution, I would really appreciate that. Thank you!

Dmitriy
  • 97
  • 3
  • 15

1 Answers1

1

Make use of rsync

rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' bksource bkdest

Note that using source and source/ are different. A trailing slash means to copy the contents of the folder source into destination. Without the trailing slash, it means copy the folder source into destination.

Alternatively, if you have lots of directories (or files) to exclude, you can use --exclude-from=FILE, where FILE is the name of a file containing files or directories to exclude.

--exclude may also contain wildcards, such as --exclude=*/.svn*

UPDATE: To transfer only a list of files obtained from your find command with absolute paths, then it might look something like:

rsync -av --files-from=/path/to/files.txt / /destination/path/

You can make use of --dry-run to test the files

Community
  • 1
  • 1
Srini V
  • 11,045
  • 14
  • 66
  • 89
  • I'm a bit confused with this. So I am using find and mtime to find files that have been modified the past 24 hours. So basically I can pipe it into the rsync command you recommended? will it go like this? " find "$bksource" -type f -mtime 0 | rsync -av --exclude='/home/' --exclude='/user/' bksource bkdest" Thanks! – Dmitriy Aug 03 '15 at 06:35
  • Make a list of file from your find and mtime. Then pipe it to rsync as a list of files. That would be a different syntax – Srini V Aug 03 '15 at 08:16