You are not logged in.

#1 2023-03-09 15:54:56

AlbertMaier
Member
Registered: 2014-11-01
Posts: 7

rsync - Update in case of changed size or newer date

Hello,

I want to use rsync for a backup on a cloud storage via webdav. In this case the rsync -a option cannot be used, because the modification date of the file on the webdav has the date of the backup and not the date of the original file. So each time all files would be uploaded.

I want to upload the files if:
- the size is changed
OR
- the local date is newer than the date of the backup.

For this I currently run rsync twice:
1st run: rsync -- size-only, to backup in case the size is changed
2nd run: rsync -u, to backup in case the time is newer then the date of the backup

Is there a possibility to reach the same with one run? I think, if I combine both options, i.e. rsync -u --size-only, this would mean that the file is only uploaded in case the size is changed AND the time is newer. But I want to reach a OR and not a AND of both conditions.

Thanks
Albert

Offline

#2 2023-10-09 13:25:25

MrNordio
Member
Registered: 2023-02-10
Posts: 3

Re: rsync - Update in case of changed size or newer date

In rsync, combining the -u (or --ignore-existing) and --size-only options would indeed result in an "AND" condition, as you've noted. Unfortunately, rsync doesn't provide native support for using these options as an "OR" condition in a single command. It's explicitly designed to use multiple conditions in an "AND" manner when multiple conditions are specified.

However, there are alternative ways to achieve your goal:

    Custom Script: You could write a script that examines each file and decides whether to transfer it based on your custom criteria. This would give you complete control but would require more work to implement.

    Intermediate Step: Use a local intermediate directory where you first rsync with --size-only. Then run a second rsync from that intermediate directory to the cloud with the -u option. This also has the overhead of extra storage and double handling of the data.

    File List: Generate a list of files that meet either condition and then use rsync with --files-from=FILE to only sync those files.

Here's a pseudo-code outline for option 3:

    Run rsync with --size-only and --dry-run to get a list of files that would be transferred based on size.
    Run rsync with -u and --dry-run to get a list of files that would be transferred based on modification time.
    Combine these lists to get a unique set of files that meet either condition.
    Use rsync with --files-from=FILE where FILE contains the list of files to be transferred.

This is not as efficient as a single rsync command but may be a suitable workaround.

Offline

#3 2023-10-10 00:11:03

solskog
Member
Registered: 2020-09-05
Posts: 416

Re: rsync - Update in case of changed size or newer date

AlbertMaier wrote:

I want to upload the files if:
- the size is changed
OR
- the local date is newer than the date of the backup.

Sorry If I misunderstood, but I think the rsync --update option already doing this.

man rsync wrote:

--update, -u
              This forces rsync to skip any files which exist on the  destination  and
              have a modified time that is newer than the source file. (If an existing
              destination  file has a modification time equal to the source file's, it
              will be updated if the sizes are different.)

Last edited by solskog (2023-10-10 00:13:08)

Offline

#4 2023-10-10 19:16:40

MrNordio
Member
Registered: 2023-02-10
Posts: 3

Re: rsync - Update in case of changed size or newer date

Hey Albert and solskog,

Thank you for the insights, solskog. Upon revisiting the man page for rsync, I realized that you are correct. The --update or -u option in rsync indeed caters to the conditions AlbertMaier is interested in.

The -u option skips files that are newer on the destination, while updating those that have a size difference, which effectively addresses both of Albert's criteria in a single rsync command. Therefore, using rsync with the -u option should suffice for this backup task, eliminating the need for multiple rsync runs or additional scripts.

It's always beneficial to have a fresh perspective on a problem. I appreciate the correction and Albert, I hope this solution simplifies your backup process.

Best,
MrNordio

Offline

#5 2023-10-10 22:33:17

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: rsync - Update in case of changed size or newer date

Thanks for the information. The OP has not been back since the first post in March, so I am going to consider this thread abandoned and close it now.

Offline

Board footer

Powered by FluxBB