mwilck / btrfs-clone

A tool for copying a btrfs file system with all its subvolumes to another btrfs file system
GNU General Public License v2.0
116 stars 17 forks source link

btrfs-clone over SSH #15

Open stastnypremysl opened 3 years ago

stastnypremysl commented 3 years ago

Is it possible to do btrfs-clone over SSH please?

Thanks. Přemysl

sarfatis commented 1 year ago

Hi, an experienced noob answering a curious noob.. just me pointing in the right direction to do the required changes to the code yourself.

See the Message print part line in the python code of btrfs-clone ? : if opts.verbose: print ("%s |\n\t %s" % (" ".join(send_cmd), " ".join(recv_cmd))) it's the verbose mode telling you the shell equivalent command format prior to ssh so :

send_command | receive_command" # where | pipes send to receive without ssh

(I'm neglecting the newline and tab which make little sense to me) whereas the common btrfs-receive-over-ssh use case would be :

btrfs send /from/local-ro-snap | ssh root@10.0.0.2 "btrfs receive -v /to/remote-ro-snap"

so adding the missing 'ssh root@10.0.0.2 "' and '"' around recv_cmd could be done in the Execution part of the code, on the line slightly above : recv_cmd = ( [opts.btrfs, "receive"] + VERBOSE + [new] ) perhaps modified so : recv_cmd = ('ssh root@10.0.0.2 " ' + [opts.btrfs, "receive"] + VERBOSE + [new] + '"') where opts.btrfs is the result in make_args() of option -B = --btrfs : set full path to "btrfs" executable and new the target/destination/to path, to assist in recognising the command line "btrfs receive -v /to".

Of course, I'd recommend checking the remote user <root?>, and address , perhaps by declaring the host and naming it to write root@nas for instance, as well as set up an automated login which does not require typing a password. Notice the remote machine does not require btrfs-clone to be installed.

I'm not sure how that affects the recv_cmd status check on line.

I have found only that 1 place to do the modification (in case there were another place for the top level, or other border line exception).

My two cents, as I've not tested it, and my python and shell are rusty, and therefore, the answer to your question seems to be "yes, it seems possible". Thanks for your good question, 2021'er Stastny Premysl.

mwilck commented 11 months ago

btrfs-clone has been written with local cloning in mind. I can see that this might be a useful feature in some situations, but it isn't implemented currently. It's not only about the send/receive operation itself; there are a couple of commands for subvolume creation and moving files around which must be run on the the remote host if ssh is involved. That's a major feature request.

I'm happy to look at patches, but I won't implement this myself.