Reputation: 97
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!
Upvotes: 0
Views: 91
Reputation: 11355
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
Upvotes: 1