From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C522179389 for ; Tue, 4 May 2021 10:10:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C5B0A249CD for ; Tue, 4 May 2021 10:10:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 78E1924940 for ; Tue, 4 May 2021 10:10:13 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 53D3141B8B for ; Tue, 4 May 2021 10:10:13 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 4 May 2021 10:10:04 +0200 Message-Id: <20210504081004.21898-11-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210504081004.21898-1-f.ebner@proxmox.com> References: <20210504081004.21898-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.000 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH zsync 10/10] fix #1669: add prepend-storage-id flag X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 May 2021 08:10:16 -0000 so one can set up jobs for guests with disks with the same name on different storages. For example, storageA:vm-123-disk-0 storageB:vm-123-disk-0 will be synced to target/storageA/vm-123-disk-0 target/storageB/vm-123-disk-0 when the flag is specified. The necessary parent file systems (one per storage ID) are created as needed. Signed-off-by: Fabian Ebner --- pve-zsync | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pve-zsync b/pve-zsync index 75d4d7c..521abf0 100755 --- a/pve-zsync +++ b/pve-zsync @@ -249,6 +249,7 @@ sub parse_argv { method => undef, source_user => undef, dest_user => undef, + prepend_storage_id => undef, properties => undef, dest_config_path => undef, }; @@ -265,6 +266,7 @@ sub parse_argv { 'method=s' => \$param->{method}, 'source-user=s' => \$param->{source_user}, 'dest-user=s' => \$param->{dest_user}, + 'prepend-storage-id' => \$param->{prepend_storage_id}, 'properties' => \$param->{properties}, 'dest-config-path=s' => \$param->{dest_config_path}, ); @@ -336,6 +338,7 @@ sub param_to_job { $job->{source} = $param->{source}; $job->{source_user} = $param->{source_user}; $job->{dest_user} = $param->{dest_user}; + $job->{prepend_storage_id} = !!$param->{prepend_storage_id}; $job->{properties} = !!$param->{properties}; $job->{dest_config_path} = $param->{dest_config_path} if $param->{dest_config_path}; @@ -461,6 +464,7 @@ sub format_job { $text .= " --verbose" if $job->{verbose}; $text .= " --source-user $job->{source_user}"; $text .= " --dest-user $job->{dest_user}"; + $text .= " --prepend-storage-id" if $job->{prepend_storage_id}; $text .= " --properties" if $job->{properties}; $text .= " --dest-config-path $job->{dest_config_path}" if $job->{dest_config_path}; $text .= "\n"; @@ -674,6 +678,8 @@ sub sync { ($dest->{old_snap}, $dest->{last_snap}) = snapshot_get($source, $dest, $param->{maxsnap}, $param->{name}, $param->{dest_user}); + prepare_prepended_target($source, $dest, $param->{dest_user}) if defined($dest->{prepend}); + snapshot_add($source, $dest, $param->{name}, $date, $param->{source_user}, $param->{dest_user}); send_image($source, $dest, $param); @@ -693,6 +699,10 @@ sub sync { $source->{pool} = $disks->{$disk}->{pool}; $source->{path} = $disks->{$disk}->{path} if $disks->{$disk}->{path}; $source->{last_part} = $disks->{$disk}->{last_part}; + + $dest->{prepend} = $disks->{$disk}->{storage_id} + if $param->{prepend_storage_id}; + &$sync_path($source, $dest, $job, $param, $date); } if ($param->{method} eq "ssh" && ($source->{ip} || $dest->{ip})) { @@ -921,12 +931,30 @@ sub target_dataset { my ($source, $dest) = @_; my $target = "$dest->{all}"; + $target .= "/$dest->{prepend}" if defined($dest->{prepend}); $target .= "/$source->{last_part}" if $source->{last_part}; $target =~ s!/+!/!g; return $target; } +# create the parent dataset for the actual target +sub prepare_prepended_target { + my ($source, $dest, $dest_user) = @_; + + die "internal error - not a prepended target\n" if !defined($dest->{prepend}); + + # The parent dataset shouldn't be the actual target. + die "internal error - no last_part for source\n" if !$source->{last_part}; + + my $target = "$dest->{all}/$dest->{prepend}"; + $target =~ s!/+!/!g; + + return if check_dataset_exists($target, $dest->{ip}, $dest_user); + + create_file_system($target, $dest->{ip}, $dest_user); +} + sub snapshot_destroy { my ($source, $dest, $method, $snap, $source_user, $dest_user) = @_; @@ -1138,6 +1166,10 @@ $PROGNAME create -dest -source [OPTIONS] name of the sync job, if not set it is default + -prepend-storage-id + + If specified, prepend the storage ID to the destination's path(s). + -skip If specified, skip the first sync. @@ -1184,6 +1216,10 @@ $PROGNAME sync -dest -source [OPTIONS]\n name of the sync job, if not set it is default. It is only necessary if scheduler allready contains this source. + -prepend-storage-id + + If specified, prepend the storage ID to the destination's path(s). + -source string the source can be an or [IP:][/Path] -- 2.20.1