Copy the last file from folder regardless of age

I have a script, that downloads the latest backup of my database when I set up a new server with this:

rclone copy --max-age 30m backup:backups /root/

However that will fail if for some reason if the file has a bigger --max-age for any reason.

So I check if there's a sql file or not then increase the --max-age to 1h, but I feel like this could eventually cause rclone to download 2 files, which would mess up the mysql import of the sql files...

Is there a cleaner way to tell rclone to copy the latest file of that folder, regardless of it's age? So I can trust that rclone will download ONLY one file, and the latest.

Hope I'm clear, thanks.

"rclone lsf" have some flags, e.g. --format, --separator

What an OS? I think, you can find last modified file in folder by "sort" command.
Something like:

rclone lsf --format "tp" --files-only remote:folder/ | sort

Is the last file in the list the right one? If true, add tail, awk or another command after "sort". E.g.:

rclone ... | sort | awk -F";" 'END{print $2}'
1 Like

Here is what I'd do which is very similar to @igor_andreev 's solution except I don't know awk that well!

rclone lsf --files-only --include "*.sql" -Ftp remote:folder | sort | tail -1 | cut -d';' -f2 > latest


rclone copy remote:folder --files-from latest /root/

If rclone had a --max-transfer flag then you could do it with that and --order-by but it doesn't yet.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.