How to copy a btrfs filesystem












13















How can make a full copy of the contents of a btrfs filesystem?
By full copy I mean not only the current data, but also different subvolumes with their snapshots, ideally preserving their CoW structures (i.e.: not duplicating blocks with the same content.



It seems a block-level copy (such as with dd) is not a good idea, since it duplicates the UUID, and there isn't a way to easily change it, apparently.










share|improve this question





























    13















    How can make a full copy of the contents of a btrfs filesystem?
    By full copy I mean not only the current data, but also different subvolumes with their snapshots, ideally preserving their CoW structures (i.e.: not duplicating blocks with the same content.



    It seems a block-level copy (such as with dd) is not a good idea, since it duplicates the UUID, and there isn't a way to easily change it, apparently.










    share|improve this question



























      13












      13








      13


      4






      How can make a full copy of the contents of a btrfs filesystem?
      By full copy I mean not only the current data, but also different subvolumes with their snapshots, ideally preserving their CoW structures (i.e.: not duplicating blocks with the same content.



      It seems a block-level copy (such as with dd) is not a good idea, since it duplicates the UUID, and there isn't a way to easily change it, apparently.










      share|improve this question
















      How can make a full copy of the contents of a btrfs filesystem?
      By full copy I mean not only the current data, but also different subvolumes with their snapshots, ideally preserving their CoW structures (i.e.: not duplicating blocks with the same content.



      It seems a block-level copy (such as with dd) is not a good idea, since it duplicates the UUID, and there isn't a way to easily change it, apparently.







      backup btrfs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 13 '17 at 12:22









      Community

      1




      1










      asked Jun 13 '13 at 20:30









      goncaloppgoncalopp

      4951512




      4951512






















          5 Answers
          5






          active

          oldest

          votes


















          2














          Use btrfstune -u to change UUID after dd and before mounting.



          Data loss warning: Do NOT try to mount either original or copy until the UUID has changed






          share|improve this answer





















          • 1





            For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

            – goncalopp
            Jan 25 '18 at 23:11





















          12














          I have not found any ready-made solution as of today (2016-05-06), but solved the problem for my purposes, including Copy-on-Write handling. The steps to "clone" /source to /target are:




          1. Get a list of subvolumes ordered by ogen: btrfs subvolume list -qu --sort ogen /source. Sorting is probably enough to guarantee that snapshots or subvolumes which depend on previous ones are handled first. This is important for dealing with Copy-on-Write, because we need to have the base volumes transferred first.


          2. Make all subvolumes read-only using btrfs property set -ts /source/some-volume ro true.



          3. Now, for each subvolume from the list above, starting at the top, do the following:




            1. If the volume does not have a parent UUID (displayed as -) or the parent UUID does not exist anymore in the list, run: btrfs send /source/some/volume | btrfs receive /target/some/


            2. If the volume does have a parent UUID which still exists, we should have transferred it already because of --sort ogen and we can use that as a base to avoid data duplication. Hence, find the parent UUID's path in the list and run: btrfs send -p /source/parent/volume/ -c /source/parent/volume/ /source/some/volume/ | btrfs receive /target/some/ (btrfs would probably guess the -p argument automatically, but I prefer to be explicit).


            3. After running one of the above commands make the target and source read-write again: btrfs property set -ts /source/some/volume ro false; btrfs property set -ts /target/some/volume ro false. This step can be skipped if the source has been previously read-only.





          This should handle many cases. Caveats:




          1. There might be some complications with respect to ordering when nesting subvolumes/snapshots.


          2. The whole process is obviously more fun when scripted.


          3. btrfs send accepts multiple clone source (-c) arguments. It may be advantageous to not only specify the parent's volume path, but also those of any ancestors or simply any previously sent volumes. It did not make any difference here, but it might — just a guess — help to avoid data duplication in some cases.


          4. I am unsure if any meta information on snapshots or subvolumes is lost along the way, but just about everything interesting else for most use cases should be preserved.



          The whole process helped me transfer an 800 GB filesystem with 3.8 GB used (according to df) to a 10 GB image with 3.8 GB used. Transferring without -p and -c would have used about 190 GB, so data duplication was indeed avoided.






          share|improve this answer


























          • Well written answer, thanks. Can you explain what ogen means?

            – drumfire
            Jun 3 '16 at 16:09











          • @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

            – Thomas Luzat
            Jun 4 '16 at 14:10






          • 1





            I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

            – Johannes Ernst
            Oct 1 '17 at 1:31





















          3














          I have created a python tool which can do this. I did this because I tried @Thomas Luzat's approach in both my own and @Johannes Ernst's implementation, and the used space doubled from 20GB to 40GB in the cloning procedure. I thought something more efficient was needed.



          Consider this common file system history:



          current ---------------------------------
          | | | |
          snap4 snap3 snap2 snap1


          With Thomas' algorithm, "current" would be cloned first, and all snapshots (being snapshots of former states of "current") would use "current" as clone source / parent. Obviously, it would be better to base snap3 on snap4, snap2 on snap3, etc.



          And this is just the tip of the iceberg; finding the "best" clone sources (in terms of space savings) in a btrfs file system with a complex history is a non-trivial problem. I've come up with 3 other strategies to solve this problem, which seem to use space much more efficiently. One has actually resulted in clones size slightly below that of the source.



          You can read the details on the github page if you're interested.






          share|improve this answer































            1














            There is a similar question on unix.stackexchange.com that points to partclone.btrfs, but I do not know any specifics about this.



            There is also a discussion on the kernel mailing list, not really looking promising...






            share|improve this answer

































              1














              With btrfs-send, which last I saw, was still experimental patches floating around on the btrfs mailing list.






              share|improve this answer























                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "3"
                };
                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: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                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%2fsuperuser.com%2fquestions%2f607363%2fhow-to-copy-a-btrfs-filesystem%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                Use btrfstune -u to change UUID after dd and before mounting.



                Data loss warning: Do NOT try to mount either original or copy until the UUID has changed






                share|improve this answer





















                • 1





                  For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

                  – goncalopp
                  Jan 25 '18 at 23:11


















                2














                Use btrfstune -u to change UUID after dd and before mounting.



                Data loss warning: Do NOT try to mount either original or copy until the UUID has changed






                share|improve this answer





















                • 1





                  For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

                  – goncalopp
                  Jan 25 '18 at 23:11
















                2












                2








                2







                Use btrfstune -u to change UUID after dd and before mounting.



                Data loss warning: Do NOT try to mount either original or copy until the UUID has changed






                share|improve this answer















                Use btrfstune -u to change UUID after dd and before mounting.



                Data loss warning: Do NOT try to mount either original or copy until the UUID has changed







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 9 at 4:55

























                answered Jan 11 '18 at 11:07









                Tom HaleTom Hale

                889822




                889822








                • 1





                  For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

                  – goncalopp
                  Jan 25 '18 at 23:11
















                • 1





                  For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

                  – goncalopp
                  Jan 25 '18 at 23:11










                1




                1





                For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

                – goncalopp
                Jan 25 '18 at 23:11







                For completeness, this was added as a option to btrfs-progs during 2015: github.com/kdave/btrfs-progs/commit/…

                – goncalopp
                Jan 25 '18 at 23:11















                12














                I have not found any ready-made solution as of today (2016-05-06), but solved the problem for my purposes, including Copy-on-Write handling. The steps to "clone" /source to /target are:




                1. Get a list of subvolumes ordered by ogen: btrfs subvolume list -qu --sort ogen /source. Sorting is probably enough to guarantee that snapshots or subvolumes which depend on previous ones are handled first. This is important for dealing with Copy-on-Write, because we need to have the base volumes transferred first.


                2. Make all subvolumes read-only using btrfs property set -ts /source/some-volume ro true.



                3. Now, for each subvolume from the list above, starting at the top, do the following:




                  1. If the volume does not have a parent UUID (displayed as -) or the parent UUID does not exist anymore in the list, run: btrfs send /source/some/volume | btrfs receive /target/some/


                  2. If the volume does have a parent UUID which still exists, we should have transferred it already because of --sort ogen and we can use that as a base to avoid data duplication. Hence, find the parent UUID's path in the list and run: btrfs send -p /source/parent/volume/ -c /source/parent/volume/ /source/some/volume/ | btrfs receive /target/some/ (btrfs would probably guess the -p argument automatically, but I prefer to be explicit).


                  3. After running one of the above commands make the target and source read-write again: btrfs property set -ts /source/some/volume ro false; btrfs property set -ts /target/some/volume ro false. This step can be skipped if the source has been previously read-only.





                This should handle many cases. Caveats:




                1. There might be some complications with respect to ordering when nesting subvolumes/snapshots.


                2. The whole process is obviously more fun when scripted.


                3. btrfs send accepts multiple clone source (-c) arguments. It may be advantageous to not only specify the parent's volume path, but also those of any ancestors or simply any previously sent volumes. It did not make any difference here, but it might — just a guess — help to avoid data duplication in some cases.


                4. I am unsure if any meta information on snapshots or subvolumes is lost along the way, but just about everything interesting else for most use cases should be preserved.



                The whole process helped me transfer an 800 GB filesystem with 3.8 GB used (according to df) to a 10 GB image with 3.8 GB used. Transferring without -p and -c would have used about 190 GB, so data duplication was indeed avoided.






                share|improve this answer


























                • Well written answer, thanks. Can you explain what ogen means?

                  – drumfire
                  Jun 3 '16 at 16:09











                • @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

                  – Thomas Luzat
                  Jun 4 '16 at 14:10






                • 1





                  I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

                  – Johannes Ernst
                  Oct 1 '17 at 1:31


















                12














                I have not found any ready-made solution as of today (2016-05-06), but solved the problem for my purposes, including Copy-on-Write handling. The steps to "clone" /source to /target are:




                1. Get a list of subvolumes ordered by ogen: btrfs subvolume list -qu --sort ogen /source. Sorting is probably enough to guarantee that snapshots or subvolumes which depend on previous ones are handled first. This is important for dealing with Copy-on-Write, because we need to have the base volumes transferred first.


                2. Make all subvolumes read-only using btrfs property set -ts /source/some-volume ro true.



                3. Now, for each subvolume from the list above, starting at the top, do the following:




                  1. If the volume does not have a parent UUID (displayed as -) or the parent UUID does not exist anymore in the list, run: btrfs send /source/some/volume | btrfs receive /target/some/


                  2. If the volume does have a parent UUID which still exists, we should have transferred it already because of --sort ogen and we can use that as a base to avoid data duplication. Hence, find the parent UUID's path in the list and run: btrfs send -p /source/parent/volume/ -c /source/parent/volume/ /source/some/volume/ | btrfs receive /target/some/ (btrfs would probably guess the -p argument automatically, but I prefer to be explicit).


                  3. After running one of the above commands make the target and source read-write again: btrfs property set -ts /source/some/volume ro false; btrfs property set -ts /target/some/volume ro false. This step can be skipped if the source has been previously read-only.





                This should handle many cases. Caveats:




                1. There might be some complications with respect to ordering when nesting subvolumes/snapshots.


                2. The whole process is obviously more fun when scripted.


                3. btrfs send accepts multiple clone source (-c) arguments. It may be advantageous to not only specify the parent's volume path, but also those of any ancestors or simply any previously sent volumes. It did not make any difference here, but it might — just a guess — help to avoid data duplication in some cases.


                4. I am unsure if any meta information on snapshots or subvolumes is lost along the way, but just about everything interesting else for most use cases should be preserved.



                The whole process helped me transfer an 800 GB filesystem with 3.8 GB used (according to df) to a 10 GB image with 3.8 GB used. Transferring without -p and -c would have used about 190 GB, so data duplication was indeed avoided.






                share|improve this answer


























                • Well written answer, thanks. Can you explain what ogen means?

                  – drumfire
                  Jun 3 '16 at 16:09











                • @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

                  – Thomas Luzat
                  Jun 4 '16 at 14:10






                • 1





                  I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

                  – Johannes Ernst
                  Oct 1 '17 at 1:31
















                12












                12








                12







                I have not found any ready-made solution as of today (2016-05-06), but solved the problem for my purposes, including Copy-on-Write handling. The steps to "clone" /source to /target are:




                1. Get a list of subvolumes ordered by ogen: btrfs subvolume list -qu --sort ogen /source. Sorting is probably enough to guarantee that snapshots or subvolumes which depend on previous ones are handled first. This is important for dealing with Copy-on-Write, because we need to have the base volumes transferred first.


                2. Make all subvolumes read-only using btrfs property set -ts /source/some-volume ro true.



                3. Now, for each subvolume from the list above, starting at the top, do the following:




                  1. If the volume does not have a parent UUID (displayed as -) or the parent UUID does not exist anymore in the list, run: btrfs send /source/some/volume | btrfs receive /target/some/


                  2. If the volume does have a parent UUID which still exists, we should have transferred it already because of --sort ogen and we can use that as a base to avoid data duplication. Hence, find the parent UUID's path in the list and run: btrfs send -p /source/parent/volume/ -c /source/parent/volume/ /source/some/volume/ | btrfs receive /target/some/ (btrfs would probably guess the -p argument automatically, but I prefer to be explicit).


                  3. After running one of the above commands make the target and source read-write again: btrfs property set -ts /source/some/volume ro false; btrfs property set -ts /target/some/volume ro false. This step can be skipped if the source has been previously read-only.





                This should handle many cases. Caveats:




                1. There might be some complications with respect to ordering when nesting subvolumes/snapshots.


                2. The whole process is obviously more fun when scripted.


                3. btrfs send accepts multiple clone source (-c) arguments. It may be advantageous to not only specify the parent's volume path, but also those of any ancestors or simply any previously sent volumes. It did not make any difference here, but it might — just a guess — help to avoid data duplication in some cases.


                4. I am unsure if any meta information on snapshots or subvolumes is lost along the way, but just about everything interesting else for most use cases should be preserved.



                The whole process helped me transfer an 800 GB filesystem with 3.8 GB used (according to df) to a 10 GB image with 3.8 GB used. Transferring without -p and -c would have used about 190 GB, so data duplication was indeed avoided.






                share|improve this answer















                I have not found any ready-made solution as of today (2016-05-06), but solved the problem for my purposes, including Copy-on-Write handling. The steps to "clone" /source to /target are:




                1. Get a list of subvolumes ordered by ogen: btrfs subvolume list -qu --sort ogen /source. Sorting is probably enough to guarantee that snapshots or subvolumes which depend on previous ones are handled first. This is important for dealing with Copy-on-Write, because we need to have the base volumes transferred first.


                2. Make all subvolumes read-only using btrfs property set -ts /source/some-volume ro true.



                3. Now, for each subvolume from the list above, starting at the top, do the following:




                  1. If the volume does not have a parent UUID (displayed as -) or the parent UUID does not exist anymore in the list, run: btrfs send /source/some/volume | btrfs receive /target/some/


                  2. If the volume does have a parent UUID which still exists, we should have transferred it already because of --sort ogen and we can use that as a base to avoid data duplication. Hence, find the parent UUID's path in the list and run: btrfs send -p /source/parent/volume/ -c /source/parent/volume/ /source/some/volume/ | btrfs receive /target/some/ (btrfs would probably guess the -p argument automatically, but I prefer to be explicit).


                  3. After running one of the above commands make the target and source read-write again: btrfs property set -ts /source/some/volume ro false; btrfs property set -ts /target/some/volume ro false. This step can be skipped if the source has been previously read-only.





                This should handle many cases. Caveats:




                1. There might be some complications with respect to ordering when nesting subvolumes/snapshots.


                2. The whole process is obviously more fun when scripted.


                3. btrfs send accepts multiple clone source (-c) arguments. It may be advantageous to not only specify the parent's volume path, but also those of any ancestors or simply any previously sent volumes. It did not make any difference here, but it might — just a guess — help to avoid data duplication in some cases.


                4. I am unsure if any meta information on snapshots or subvolumes is lost along the way, but just about everything interesting else for most use cases should be preserved.



                The whole process helped me transfer an 800 GB filesystem with 3.8 GB used (according to df) to a 10 GB image with 3.8 GB used. Transferring without -p and -c would have used about 190 GB, so data duplication was indeed avoided.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 15 '17 at 16:49









                matt

                2961314




                2961314










                answered May 6 '16 at 16:22









                Thomas LuzatThomas Luzat

                25839




                25839













                • Well written answer, thanks. Can you explain what ogen means?

                  – drumfire
                  Jun 3 '16 at 16:09











                • @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

                  – Thomas Luzat
                  Jun 4 '16 at 14:10






                • 1





                  I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

                  – Johannes Ernst
                  Oct 1 '17 at 1:31





















                • Well written answer, thanks. Can you explain what ogen means?

                  – drumfire
                  Jun 3 '16 at 16:09











                • @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

                  – Thomas Luzat
                  Jun 4 '16 at 14:10






                • 1





                  I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

                  – Johannes Ernst
                  Oct 1 '17 at 1:31



















                Well written answer, thanks. Can you explain what ogen means?

                – drumfire
                Jun 3 '16 at 16:09





                Well written answer, thanks. Can you explain what ogen means?

                – drumfire
                Jun 3 '16 at 16:09













                @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

                – Thomas Luzat
                Jun 4 '16 at 14:10





                @drumfire ogen is the subvolume's "origin generation". I have to admit that I do not fully understand the differences or whether using the (non-origin) generation would be correct, but assume some test indicated that this worked better (avoided duplication). The generation does seem to get updated when creating snapshots based on a subvolume, ogen doesn't. I would be interested in hearing about some findings. It's probably best to check on IRC or the Btrfs mailing list.

                – Thomas Luzat
                Jun 4 '16 at 14:10




                1




                1





                I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

                – Johannes Ernst
                Oct 1 '17 at 1:31







                I just took the algorithm of @ThomasLuzat , added some fluff around it (error checking etc) and put it here: github.com/jernst/btrfs-copy-filesystem/blob/master/… . It worked for my problem getting off a corrupted disk, and there are no guarantees it will work for anybody else. But I'm posting this here anyway in case anybody wants to start from somewhere other than scratch to code this. Currently depends on a new UBOS methods but should be easy to port.

                – Johannes Ernst
                Oct 1 '17 at 1:31













                3














                I have created a python tool which can do this. I did this because I tried @Thomas Luzat's approach in both my own and @Johannes Ernst's implementation, and the used space doubled from 20GB to 40GB in the cloning procedure. I thought something more efficient was needed.



                Consider this common file system history:



                current ---------------------------------
                | | | |
                snap4 snap3 snap2 snap1


                With Thomas' algorithm, "current" would be cloned first, and all snapshots (being snapshots of former states of "current") would use "current" as clone source / parent. Obviously, it would be better to base snap3 on snap4, snap2 on snap3, etc.



                And this is just the tip of the iceberg; finding the "best" clone sources (in terms of space savings) in a btrfs file system with a complex history is a non-trivial problem. I've come up with 3 other strategies to solve this problem, which seem to use space much more efficiently. One has actually resulted in clones size slightly below that of the source.



                You can read the details on the github page if you're interested.






                share|improve this answer




























                  3














                  I have created a python tool which can do this. I did this because I tried @Thomas Luzat's approach in both my own and @Johannes Ernst's implementation, and the used space doubled from 20GB to 40GB in the cloning procedure. I thought something more efficient was needed.



                  Consider this common file system history:



                  current ---------------------------------
                  | | | |
                  snap4 snap3 snap2 snap1


                  With Thomas' algorithm, "current" would be cloned first, and all snapshots (being snapshots of former states of "current") would use "current" as clone source / parent. Obviously, it would be better to base snap3 on snap4, snap2 on snap3, etc.



                  And this is just the tip of the iceberg; finding the "best" clone sources (in terms of space savings) in a btrfs file system with a complex history is a non-trivial problem. I've come up with 3 other strategies to solve this problem, which seem to use space much more efficiently. One has actually resulted in clones size slightly below that of the source.



                  You can read the details on the github page if you're interested.






                  share|improve this answer


























                    3












                    3








                    3







                    I have created a python tool which can do this. I did this because I tried @Thomas Luzat's approach in both my own and @Johannes Ernst's implementation, and the used space doubled from 20GB to 40GB in the cloning procedure. I thought something more efficient was needed.



                    Consider this common file system history:



                    current ---------------------------------
                    | | | |
                    snap4 snap3 snap2 snap1


                    With Thomas' algorithm, "current" would be cloned first, and all snapshots (being snapshots of former states of "current") would use "current" as clone source / parent. Obviously, it would be better to base snap3 on snap4, snap2 on snap3, etc.



                    And this is just the tip of the iceberg; finding the "best" clone sources (in terms of space savings) in a btrfs file system with a complex history is a non-trivial problem. I've come up with 3 other strategies to solve this problem, which seem to use space much more efficiently. One has actually resulted in clones size slightly below that of the source.



                    You can read the details on the github page if you're interested.






                    share|improve this answer













                    I have created a python tool which can do this. I did this because I tried @Thomas Luzat's approach in both my own and @Johannes Ernst's implementation, and the used space doubled from 20GB to 40GB in the cloning procedure. I thought something more efficient was needed.



                    Consider this common file system history:



                    current ---------------------------------
                    | | | |
                    snap4 snap3 snap2 snap1


                    With Thomas' algorithm, "current" would be cloned first, and all snapshots (being snapshots of former states of "current") would use "current" as clone source / parent. Obviously, it would be better to base snap3 on snap4, snap2 on snap3, etc.



                    And this is just the tip of the iceberg; finding the "best" clone sources (in terms of space savings) in a btrfs file system with a complex history is a non-trivial problem. I've come up with 3 other strategies to solve this problem, which seem to use space much more efficiently. One has actually resulted in clones size slightly below that of the source.



                    You can read the details on the github page if you're interested.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 13 '17 at 23:10









                    uncleremusuncleremus

                    411




                    411























                        1














                        There is a similar question on unix.stackexchange.com that points to partclone.btrfs, but I do not know any specifics about this.



                        There is also a discussion on the kernel mailing list, not really looking promising...






                        share|improve this answer






























                          1














                          There is a similar question on unix.stackexchange.com that points to partclone.btrfs, but I do not know any specifics about this.



                          There is also a discussion on the kernel mailing list, not really looking promising...






                          share|improve this answer




























                            1












                            1








                            1







                            There is a similar question on unix.stackexchange.com that points to partclone.btrfs, but I do not know any specifics about this.



                            There is also a discussion on the kernel mailing list, not really looking promising...






                            share|improve this answer















                            There is a similar question on unix.stackexchange.com that points to partclone.btrfs, but I do not know any specifics about this.



                            There is also a discussion on the kernel mailing list, not really looking promising...







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 13 '17 at 12:37









                            Community

                            1




                            1










                            answered Jun 14 '13 at 14:17









                            jstarekjstarek

                            880520




                            880520























                                1














                                With btrfs-send, which last I saw, was still experimental patches floating around on the btrfs mailing list.






                                share|improve this answer




























                                  1














                                  With btrfs-send, which last I saw, was still experimental patches floating around on the btrfs mailing list.






                                  share|improve this answer


























                                    1












                                    1








                                    1







                                    With btrfs-send, which last I saw, was still experimental patches floating around on the btrfs mailing list.






                                    share|improve this answer













                                    With btrfs-send, which last I saw, was still experimental patches floating around on the btrfs mailing list.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jun 14 '13 at 14:46









                                    psusipsusi

                                    6,8311622




                                    6,8311622






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Super User!


                                        • 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%2fsuperuser.com%2fquestions%2f607363%2fhow-to-copy-a-btrfs-filesystem%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

                                        flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                        Mangá

                                         ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕