public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api 1/2] backup: reorder tables in order of dependency
Date: Thu, 22 Feb 2024 13:40:50 +0100	[thread overview]
Message-ID: <20240222124051.324714-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20240222124051.324714-1-s.ivanov@proxmox.com>

Currently we dump the tables manually and print the relevant
DDL statements into the dump-file before copying the data.

The complete backup and dump specific tables part would probably be
best replaced by an appropriate `pg_dump` invocation - but as a
stop-gap measure reorder the tables in order of their dependencies.

Noticed while adding a foreign key constraint on 2 new tables
(objectgroup_attribute and rule_attribute) and running backup+restore.

Reported-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/Backup.pm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/PMG/Backup.pm b/src/PMG/Backup.pm
index 5891afb..ab7e628 100644
--- a/src/PMG/Backup.pm
+++ b/src/PMG/Backup.pm
@@ -90,18 +90,18 @@ sub dumpdb {
     eval {
 	$dbh->begin_work;
 
 	# read a consistent snapshot
 	$dbh->do("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
 
+	dump_table($dbh, 'objectgroup', $ofh, 'objectgroup_id_seq', 'id');
+	dump_table($dbh, 'object', $ofh, 'object_id_seq', 'id');
 	dump_table($dbh, 'attribut', $ofh);
 	dump_table($dbh, 'objectgroup_attributes', $ofh);
-	dump_table($dbh, 'rule_attributes', $ofh);
-	dump_table($dbh, 'object', $ofh, 'object_id_seq', 'id');
-	dump_table($dbh, 'objectgroup', $ofh, 'objectgroup_id_seq', 'id');
 	dump_table($dbh, 'rule', $ofh, 'rule_id_seq', 'id');
+	dump_table($dbh, 'rule_attributes', $ofh);
 	dump_table($dbh, 'rulegroup', $ofh);
 	dump_table($dbh, 'userprefs', $ofh);
 
 	# we do not save the following tables: cgreylist, cmailstore, cmsreceivers, clusterinfo
     };
     my $err = $@;
-- 
2.39.2





  reply	other threads:[~2024-02-22 12:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22 12:40 [pmg-devel] [PATCH pmg-api 0/2] fix table order on backup and add foreign key constraint for new tables Stoiko Ivanov
2024-02-22 12:40 ` Stoiko Ivanov [this message]
2024-02-22 12:40 ` [pmg-devel] [PATCH pmg-api 2/2] database: use foreign keys for rule and object group attributes Stoiko Ivanov
2024-02-22 13:22 ` [pmg-devel] [PATCH pmg-api 0/2] fix table order on backup and add foreign key constraint for new tables Dominik Csapak
2024-02-22 13:29 ` [pmg-devel] applied: " 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=20240222124051.324714-2-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-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