rsync : Recursively sync all files while ignoring the directory structure

后端 未结 4 860
一生所求
一生所求 2021-02-12 18:45

I am trying to create a bash script for syncing music from my desktop to a mobile device. The desktop is the source.

Is there a way to make rsync recursively sync files

4条回答
  •  后悔当初
    2021-02-12 19:28

    Simply:

    rsync -a --delete --include=*.mp3 --exclude=* \
        pathToSongs/Theme*/Artist*/. destuser@desthost:Music/.
    

    would do the job if you're path hierarchy has a fixed number of level.

    WARNING: if two song file do have exactly same name, while on same destination directory, your backup will miss one of them!

    If else, and for answering strictly to your ask ignoring the directory structure you could use bash's shopt -s globstar feature:

    shopt -s globstar
    rsync -a --delete --include=*.mp3 --exclude=* \
        pathToSongsRoot/**/. destuser@desthost:Music/.
    

    At all, there is no need to fork to find command.

    Recursively sync all files while ignoring the directory structure

    For answering strictly to question, there must no be limited to an extension:

    shopt -s globstar
    rsync -d --delete sourceRoot/**/. destuser@desthost:destRoot/.
    

    With this, directories will be copied too, but without content. All files and directories would be stored on same level at destRoot/.

    WARNING: If some different files with same name exists in defferents directories, they would simply be overwrited on destination, durring rsync, for finaly storing randomly only one.

提交回复
热议问题