How to make rsync delete directories from destination that are not in the source listrsync list of files in...

Yandex Programming Contest: Alarms

Smart people send dumb people to a new planet on a space craft that crashes into a body of water

Plot exactly N bounce of a ball

What does "Marchentalender" on the front of a postcard mean?

Can a Beholder use rays in melee range?

Different PCB color ( is it different material? )

SQL Server (JOIN) all from first with NULLs from 2nd

Why does the 6502 have the BIT instruction?

Crossing US border with music files I'm legally allowed to possess

Transform the partial differential equation with new independent variables

Is my router's IP address really public?

How to properly maintain eye contact with people that have distinct facial features?

1960s sci-fi novella with a character who is treated as invisible by being ignored

Why do Russians call their women expensive ("дорогая")?

Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?

How feasible is the Delta-Glider?

How can I find where certain bash function is defined?

How can I prevent interns from being expendable?

What are the problems in teaching guitar via Skype?

Comment dit-on « I’ll tell you what » ?

Uses of T extends U?

Restoring order in a deck of playing cards

How to prevent bad sectors?

Is it ok to put a subplot to a story that is never meant to contribute to the development of the main plot?



How to make rsync delete directories from destination that are not in the source list


rsync list of files in sub-directories to remote server and delete extraneousrsync, delete files on receiving side that were deleted on sending side. (But don't delete everything)rsync question syncing source with destination (archiving surplus files on destination)Delete destination directories with rsync (contents as well as parent)Does rsync delete files on the destination that were deleted from the sending side?Comparing 2 directories and copying the different sub-directories to a 3rd directoryRaspbian, debian: Howto make find $SOURCE return all directories under $SOURCE without itselfHow to copy from multiple source directories to a single destination?rsync - include “only” source directoriesrsync --delete with superset destination folder






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I'm familiar with rsync, but having trouble with one issue..



I want to be able to sync files from multiple directories to one directory. If I remove a directory from the source list, then I want that directory and all of its files to be removed from the destination.



Here's a quick sample:



mkdir dir1
touch dir1/file1
mkdir dir2
touch dir2/file2
mkdir dir3
rsync -a dir1 dir2 dir3


dir3 now contains "dir1/file1" and "dir2/file2".



If I rsync again, and remove dir2 from the list:



rsync -a dir1 dir3


Then I would like dir2/file2 and dir2 to be removed from the destination.



The --delete option to rsync only handles deletes between dir1 and dir3/dir1, so dir2 remains (even if using --delete).



I've looked through the various option in the man page for rsync, and I don't see any option that tells rsync to "combine" all the sources and consider them as "one" tree so that "--delete" would do what I want it to do. However, I'm pretty confident I'm not the first person to want to do something like this.



Ideas?










share|improve this question























  • I think it's not possible using the syntax that you want. I think you nail it with your last paragraph. rsync doesn't "know" about dir2, so it won't delete it.

    – Sparhawk
    28 mins ago


















1















I'm familiar with rsync, but having trouble with one issue..



I want to be able to sync files from multiple directories to one directory. If I remove a directory from the source list, then I want that directory and all of its files to be removed from the destination.



Here's a quick sample:



mkdir dir1
touch dir1/file1
mkdir dir2
touch dir2/file2
mkdir dir3
rsync -a dir1 dir2 dir3


dir3 now contains "dir1/file1" and "dir2/file2".



If I rsync again, and remove dir2 from the list:



rsync -a dir1 dir3


Then I would like dir2/file2 and dir2 to be removed from the destination.



The --delete option to rsync only handles deletes between dir1 and dir3/dir1, so dir2 remains (even if using --delete).



I've looked through the various option in the man page for rsync, and I don't see any option that tells rsync to "combine" all the sources and consider them as "one" tree so that "--delete" would do what I want it to do. However, I'm pretty confident I'm not the first person to want to do something like this.



Ideas?










share|improve this question























  • I think it's not possible using the syntax that you want. I think you nail it with your last paragraph. rsync doesn't "know" about dir2, so it won't delete it.

    – Sparhawk
    28 mins ago














1












1








1








I'm familiar with rsync, but having trouble with one issue..



I want to be able to sync files from multiple directories to one directory. If I remove a directory from the source list, then I want that directory and all of its files to be removed from the destination.



Here's a quick sample:



mkdir dir1
touch dir1/file1
mkdir dir2
touch dir2/file2
mkdir dir3
rsync -a dir1 dir2 dir3


dir3 now contains "dir1/file1" and "dir2/file2".



If I rsync again, and remove dir2 from the list:



rsync -a dir1 dir3


Then I would like dir2/file2 and dir2 to be removed from the destination.



The --delete option to rsync only handles deletes between dir1 and dir3/dir1, so dir2 remains (even if using --delete).



I've looked through the various option in the man page for rsync, and I don't see any option that tells rsync to "combine" all the sources and consider them as "one" tree so that "--delete" would do what I want it to do. However, I'm pretty confident I'm not the first person to want to do something like this.



Ideas?










share|improve this question














I'm familiar with rsync, but having trouble with one issue..



I want to be able to sync files from multiple directories to one directory. If I remove a directory from the source list, then I want that directory and all of its files to be removed from the destination.



Here's a quick sample:



mkdir dir1
touch dir1/file1
mkdir dir2
touch dir2/file2
mkdir dir3
rsync -a dir1 dir2 dir3


dir3 now contains "dir1/file1" and "dir2/file2".



If I rsync again, and remove dir2 from the list:



rsync -a dir1 dir3


Then I would like dir2/file2 and dir2 to be removed from the destination.



The --delete option to rsync only handles deletes between dir1 and dir3/dir1, so dir2 remains (even if using --delete).



I've looked through the various option in the man page for rsync, and I don't see any option that tells rsync to "combine" all the sources and consider them as "one" tree so that "--delete" would do what I want it to do. However, I'm pretty confident I'm not the first person to want to do something like this.



Ideas?







rsync






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Jason KJason K

133




133













  • I think it's not possible using the syntax that you want. I think you nail it with your last paragraph. rsync doesn't "know" about dir2, so it won't delete it.

    – Sparhawk
    28 mins ago



















  • I think it's not possible using the syntax that you want. I think you nail it with your last paragraph. rsync doesn't "know" about dir2, so it won't delete it.

    – Sparhawk
    28 mins ago

















I think it's not possible using the syntax that you want. I think you nail it with your last paragraph. rsync doesn't "know" about dir2, so it won't delete it.

– Sparhawk
28 mins ago





I think it's not possible using the syntax that you want. I think you nail it with your last paragraph. rsync doesn't "know" about dir2, so it won't delete it.

– Sparhawk
28 mins ago










1 Answer
1






active

oldest

votes


















0














The --delete flag obviously doesn't work if you sync multiple source directories to one destination directory. Instead of syncing dir1 and dir2 to dir3 you could sync the content of parent dir of dir1 and dir2.



Example (using rsync flag -i to see the changes):



$ mkdir -p dir12/dir1 dir12/dir2 dir3
$ touch dir12/dir1/file1 dir12/dir2/file2
$ rsync -ai dir12/ dir3
cd+++++++++ dir1/
>f+++++++++ dir1/file1
cd+++++++++ dir2/
>f+++++++++ dir2/file2
# BEFORE: dir1 and dir2 were synced to dir3
$ rm -rf dir12/dir2
$ rsync -ai --delete dir12/ dir3
*deleting dir2/file2
*deleting dir2/
.d..t...... ./
# AFTER: dir3/dir2 is gone


If you don't have a common parent directory, then dir12/dir2 could be a symlink pointing to the real directory. With option -L (--copy-links) in the first rsync call you would get the same directory structure in dir3 with dir2 as directory (instead of a symlink). And after deleting symlink dir12/dir2 and syncing again with --delete the directory dir3/dir2 would be gone like in the example.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521406%2fhow-to-make-rsync-delete-directories-from-destination-that-are-not-in-the-source%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The --delete flag obviously doesn't work if you sync multiple source directories to one destination directory. Instead of syncing dir1 and dir2 to dir3 you could sync the content of parent dir of dir1 and dir2.



    Example (using rsync flag -i to see the changes):



    $ mkdir -p dir12/dir1 dir12/dir2 dir3
    $ touch dir12/dir1/file1 dir12/dir2/file2
    $ rsync -ai dir12/ dir3
    cd+++++++++ dir1/
    >f+++++++++ dir1/file1
    cd+++++++++ dir2/
    >f+++++++++ dir2/file2
    # BEFORE: dir1 and dir2 were synced to dir3
    $ rm -rf dir12/dir2
    $ rsync -ai --delete dir12/ dir3
    *deleting dir2/file2
    *deleting dir2/
    .d..t...... ./
    # AFTER: dir3/dir2 is gone


    If you don't have a common parent directory, then dir12/dir2 could be a symlink pointing to the real directory. With option -L (--copy-links) in the first rsync call you would get the same directory structure in dir3 with dir2 as directory (instead of a symlink). And after deleting symlink dir12/dir2 and syncing again with --delete the directory dir3/dir2 would be gone like in the example.






    share|improve this answer




























      0














      The --delete flag obviously doesn't work if you sync multiple source directories to one destination directory. Instead of syncing dir1 and dir2 to dir3 you could sync the content of parent dir of dir1 and dir2.



      Example (using rsync flag -i to see the changes):



      $ mkdir -p dir12/dir1 dir12/dir2 dir3
      $ touch dir12/dir1/file1 dir12/dir2/file2
      $ rsync -ai dir12/ dir3
      cd+++++++++ dir1/
      >f+++++++++ dir1/file1
      cd+++++++++ dir2/
      >f+++++++++ dir2/file2
      # BEFORE: dir1 and dir2 were synced to dir3
      $ rm -rf dir12/dir2
      $ rsync -ai --delete dir12/ dir3
      *deleting dir2/file2
      *deleting dir2/
      .d..t...... ./
      # AFTER: dir3/dir2 is gone


      If you don't have a common parent directory, then dir12/dir2 could be a symlink pointing to the real directory. With option -L (--copy-links) in the first rsync call you would get the same directory structure in dir3 with dir2 as directory (instead of a symlink). And after deleting symlink dir12/dir2 and syncing again with --delete the directory dir3/dir2 would be gone like in the example.






      share|improve this answer


























        0












        0








        0







        The --delete flag obviously doesn't work if you sync multiple source directories to one destination directory. Instead of syncing dir1 and dir2 to dir3 you could sync the content of parent dir of dir1 and dir2.



        Example (using rsync flag -i to see the changes):



        $ mkdir -p dir12/dir1 dir12/dir2 dir3
        $ touch dir12/dir1/file1 dir12/dir2/file2
        $ rsync -ai dir12/ dir3
        cd+++++++++ dir1/
        >f+++++++++ dir1/file1
        cd+++++++++ dir2/
        >f+++++++++ dir2/file2
        # BEFORE: dir1 and dir2 were synced to dir3
        $ rm -rf dir12/dir2
        $ rsync -ai --delete dir12/ dir3
        *deleting dir2/file2
        *deleting dir2/
        .d..t...... ./
        # AFTER: dir3/dir2 is gone


        If you don't have a common parent directory, then dir12/dir2 could be a symlink pointing to the real directory. With option -L (--copy-links) in the first rsync call you would get the same directory structure in dir3 with dir2 as directory (instead of a symlink). And after deleting symlink dir12/dir2 and syncing again with --delete the directory dir3/dir2 would be gone like in the example.






        share|improve this answer













        The --delete flag obviously doesn't work if you sync multiple source directories to one destination directory. Instead of syncing dir1 and dir2 to dir3 you could sync the content of parent dir of dir1 and dir2.



        Example (using rsync flag -i to see the changes):



        $ mkdir -p dir12/dir1 dir12/dir2 dir3
        $ touch dir12/dir1/file1 dir12/dir2/file2
        $ rsync -ai dir12/ dir3
        cd+++++++++ dir1/
        >f+++++++++ dir1/file1
        cd+++++++++ dir2/
        >f+++++++++ dir2/file2
        # BEFORE: dir1 and dir2 were synced to dir3
        $ rm -rf dir12/dir2
        $ rsync -ai --delete dir12/ dir3
        *deleting dir2/file2
        *deleting dir2/
        .d..t...... ./
        # AFTER: dir3/dir2 is gone


        If you don't have a common parent directory, then dir12/dir2 could be a symlink pointing to the real directory. With option -L (--copy-links) in the first rsync call you would get the same directory structure in dir3 with dir2 as directory (instead of a symlink). And after deleting symlink dir12/dir2 and syncing again with --delete the directory dir3/dir2 would be gone like in the example.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 17 mins ago









        FreddyFreddy

        3,6731417




        3,6731417






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521406%2fhow-to-make-rsync-delete-directories-from-destination-that-are-not-in-the-source%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...