public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH zsync 10/10] fix #1669: add prepend-storage-id flag
Date: Tue,  4 May 2021 10:10:04 +0200	[thread overview]
Message-ID: <20210504081004.21898-11-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210504081004.21898-1-f.ebner@proxmox.com>

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 <f.ebner@proxmox.com>
---
 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 <string> -source <string> [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 <string> -source <string> [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 <VMID> or [IP:]<ZFSPool>[/Path]
-- 
2.20.1





  parent reply	other threads:[~2021-05-04  8:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  8:09 [pve-devel] [PATCH-SERIES zsync] fix #1669: allow prepending storage ID Fabian Ebner
2021-05-04  8:09 ` [pve-devel] [PATCH zsync 01/10] whitespace fix Fabian Ebner
2021-05-04  8:09 ` [pve-devel] [PATCH zsync 02/10] copyright: update year Fabian Ebner
2021-05-04  8:09 ` [pve-devel] [PATCH zsync 03/10] usage: describe flag parameters correctly Fabian Ebner
2021-05-04  8:09 ` [pve-devel] [PATCH zsync 04/10] usage: fix type for maxsnap Fabian Ebner
2021-05-04  8:09 ` [pve-devel] [PATCH zsync 05/10] add target_dataset function Fabian Ebner
2021-05-04  8:10 ` [pve-devel] [PATCH zsync 06/10] add check_dataset_exists function Fabian Ebner
2021-05-04  8:10 ` [pve-devel] [PATCH zsync 07/10] add create_file_system function Fabian Ebner
2021-05-04  8:10 ` [pve-devel] [PATCH zsync 08/10] parse disks: don't include colon in storage name variable Fabian Ebner
2021-05-04  8:10 ` [pve-devel] [PATCH zsync 09/10] parse disks: also include storage ID information Fabian Ebner
2021-05-04  8:10 ` Fabian Ebner [this message]
2021-05-04 12:01 ` [pve-devel] applied-series: [PATCH-SERIES zsync] fix #1669: allow prepending storage ID Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210504081004.21898-11-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal