[Python] Copying files with rsync based on their file age and removing extraneous data in the...

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I want to copy the files of the last 24 hours from one directory (source) to a remote host (target). All extraneous data on the target host should be deleted.

    As far as my research went there is no rsync flag to filter input files by their modified date. If there is, please let me know.

    In the end I would like to use the code in python but for the sake of compatibility the solution should also work on the console.

    My first attempt was to create a list of the files that ought to be copied via find . -mtime {} -type f and to save it inside a file that is then given to rsync via --files-from. The full command would by something like

    find . -mtime -2 -type f > files.txt
    rsync --delete --files-from files.txt /sourcedir user@target:/targetdir


    This does copy only the files from files.txt but unfortunately it does not delete any extraneous files in the targetdir. It is my understanding, that --files-from only looks at the files in files.txt and ignores any other files in source and target.

    Continue reading...

Compartilhe esta Página