Doc /

BackupByDate

Want to backup only files on date or range of date. May be tricky.

For example, I want to backup files not newer than january first 2016, from a folder that is not sorted by date. rsync do not know about dates, so one have first to filter with find.

But I also want to be able to remove files from the backup if ever I change order or remove duplicates of old files, so I want to use the rsync --delete option. This do not works with pipes.

So one have to first build a "fake" tree with the desired files. Links are enough, at least hard links, and do not spent nearly any space on disk. So first you create this tree.

But ln can't create folders... so first it's necessary to create them. As folder's date and file's dates may not match, better create all the folder (use mostly inodes, no real space on disk) and fill them with the necessary files.

Creating the folders (on examples):

find /data-ssd480/mesdocs-jdd/ -type d -exec mkdir -p /data-ssd480/tmp/{} \;

then filing with files:

find /data-ssd480/mesdocs-jdd/ -type f ! -newermt 2016-01-01 -exec ln '{}' '/data-ssd480/tmp/{}' \;

this new tree have only the files from the date wanted, so you can rsync --delete it to any position:

cd /data-ssd480/tmp

complete the next command with tab, in case the UID changed:

rsync -ai --delete-before . /run/media/jdd/0ae3a54f-b032-4a21-8180-14d5efc5577f/

if ever you get a medium full message, do the steps again for an older date. You can test (du -sh) the tmp folder to see what is it's size.

Summary

find /data-ssd480/mesdocs-jdd/ -type d -exec mkdir -p /data-ssd480/tmp/{} \; 
find /data-ssd480/mesdocs-jdd/ -type f  ! -newermt 2016-01-01  -exec ln '{}' '/data-ssd480/tmp/{}' \; 
cd /data-ssd480/tmp
rsync -ai  --delete-before . /run/media/jdd/0ae3a54f-b032-4a21-8180-14d5efc5577f/

Opposite

the other part of the files

first remove /data-ssd480/tmp, then change the media.

then:

find /data-ssd480/mesdocs-jdd/ -type d -exec mkdir -p /data-ssd480/tmp/{} \; 
find /data-ssd480/mesdocs-jdd/ -type f -newermt 2016-01-01  -exec ln '{}' '/data-ssd480/tmp/{}' \; 
cd /data-ssd480/tmp
rsync -ai  --delete-before . /run/media/jdd/0ae3a54f-b032-4a21-8180-14d5efc5577f/

Références

Musique.LierDesMp3