Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FEATURE (backups): Move backups to separate backup config and make feature optional

Rostislav Duginaa6b495cfff0
diff --git a/README.md b/README.md
index 5b285cef..32ff707a 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
<img src="assets/logo.svg" alt="Postgresus Logo" width="250"/>
<h3>PostgreSQL monitoring and backup</h3>
- <p>Free, open source and self-hosted solution for automated PostgreSQL monitoring and backups with multiple storage options and notifications</p>
+ <p>Free, open source and self-hosted solution for automated PostgreSQL monitoring and backups. With multiple storage options and notifications</p>
<p>
<a href="#-features">Features</a> •
diff --git a/assets/healthchecks.svg b/assets/healthchecks.svg
index 702d7108..6dd3037d 100644
--- a/assets/healthchecks.svg
+++ b/assets/healthchecks.svg
@@ -1,11 +1,22 @@
-<svg width="438" height="91" viewBox="0 0 438 91" fill="none" xmlns="http://www.w3.org/2000/svg">
-<rect width="438" height="91" fill="white"/>
-<rect x="220" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="232" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="244" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="256" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="268" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<svg width="570" height="91" viewBox="0 0 570 91" fill="none" xmlns="http://www.w3.org/2000/svg">
+<rect width="570" height="91" fill="white"/>
+<rect x="352" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="364" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="376" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="388" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="400" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="412" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="4" width="10" height="10" rx="2" fill="#00C951"/>
@@ -24,24 +35,35 @@
<rect x="28" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="16" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="4" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="376" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="388" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="400" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="4" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="424" y="4" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="220" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="232" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="244" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="256" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="268" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="436" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="508" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="520" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="532" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="4" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="352" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="364" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="376" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="388" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="400" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="412" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="16" width="10" height="10" rx="2" fill="#00C951"/>
@@ -60,24 +82,35 @@
<rect x="28" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="16" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="4" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="376" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="388" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="400" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="16" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="424" y="16" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="220" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="232" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="244" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="256" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="268" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="436" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="508" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="520" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="532" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="16" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="352" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="364" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="376" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="388" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="400" y="28" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="412" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="28" width="10" height="10" rx="2" fill="#00C951"/>
@@ -96,24 +129,35 @@
<rect x="28" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="16" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="4" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="376" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="388" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="400" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="28" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="424" y="28" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="220" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="232" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="244" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="256" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="268" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="436" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="508" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="520" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="532" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="28" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="352" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="364" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="376" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="388" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="400" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="412" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="40" width="10" height="10" rx="2" fill="#00C951"/>
@@ -132,24 +176,35 @@
<rect x="28" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="16" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="4" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="376" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="388" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="400" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="40" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="424" y="40" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="220" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="232" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="244" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="256" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="268" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="436" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="508" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="520" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="532" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="40" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="352" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="364" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="376" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="388" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="400" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="412" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="52" width="10" height="10" rx="2" fill="#00C951"/>
@@ -168,24 +223,35 @@
<rect x="28" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="16" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="4" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="376" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="388" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="400" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="52" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="424" y="52" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="220" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="232" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="244" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="256" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="268" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="436" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="508" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="520" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="532" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="52" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="352" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="364" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="376" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="388" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="400" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="412" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="64" width="10" height="10" rx="2" fill="#00C951"/>
@@ -204,24 +270,35 @@
<rect x="28" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="16" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="4" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="64" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="376" y="64" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="388" y="64" width="10" height="10" rx="2" fill="#FB2C36"/>
-<rect x="400" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="64" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="424" y="64" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="220" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="232" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="244" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="256" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="268" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="436" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="64" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="508" y="64" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="520" y="64" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="532" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="64" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="352" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="364" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="376" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="388" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="400" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="412" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="340" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="328" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="316" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="304" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="292" y="76" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="280" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="268" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="256" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="244" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="232" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="220" y="76" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="208" y="76" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="196" y="76" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="184" y="76" width="10" height="10" rx="2" fill="#00C951"/>
@@ -237,22 +314,22 @@
<rect x="64" y="76" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="52" y="76" width="10" height="10" rx="2" fill="#00C951"/>
<rect x="40" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="28" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="16" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="4" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="292" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="304" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="316" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="328" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="340" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="352" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="364" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="376" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="388" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="400" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="412" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="28" y="76" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="16" y="76" width="10" height="10" rx="2" fill="#FB2C36"/>
+<rect x="4" y="76" width="10" height="10" rx="2" fill="#FB2C36"/>
<rect x="424" y="76" width="10" height="10" rx="2" fill="#00C951"/>
-<rect x="315" y="43" width="109" height="19" rx="2" fill="#373737" fill-opacity="0.95"/>
-<path d="M369.542 67L374.342 61.75H364.743L369.542 67Z" fill="#373737" fill-opacity="0.95"/>
-<path d="M321.22 57L324.861 53.117C325.03 52.9337 325.173 52.754 325.29 52.578C325.415 52.3947 325.506 52.2113 325.565 52.028C325.631 51.8373 325.664 51.6393 325.664 51.434C325.664 51.2653 325.631 51.1003 325.565 50.939C325.499 50.7777 325.4 50.631 325.268 50.499C325.143 50.367 324.989 50.2607 324.806 50.18C324.623 50.0993 324.414 50.059 324.179 50.059C323.849 50.059 323.563 50.136 323.321 50.29C323.086 50.4367 322.907 50.653 322.782 50.939C322.657 51.2177 322.595 51.5513 322.595 51.94H321.66C321.66 51.39 321.759 50.9097 321.957 50.499C322.155 50.081 322.441 49.7583 322.815 49.531C323.196 49.2963 323.651 49.179 324.179 49.179C324.604 49.179 324.971 49.2523 325.279 49.399C325.587 49.5383 325.84 49.7217 326.038 49.949C326.236 50.169 326.383 50.4073 326.478 50.664C326.573 50.9207 326.621 51.1663 326.621 51.401C326.621 51.797 326.526 52.1893 326.335 52.578C326.144 52.9667 325.899 53.315 325.598 53.623L323.145 56.12H326.654V57H321.22ZM328.143 50.818V49.85L330.783 49.19V57H329.848V50.312L328.143 50.818ZM337.13 54.69L337.46 53.81H340.87L341.2 54.69H337.13ZM339.143 51.038L337.845 54.096L337.757 54.294L336.613 57H335.568L339.143 48.915L342.718 57H341.673L340.551 54.36L340.463 54.14L339.143 51.038ZM344.265 55.02C344.265 55.4233 344.356 55.735 344.54 55.955C344.723 56.175 344.991 56.285 345.343 56.285C345.599 56.285 345.823 56.2337 346.014 56.131C346.212 56.021 346.362 55.8707 346.465 55.68C346.575 55.4893 346.63 55.2693 346.63 55.02V51.94H347.51V57H346.63V56.208C346.461 56.5087 346.252 56.736 346.003 56.89C345.753 57.0367 345.46 57.11 345.123 57.11C344.595 57.11 344.173 56.9303 343.858 56.571C343.542 56.2117 343.385 55.7313 343.385 55.13V51.94H344.265V55.02ZM348.823 57.33H349.714C349.714 57.572 349.78 57.7957 349.912 58.001C350.044 58.2137 350.231 58.3823 350.473 58.507C350.715 58.639 351.001 58.705 351.331 58.705C351.588 58.705 351.841 58.6427 352.09 58.518C352.339 58.3933 352.545 58.1953 352.706 57.924C352.875 57.66 352.959 57.3153 352.959 56.89V51.94H353.839V56.89C353.839 57.4693 353.718 57.9533 353.476 58.342C353.234 58.738 352.922 59.035 352.541 59.233C352.16 59.431 351.756 59.53 351.331 59.53C350.84 59.53 350.403 59.4383 350.022 59.255C349.648 59.0717 349.355 58.8113 349.142 58.474C348.929 58.144 348.823 57.7627 348.823 57.33ZM348.724 54.47C348.724 53.92 348.838 53.4507 349.065 53.062C349.292 52.666 349.597 52.3617 349.978 52.149C350.359 51.9363 350.777 51.83 351.232 51.83C351.657 51.83 352.028 51.9363 352.343 52.149C352.658 52.3617 352.904 52.666 353.08 53.062C353.263 53.4507 353.355 53.92 353.355 54.47C353.355 55.0127 353.263 55.482 353.08 55.878C352.904 56.274 352.658 56.5783 352.343 56.791C352.028 57.0037 351.657 57.11 351.232 57.11C350.777 57.11 350.359 57.0037 349.978 56.791C349.597 56.5783 349.292 56.274 349.065 55.878C348.838 55.482 348.724 55.0127 348.724 54.47ZM349.615 54.47C349.615 54.8587 349.692 55.1887 349.846 55.46C350.007 55.7313 350.22 55.9367 350.484 56.076C350.748 56.2153 351.034 56.285 351.342 56.285C351.599 56.285 351.852 56.2153 352.101 56.076C352.35 55.9367 352.556 55.7313 352.717 55.46C352.878 55.1887 352.959 54.8587 352.959 54.47C352.959 54.1767 352.911 53.92 352.816 53.7C352.721 53.4727 352.592 53.282 352.431 53.128C352.277 52.974 352.105 52.8567 351.914 52.776C351.723 52.6953 351.533 52.655 351.342 52.655C351.034 52.655 350.748 52.7247 350.484 52.864C350.22 53.0033 350.007 53.2087 349.846 53.48C349.692 53.7513 349.615 54.0813 349.615 54.47ZM358.13 57L361.771 53.117C361.94 52.9337 362.083 52.754 362.2 52.578C362.325 52.3947 362.416 52.2113 362.475 52.028C362.541 51.8373 362.574 51.6393 362.574 51.434C362.574 51.2653 362.541 51.1003 362.475 50.939C362.409 50.7777 362.31 50.631 362.178 50.499C362.053 50.367 361.899 50.2607 361.716 50.18C361.533 50.0993 361.324 50.059 361.089 50.059C360.759 50.059 360.473 50.136 360.231 50.29C359.996 50.4367 359.817 50.653 359.692 50.939C359.567 51.2177 359.505 51.5513 359.505 51.94H358.57C358.57 51.39 358.669 50.9097 358.867 50.499C359.065 50.081 359.351 49.7583 359.725 49.531C360.106 49.2963 360.561 49.179 361.089 49.179C361.514 49.179 361.881 49.2523 362.189 49.399C362.497 49.5383 362.75 49.7217 362.948 49.949C363.146 50.169 363.293 50.4073 363.388 50.664C363.483 50.9207 363.531 51.1663 363.531 51.401C363.531 51.797 363.436 52.1893 363.245 52.578C363.054 52.9667 362.809 53.315 362.508 53.623L360.055 56.12H363.564V57H358.13ZM365.548 53.15C365.548 53.5973 365.592 54.0117 365.68 54.393C365.768 54.767 365.896 55.0933 366.065 55.372C366.234 55.6433 366.435 55.856 366.67 56.01C366.912 56.1567 367.18 56.23 367.473 56.23C367.774 56.23 368.041 56.1567 368.276 56.01C368.511 55.856 368.712 55.6433 368.881 55.372C369.05 55.0933 369.178 54.767 369.266 54.393C369.354 54.0117 369.398 53.5973 369.398 53.15C369.398 52.7027 369.354 52.292 369.266 51.918C369.178 51.5367 369.05 51.2103 368.881 50.939C368.712 50.6603 368.511 50.4477 368.276 50.301C368.041 50.147 367.774 50.07 367.473 50.07C367.18 50.07 366.912 50.147 366.67 50.301C366.435 50.4477 366.234 50.6603 366.065 50.939C365.896 51.2103 365.768 51.5367 365.68 51.918C365.592 52.292 365.548 52.7027 365.548 53.15ZM364.613 53.15C364.613 52.38 364.734 51.698 364.976 51.104C365.218 50.51 365.552 50.0443 365.977 49.707C366.41 49.3623 366.908 49.19 367.473 49.19C368.038 49.19 368.533 49.3623 368.958 49.707C369.391 50.0443 369.728 50.51 369.97 51.104C370.212 51.698 370.333 52.38 370.333 53.15C370.333 53.92 370.212 54.602 369.97 55.196C369.728 55.79 369.391 56.2593 368.958 56.604C368.533 56.9413 368.038 57.11 367.473 57.11C366.908 57.11 366.41 56.9413 365.977 56.604C365.552 56.2593 365.218 55.79 364.976 55.196C364.734 54.602 364.613 53.92 364.613 53.15ZM370.989 57L374.63 53.117C374.798 52.9337 374.941 52.754 375.059 52.578C375.183 52.3947 375.275 52.2113 375.334 52.028C375.4 51.8373 375.433 51.6393 375.433 51.434C375.433 51.2653 375.4 51.1003 375.334 50.939C375.268 50.7777 375.169 50.631 375.037 50.499C374.912 50.367 374.758 50.2607 374.575 50.18C374.391 50.0993 374.182 50.059 373.948 50.059C373.618 50.059 373.332 50.136 373.09 50.29C372.855 50.4367 372.675 50.653 372.551 50.939C372.426 51.2177 372.364 51.5513 372.364 51.94H371.429C371.429 51.39 371.528 50.9097 371.726 50.499C371.924 50.081 372.21 49.7583 372.584 49.531C372.965 49.2963 373.42 49.179 373.948 49.179C374.373 49.179 374.74 49.2523 375.048 49.399C375.356 49.5383 375.609 49.7217 375.807 49.949C376.005 50.169 376.151 50.4073 376.247 50.664C376.342 50.9207 376.39 51.1663 376.39 51.401C376.39 51.797 376.294 52.1893 376.104 52.578C375.913 52.9667 375.667 53.315 375.367 53.623L372.914 56.12H376.423V57H370.989ZM382.795 54.47C382.795 54.91 382.726 55.295 382.586 55.625C382.447 55.955 382.253 56.23 382.003 56.45C381.754 56.67 381.468 56.835 381.145 56.945C380.823 57.055 380.474 57.11 380.1 57.11C379.631 57.11 379.22 57.0367 378.868 56.89C378.524 56.7433 378.227 56.549 377.977 56.307C377.735 56.0577 377.53 55.7863 377.361 55.493L378.153 54.954C378.271 55.174 378.425 55.383 378.615 55.581C378.813 55.7717 379.041 55.9293 379.297 56.054C379.554 56.1713 379.822 56.23 380.1 56.23C380.467 56.23 380.779 56.1567 381.035 56.01C381.292 55.8633 381.486 55.658 381.618 55.394C381.758 55.13 381.827 54.822 381.827 54.47C381.827 54.118 381.75 53.81 381.596 53.546C381.45 53.282 381.244 53.0767 380.98 52.93C380.724 52.7833 380.43 52.71 380.1 52.71C379.858 52.71 379.635 52.732 379.429 52.776C379.231 52.8127 379.03 52.8823 378.824 52.985C378.626 53.0803 378.395 53.2197 378.131 53.403L379.143 49.3H382.773V50.125H379.869L379.352 52.16C379.536 52.0647 379.723 51.995 379.913 51.951C380.111 51.8997 380.306 51.874 380.496 51.874C380.936 51.874 381.329 51.984 381.673 52.204C382.025 52.424 382.3 52.7283 382.498 53.117C382.696 53.5057 382.795 53.9567 382.795 54.47ZM386.593 54.8V53.975H388.793V54.8H386.593ZM392.366 55.46L396.634 49.3H397.019V57H396.084V55.064V54.943V51.379L393.906 54.635H396.469H396.656H398.229V55.46H392.366ZM402.736 49.3H403.671V57H402.736V49.3ZM403.253 50.18V49.3H404.826C405.325 49.3 405.769 49.3953 406.157 49.586C406.553 49.7693 406.865 50.0333 407.092 50.378C407.327 50.7227 407.444 51.1333 407.444 51.61C407.444 52.0793 407.327 52.49 407.092 52.842C406.865 53.1867 406.553 53.4543 406.157 53.645C405.769 53.8283 405.325 53.92 404.826 53.92H403.253V53.04H404.826C405.325 53.04 405.728 52.919 406.036 52.677C406.352 52.435 406.509 52.0793 406.509 51.61C406.509 51.1333 406.352 50.7777 406.036 50.543C405.728 50.301 405.325 50.18 404.826 50.18H403.253ZM409.83 51.797L409.258 57H408.323L409.258 48.915L412.338 54.492L415.418 48.915L416.353 57H415.418L414.846 51.797L412.338 56.285L409.83 51.797Z" fill="white"/>
+<rect x="436" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="448" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="460" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="472" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="484" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="496" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="508" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="520" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="532" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="544" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="556" y="76" width="10" height="10" rx="2" fill="#00C951"/>
+<rect x="431" y="43" width="118" height="19" rx="2" fill="#373737" fill-opacity="0.95"/>
+<path d="M500.702 67L505.898 61.75H495.506L500.702 67Z" fill="#373737" fill-opacity="0.95"/>
+<path d="M435.22 57L438.861 53.117C439.03 52.9337 439.173 52.754 439.29 52.578C439.415 52.3947 439.506 52.2113 439.565 52.028C439.631 51.8373 439.664 51.6393 439.664 51.434C439.664 51.2653 439.631 51.1003 439.565 50.939C439.499 50.7777 439.4 50.631 439.268 50.499C439.143 50.367 438.989 50.2607 438.806 50.18C438.623 50.0993 438.414 50.059 438.179 50.059C437.849 50.059 437.563 50.136 437.321 50.29C437.086 50.4367 436.907 50.653 436.782 50.939C436.657 51.2177 436.595 51.5513 436.595 51.94H435.66C435.66 51.39 435.759 50.9097 435.957 50.499C436.155 50.081 436.441 49.7583 436.815 49.531C437.196 49.2963 437.651 49.179 438.179 49.179C438.604 49.179 438.971 49.2523 439.279 49.399C439.587 49.5383 439.84 49.7217 440.038 49.949C440.236 50.169 440.383 50.4073 440.478 50.664C440.573 50.9207 440.621 51.1663 440.621 51.401C440.621 51.797 440.526 52.1893 440.335 52.578C440.144 52.9667 439.899 53.315 439.598 53.623L437.145 56.12H440.654V57H435.22ZM442.143 50.818V49.85L444.783 49.19V57H443.848V50.312L442.143 50.818ZM451.13 54.69L451.46 53.81H454.87L455.2 54.69H451.13ZM453.143 51.038L451.845 54.096L451.757 54.294L450.613 57H449.568L453.143 48.915L456.718 57H455.673L454.551 54.36L454.463 54.14L453.143 51.038ZM458.265 55.02C458.265 55.4233 458.356 55.735 458.54 55.955C458.723 56.175 458.991 56.285 459.343 56.285C459.599 56.285 459.823 56.2337 460.014 56.131C460.212 56.021 460.362 55.8707 460.465 55.68C460.575 55.4893 460.63 55.2693 460.63 55.02V51.94H461.51V57H460.63V56.208C460.461 56.5087 460.252 56.736 460.003 56.89C459.753 57.0367 459.46 57.11 459.123 57.11C458.595 57.11 458.173 56.9303 457.858 56.571C457.542 56.2117 457.385 55.7313 457.385 55.13V51.94H458.265V55.02ZM462.823 57.33H463.714C463.714 57.572 463.78 57.7957 463.912 58.001C464.044 58.2137 464.231 58.3823 464.473 58.507C464.715 58.639 465.001 58.705 465.331 58.705C465.588 58.705 465.841 58.6427 466.09 58.518C466.339 58.3933 466.545 58.1953 466.706 57.924C466.875 57.66 466.959 57.3153 466.959 56.89V51.94H467.839V56.89C467.839 57.4693 467.718 57.9533 467.476 58.342C467.234 58.738 466.922 59.035 466.541 59.233C466.16 59.431 465.756 59.53 465.331 59.53C464.84 59.53 464.403 59.4383 464.022 59.255C463.648 59.0717 463.355 58.8113 463.142 58.474C462.929 58.144 462.823 57.7627 462.823 57.33ZM462.724 54.47C462.724 53.92 462.838 53.4507 463.065 53.062C463.292 52.666 463.597 52.3617 463.978 52.149C464.359 51.9363 464.777 51.83 465.232 51.83C465.657 51.83 466.028 51.9363 466.343 52.149C466.658 52.3617 466.904 52.666 467.08 53.062C467.263 53.4507 467.355 53.92 467.355 54.47C467.355 55.0127 467.263 55.482 467.08 55.878C466.904 56.274 466.658 56.5783 466.343 56.791C466.028 57.0037 465.657 57.11 465.232 57.11C464.777 57.11 464.359 57.0037 463.978 56.791C463.597 56.5783 463.292 56.274 463.065 55.878C462.838 55.482 462.724 55.0127 462.724 54.47ZM463.615 54.47C463.615 54.8587 463.692 55.1887 463.846 55.46C464.007 55.7313 464.22 55.9367 464.484 56.076C464.748 56.2153 465.034 56.285 465.342 56.285C465.599 56.285 465.852 56.2153 466.101 56.076C466.35 55.9367 466.556 55.7313 466.717 55.46C466.878 55.1887 466.959 54.8587 466.959 54.47C466.959 54.1767 466.911 53.92 466.816 53.7C466.721 53.4727 466.592 53.282 466.431 53.128C466.277 52.974 466.105 52.8567 465.914 52.776C465.723 52.6953 465.533 52.655 465.342 52.655C465.034 52.655 464.748 52.7247 464.484 52.864C464.22 53.0033 464.007 53.2087 463.846 53.48C463.692 53.7513 463.615 54.0813 463.615 54.47ZM472.13 57L475.771 53.117C475.94 52.9337 476.083 52.754 476.2 52.578C476.325 52.3947 476.416 52.2113 476.475 52.028C476.541 51.8373 476.574 51.6393 476.574 51.434C476.574 51.2653 476.541 51.1003 476.475 50.939C476.409 50.7777 476.31 50.631 476.178 50.499C476.053 50.367 475.899 50.2607 475.716 50.18C475.533 50.0993 475.324 50.059 475.089 50.059C474.759 50.059 474.473 50.136 474.231 50.29C473.996 50.4367 473.817 50.653 473.692 50.939C473.567 51.2177 473.505 51.5513 473.505 51.94H472.57C472.57 51.39 472.669 50.9097 472.867 50.499C473.065 50.081 473.351 49.7583 473.725 49.531C474.106 49.2963 474.561 49.179 475.089 49.179C475.514 49.179 475.881 49.2523 476.189 49.399C476.497 49.5383 476.75 49.7217 476.948 49.949C477.146 50.169 477.293 50.4073 477.388 50.664C477.483 50.9207 477.531 51.1663 477.531 51.401C477.531 51.797 477.436 52.1893 477.245 52.578C477.054 52.9667 476.809 53.315 476.508 53.623L474.055 56.12H477.564V57H472.13ZM479.548 53.15C479.548 53.5973 479.592 54.0117 479.68 54.393C479.768 54.767 479.896 55.0933 480.065 55.372C480.234 55.6433 480.435 55.856 480.67 56.01C480.912 56.1567 481.18 56.23 481.473 56.23C481.774 56.23 482.041 56.1567 482.276 56.01C482.511 55.856 482.712 55.6433 482.881 55.372C483.05 55.0933 483.178 54.767 483.266 54.393C483.354 54.0117 483.398 53.5973 483.398 53.15C483.398 52.7027 483.354 52.292 483.266 51.918C483.178 51.5367 483.05 51.2103 482.881 50.939C482.712 50.6603 482.511 50.4477 482.276 50.301C482.041 50.147 481.774 50.07 481.473 50.07C481.18 50.07 480.912 50.147 480.67 50.301C480.435 50.4477 480.234 50.6603 480.065 50.939C479.896 51.2103 479.768 51.5367 479.68 51.918C479.592 52.292 479.548 52.7027 479.548 53.15ZM478.613 53.15C478.613 52.38 478.734 51.698 478.976 51.104C479.218 50.51 479.552 50.0443 479.977 49.707C480.41 49.3623 480.908 49.19 481.473 49.19C482.038 49.19 482.533 49.3623 482.958 49.707C483.391 50.0443 483.728 50.51 483.97 51.104C484.212 51.698 484.333 52.38 484.333 53.15C484.333 53.92 484.212 54.602 483.97 55.196C483.728 55.79 483.391 56.2593 482.958 56.604C482.533 56.9413 482.038 57.11 481.473 57.11C480.908 57.11 480.41 56.9413 479.977 56.604C479.552 56.2593 479.218 55.79 478.976 55.196C478.734 54.602 478.613 53.92 478.613 53.15ZM484.989 57L488.63 53.117C488.798 52.9337 488.941 52.754 489.059 52.578C489.183 52.3947 489.275 52.2113 489.334 52.028C489.4 51.8373 489.433 51.6393 489.433 51.434C489.433 51.2653 489.4 51.1003 489.334 50.939C489.268 50.7777 489.169 50.631 489.037 50.499C488.912 50.367 488.758 50.2607 488.575 50.18C488.391 50.0993 488.182 50.059 487.948 50.059C487.618 50.059 487.332 50.136 487.09 50.29C486.855 50.4367 486.675 50.653 486.551 50.939C486.426 51.2177 486.364 51.5513 486.364 51.94H485.429C485.429 51.39 485.528 50.9097 485.726 50.499C485.924 50.081 486.21 49.7583 486.584 49.531C486.965 49.2963 487.42 49.179 487.948 49.179C488.373 49.179 488.74 49.2523 489.048 49.399C489.356 49.5383 489.609 49.7217 489.807 49.949C490.005 50.169 490.151 50.4073 490.247 50.664C490.342 50.9207 490.39 51.1663 490.39 51.401C490.39 51.797 490.294 52.1893 490.104 52.578C489.913 52.9667 489.667 53.315 489.367 53.623L486.914 56.12H490.423V57H484.989ZM496.795 54.47C496.795 54.91 496.726 55.295 496.586 55.625C496.447 55.955 496.253 56.23 496.003 56.45C495.754 56.67 495.468 56.835 495.145 56.945C494.823 57.055 494.474 57.11 494.1 57.11C493.631 57.11 493.22 57.0367 492.868 56.89C492.524 56.7433 492.227 56.549 491.977 56.307C491.735 56.0577 491.53 55.7863 491.361 55.493L492.153 54.954C492.271 55.174 492.425 55.383 492.615 55.581C492.813 55.7717 493.041 55.9293 493.297 56.054C493.554 56.1713 493.822 56.23 494.1 56.23C494.467 56.23 494.779 56.1567 495.035 56.01C495.292 55.8633 495.486 55.658 495.618 55.394C495.758 55.13 495.827 54.822 495.827 54.47C495.827 54.118 495.75 53.81 495.596 53.546C495.45 53.282 495.244 53.0767 494.98 52.93C494.724 52.7833 494.43 52.71 494.1 52.71C493.858 52.71 493.635 52.732 493.429 52.776C493.231 52.8127 493.03 52.8823 492.824 52.985C492.626 53.0803 492.395 53.2197 492.131 53.403L493.143 49.3H496.773V50.125H493.869L493.352 52.16C493.536 52.0647 493.723 51.995 493.913 51.951C494.111 51.8997 494.306 51.874 494.496 51.874C494.936 51.874 495.329 51.984 495.673 52.204C496.025 52.424 496.3 52.7283 496.498 53.117C496.696 53.5057 496.795 53.9567 496.795 54.47ZM500.593 54.8V53.975H502.793V54.8H500.593ZM506.366 55.46L510.634 49.3H511.019V57H510.084V55.064V54.943V51.379L507.906 54.635H510.469H510.656H512.229V55.46H506.366ZM513.604 56.56C513.604 56.3913 513.662 56.2483 513.78 56.131C513.904 56.0137 514.047 55.955 514.209 55.955C514.377 55.955 514.52 56.0137 514.638 56.131C514.755 56.2483 514.814 56.3913 514.814 56.56C514.814 56.7213 514.755 56.8643 514.638 56.989C514.52 57.1063 514.377 57.165 514.209 57.165C514.047 57.165 513.904 57.1063 513.78 56.989C513.662 56.8643 513.604 56.7213 513.604 56.56ZM513.604 52.38C513.604 52.2113 513.662 52.0683 513.78 51.951C513.904 51.8337 514.047 51.775 514.209 51.775C514.377 51.775 514.52 51.8337 514.638 51.951C514.755 52.0683 514.814 52.2113 514.814 52.38C514.814 52.5413 514.755 52.6843 514.638 52.809C514.52 52.9263 514.377 52.985 514.209 52.985C514.047 52.985 513.904 52.9263 513.78 52.809C513.662 52.6843 513.604 52.5413 513.604 52.38ZM516.736 50.818V49.85L519.376 49.19V57H518.441V50.312L516.736 50.818ZM521.139 50.18V49.3H526.529L522.844 57H521.865L525.132 50.18H521.139ZM530.766 49.3H531.701V57H530.766V49.3ZM531.283 50.18V49.3H532.856C533.354 49.3 533.798 49.3953 534.187 49.586C534.583 49.7693 534.894 50.0333 535.122 50.378C535.356 50.7227 535.474 51.1333 535.474 51.61C535.474 52.0793 535.356 52.49 535.122 52.842C534.894 53.1867 534.583 53.4543 534.187 53.645C533.798 53.8283 533.354 53.92 532.856 53.92H531.283V53.04H532.856C533.354 53.04 533.758 52.919 534.066 52.677C534.381 52.435 534.539 52.0793 534.539 51.61C534.539 51.1333 534.381 50.7777 534.066 50.543C533.758 50.301 533.354 50.18 532.856 50.18H531.283ZM537.859 51.797L537.287 57H536.352L537.287 48.915L540.367 54.492L543.447 48.915L544.382 57H543.447L542.875 51.797L540.367 56.285L537.859 51.797Z" fill="white"/>
</svg>
diff --git a/backend/.env.development.example b/backend/.env.development.example
index 3734a19f..fa7e7121 100644
--- a/backend/.env.development.example
+++ b/backend/.env.development.example
@@ -15,7 +15,7 @@ GOOSE_MIGRATION_DIR=./migrations
# to get Google Drive env variables: add storage in UI and copy data from added storage here
TEST_GOOGLE_DRIVE_CLIENT_ID=
TEST_GOOGLE_DRIVE_CLIENT_SECRET=
-TEST_GOOGLE_DRIVE_TOKEN_JSON=
+TEST_GOOGLE_DRIVE_TOKEN_JSON="{\"access_token\":\"ya29..."
# testing DBs
TEST_POSTGRES_13_PORT=5001
TEST_POSTGRES_14_PORT=5002
diff --git a/backend/.gitignore b/backend/.gitignore
index 5d8760cf..d10186d4 100644
--- a/backend/.gitignore
+++ b/backend/.gitignore
@@ -10,4 +10,5 @@ swagger/docs.go
swagger/swagger.json
swagger/swagger.yaml
postgresus-backend.exe
-ui/build/*
\ No newline at end of file
+ui/build/*
+pgdata-for-restore/
\ No newline at end of file
diff --git a/backend/cmd/main.go b/backend/cmd/main.go
index 38aede96..85c9ec23 100644
--- a/backend/cmd/main.go
+++ b/backend/cmd/main.go
@@ -14,7 +14,8 @@ import (
"postgresus-backend/internal/config"
"postgresus-backend/internal/downdetect"
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/disk"
healthcheck_attempt "postgresus-backend/internal/features/healthcheck/attempt"
@@ -135,6 +136,7 @@ func setUpRoutes(r *gin.Engine) {
healthcheckConfigController := healthcheck_config.GetHealthcheckConfigController()
healthcheckAttemptController := healthcheck_attempt.GetHealthcheckAttemptController()
diskController := disk.GetDiskController()
+ backupConfigController := backups_config.GetBackupConfigController()
downdetectContoller.RegisterRoutes(v1)
userController.RegisterRoutes(v1)
@@ -147,10 +149,13 @@ func setUpRoutes(r *gin.Engine) {
diskController.RegisterRoutes(v1)
healthcheckConfigController.RegisterRoutes(v1)
healthcheckAttemptController.RegisterRoutes(v1)
+ backupConfigController.RegisterRoutes(v1)
}
func setUpDependencies() {
backups.SetupDependencies()
+ backups.SetupDependencies()
+ restores.SetupDependencies()
healthcheck_config.SetupDependencies()
}
diff --git a/backend/internal/features/backups/background_service.go b/backend/internal/features/backups/backups/background_service.go
similarity index 75%
rename from backend/internal/features/backups/background_service.go
rename to backend/internal/features/backups/backups/background_service.go
index 3e1c8f04..548554df 100644
--- a/backend/internal/features/backups/background_service.go
+++ b/backend/internal/features/backups/backups/background_service.go
@@ -3,16 +3,19 @@ package backups
import (
"log/slog"
"postgresus-backend/internal/config"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/storages"
+ "postgresus-backend/internal/util/period"
"time"
)
type BackupBackgroundService struct {
- backupService *BackupService
- backupRepository *BackupRepository
- databaseService *databases.DatabaseService
- storageService *storages.StorageService
+ backupService *BackupService
+ backupRepository *BackupRepository
+ databaseService *databases.DatabaseService
+ storageService *storages.StorageService
+ backupConfigService *backups_config.BackupConfigService
lastBackupTime time.Time
logger *slog.Logger
@@ -60,15 +63,21 @@ func (s *BackupBackgroundService) failBackupsInProgress() error {
}
for _, backup := range backupsInProgress {
+ backupConfig, err := s.backupConfigService.GetBackupConfigByDbId(backup.DatabaseID)
+ if err != nil {
+ s.logger.Error("Failed to get backup config by database ID", "error", err)
+ continue
+ }
+
failMessage := "Backup failed due to application restart"
backup.FailMessage = &failMessage
backup.Status = BackupStatusFailed
backup.BackupSizeMb = 0
s.backupService.SendBackupNotification(
- backup.Database,
+ backupConfig,
backup,
- databases.NotificationBackupFailed,
+ backups_config.NotificationBackupFailed,
&failMessage,
)
@@ -87,9 +96,15 @@ func (s *BackupBackgroundService) cleanOldBackups() error {
}
for _, database := range allDatabases {
- backupStorePeriod := database.StorePeriod
+ backupConfig, err := s.backupConfigService.GetBackupConfigByDbId(database.ID)
+ if err != nil {
+ s.logger.Error("Failed to get backup config by database ID", "error", err)
+ continue
+ }
+
+ backupStorePeriod := backupConfig.StorePeriod
- if backupStorePeriod == databases.PeriodForever {
+ if backupStorePeriod == period.PeriodForever {
continue
}
@@ -148,7 +163,13 @@ func (s *BackupBackgroundService) runPendingBackups() error {
}
for _, database := range allDatabases {
- if database.BackupInterval == nil {
+ backupConfig, err := s.backupConfigService.GetBackupConfigByDbId(database.ID)
+ if err != nil {
+ s.logger.Error("Failed to get backup config by database ID", "error", err)
+ continue
+ }
+
+ if backupConfig.BackupInterval == nil {
continue
}
@@ -169,13 +190,13 @@ func (s *BackupBackgroundService) runPendingBackups() error {
lastBackupTime = &lastBackup.CreatedAt
}
- if database.BackupInterval.ShouldTriggerBackup(time.Now().UTC(), lastBackupTime) {
+ if backupConfig.BackupInterval.ShouldTriggerBackup(time.Now().UTC(), lastBackupTime) {
s.logger.Info(
"Triggering scheduled backup",
"databaseId",
database.ID,
"intervalType",
- database.BackupInterval.Interval,
+ backupConfig.BackupInterval.Interval,
)
go s.backupService.MakeBackup(database.ID)
diff --git a/backend/internal/features/backups/controller.go b/backend/internal/features/backups/backups/controller.go
similarity index 100%
rename from backend/internal/features/backups/controller.go
rename to backend/internal/features/backups/backups/controller.go
diff --git a/backend/internal/features/backups/di.go b/backend/internal/features/backups/backups/di.go
similarity index 76%
rename from backend/internal/features/backups/di.go
rename to backend/internal/features/backups/backups/di.go
index 023994bd..d6074e78 100644
--- a/backend/internal/features/backups/di.go
+++ b/backend/internal/features/backups/backups/di.go
@@ -1,7 +1,8 @@
package backups
import (
- "postgresus-backend/internal/features/backups/usecases"
+ "postgresus-backend/internal/features/backups/backups/usecases"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/notifiers"
"postgresus-backend/internal/features/storages"
@@ -17,8 +18,10 @@ var backupService = &BackupService{
backupRepository,
notifiers.GetNotifierService(),
notifiers.GetNotifierService(),
+ backups_config.GetBackupConfigService(),
usecases.GetCreateBackupUsecase(),
logger.GetLogger(),
+ []BackupRemoveListener{},
}
var backupBackgroundService = &BackupBackgroundService{
@@ -26,6 +29,7 @@ var backupBackgroundService = &BackupBackgroundService{
backupRepository,
databases.GetDatabaseService(),
storages.GetStorageService(),
+ backups_config.GetBackupConfigService(),
time.Now().UTC(),
logger.GetLogger(),
}
@@ -36,9 +40,11 @@ var backupController = &BackupController{
}
func SetupDependencies() {
- databases.
- GetDatabaseService().
+ backups_config.
+ GetBackupConfigService().
SetDatabaseStorageChangeListener(backupService)
+
+ databases.GetDatabaseService().AddDbRemoveListener(backupService)
}
func GetBackupService() *BackupService {
diff --git a/backend/internal/features/backups/enums.go b/backend/internal/features/backups/backups/enums.go
similarity index 80%
rename from backend/internal/features/backups/enums.go
rename to backend/internal/features/backups/backups/enums.go
index 3c1cb4aa..ef06b19b 100644
--- a/backend/internal/features/backups/enums.go
+++ b/backend/internal/features/backups/backups/enums.go
@@ -6,5 +6,4 @@ const (
BackupStatusInProgress BackupStatus = "IN_PROGRESS"
BackupStatusCompleted BackupStatus = "COMPLETED"
BackupStatusFailed BackupStatus = "FAILED"
- BackupStatusDeleted BackupStatus = "DELETED"
)
diff --git a/backend/internal/features/backups/interfaces.go b/backend/internal/features/backups/backups/interfaces.go
similarity index 72%
rename from backend/internal/features/backups/interfaces.go
rename to backend/internal/features/backups/backups/interfaces.go
index 2bd8443d..b4b7fb6e 100644
--- a/backend/internal/features/backups/interfaces.go
+++ b/backend/internal/features/backups/backups/interfaces.go
@@ -1,6 +1,7 @@
package backups
import (
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/notifiers"
"postgresus-backend/internal/features/storages"
@@ -19,6 +20,7 @@ type NotificationSender interface {
type CreateBackupUsecase interface {
Execute(
backupID uuid.UUID,
+ backupConfig *backups_config.BackupConfig,
database *databases.Database,
storage *storages.Storage,
backupProgressListener func(
@@ -26,3 +28,7 @@ type CreateBackupUsecase interface {
),
) error
}
+
+type BackupRemoveListener interface {
+ OnBeforeBackupRemove(backup *Backup) error
+}
diff --git a/backend/internal/features/backups/mocks.go b/backend/internal/features/backups/backups/mocks.go
similarity index 100%
rename from backend/internal/features/backups/mocks.go
rename to backend/internal/features/backups/backups/mocks.go
diff --git a/backend/internal/features/backups/model.go b/backend/internal/features/backups/backups/model.go
similarity index 100%
rename from backend/internal/features/backups/model.go
rename to backend/internal/features/backups/backups/model.go
diff --git a/backend/internal/features/backups/repository.go b/backend/internal/features/backups/backups/repository.go
similarity index 78%
rename from backend/internal/features/backups/repository.go
rename to backend/internal/features/backups/backups/repository.go
index c9bb0a1e..dc751135 100644
--- a/backend/internal/features/backups/repository.go
+++ b/backend/internal/features/backups/backups/repository.go
@@ -43,6 +43,22 @@ func (r *BackupRepository) FindByDatabaseID(databaseID uuid.UUID) ([]*Backup, er
return backups, nil
}
+func (r *BackupRepository) FindByStorageID(storageID uuid.UUID) ([]*Backup, error) {
+ var backups []*Backup
+
+ if err := storage.
+ GetDb().
+ Preload("Database").
+ Preload("Storage").
+ Where("storage_id = ?", storageID).
+ Order("created_at DESC").
+ Find(&backups).Error; err != nil {
+ return nil, err
+ }
+
+ return backups, nil
+}
+
func (r *BackupRepository) FindLastByDatabaseID(databaseID uuid.UUID) (*Backup, error) {
var backup Backup
@@ -113,6 +129,25 @@ func (r *BackupRepository) FindByStorageIdAndStatus(
return backups, nil
}
+func (r *BackupRepository) FindByDatabaseIdAndStatus(
+ databaseID uuid.UUID,
+ status BackupStatus,
+) ([]*Backup, error) {
+ var backups []*Backup
+
+ if err := storage.
+ GetDb().
+ Preload("Database").
+ Preload("Storage").
+ Where("database_id = ? AND status = ?", databaseID, status).
+ Order("created_at DESC").
+ Find(&backups).Error; err != nil {
+ return nil, err
+ }
+
+ return backups, nil
+}
+
func (r *BackupRepository) DeleteByID(id uuid.UUID) error {
return storage.GetDb().Delete(&Backup{}, "id = ?", id).Error
}
diff --git a/backend/internal/features/backups/service.go b/backend/internal/features/backups/backups/service.go
similarity index 69%
rename from backend/internal/features/backups/service.go
rename to backend/internal/features/backups/backups/service.go
index bdef57b1..37f6ebe1 100644
--- a/backend/internal/features/backups/service.go
+++ b/backend/internal/features/backups/backups/service.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log/slog"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/notifiers"
"postgresus-backend/internal/features/storages"
@@ -15,60 +16,42 @@ import (
)
type BackupService struct {
- databaseService *databases.DatabaseService
- storageService *storages.StorageService
- backupRepository *BackupRepository
- notifierService *notifiers.NotifierService
- notificationSender NotificationSender
+ databaseService *databases.DatabaseService
+ storageService *storages.StorageService
+ backupRepository *BackupRepository
+ notifierService *notifiers.NotifierService
+ notificationSender NotificationSender
+ backupConfigService *backups_config.BackupConfigService
createBackupUseCase CreateBackupUsecase
logger *slog.Logger
+
+ backupRemoveListeners []BackupRemoveListener
+}
+
+func (s *BackupService) AddBackupRemoveListener(listener BackupRemoveListener) {
+ s.backupRemoveListeners = append(s.backupRemoveListeners, listener)
}
-func (s *BackupService) OnBeforeDbStorageChange(
+func (s *BackupService) OnBeforeBackupsStorageChange(
databaseID uuid.UUID,
storageID uuid.UUID,
) error {
- // validate no backups in progress
- backups, err := s.backupRepository.FindByStorageIdAndStatus(
- storageID,
- BackupStatusInProgress,
- )
+ err := s.deleteDbBackups(databaseID)
if err != nil {
return err
}
- if len(backups) > 0 {
- return errors.New("backup is in progress, storage cannot")
- }
+ return nil
+}
- backupsWithStorage, err := s.backupRepository.FindByStorageIdAndStatus(
- storageID,
- BackupStatusCompleted,
- )
+func (s *BackupService) OnBeforeDatabaseRemove(databaseID uuid.UUID) error {
+ err := s.deleteDbBackups(databaseID)
if err != nil {
return err
}
- if len(backupsWithStorage) > 0 {
- for _, backup := range backupsWithStorage {
- if err := backup.Storage.DeleteFile(backup.ID); err != nil {
- // most likely we cannot do nothing with this,
- // so we just remove the backup model
- s.logger.Error("Failed to delete backup file", "error", err)
- }
-
- if err := s.backupRepository.DeleteByID(backup.ID); err != nil {
- return err
- }
- }
-
- // we repeat remove for the case if backup
- // started until we removed all previous backups
- return s.OnBeforeDbStorageChange(databaseID, storageID)
- }
-
return nil
}
@@ -128,10 +111,7 @@ func (s *BackupService) DeleteBackup(
return errors.New("backup is in progress")
}
- backup.DeleteBackupFromStorage(s.logger)
-
- backup.Status = BackupStatusDeleted
- return s.backupRepository.Save(backup)
+ return s.deleteBackup(backup)
}
func (s *BackupService) MakeBackup(databaseID uuid.UUID) {
@@ -152,7 +132,23 @@ func (s *BackupService) MakeBackup(databaseID uuid.UUID) {
return
}
- storage, err := s.storageService.GetStorageByID(database.StorageID)
+ backupConfig, err := s.backupConfigService.GetBackupConfigByDbId(databaseID)
+ if err != nil {
+ s.logger.Error("Failed to get backup config by database ID", "error", err)
+ return
+ }
+
+ if !backupConfig.IsBackupsEnabled {
+ s.logger.Info("Backups are not enabled for this database")
+ return
+ }
+
+ if backupConfig.StorageID == nil {
+ s.logger.Error("Backup config storage ID is not defined")
+ return
+ }
+
+ storage, err := s.storageService.GetStorageByID(*backupConfig.StorageID)
if err != nil {
s.logger.Error("Failed to get storage by ID", "error", err)
return
@@ -192,6 +188,7 @@ func (s *BackupService) MakeBackup(databaseID uuid.UUID) {
err = s.createBackupUseCase.Execute(
backup.ID,
+ backupConfig,
database,
storage,
backupProgressListener,
@@ -218,9 +215,9 @@ func (s *BackupService) MakeBackup(databaseID uuid.UUID) {
}
s.SendBackupNotification(
- database,
+ backupConfig,
backup,
- databases.NotificationBackupFailed,
+ backups_config.NotificationBackupFailed,
&errMsg,
)
@@ -248,27 +245,27 @@ func (s *BackupService) MakeBackup(databaseID uuid.UUID) {
}
s.SendBackupNotification(
- database,
+ backupConfig,
backup,
- databases.NotificationBackupSuccess,
+ backups_config.NotificationBackupSuccess,
nil,
)
}
func (s *BackupService) SendBackupNotification(
- db *databases.Database,
+ backupConfig *backups_config.BackupConfig,
backup *Backup,
- notificationType databases.BackupNotificationType,
+ notificationType backups_config.BackupNotificationType,
errorMessage *string,
) {
- database, err := s.databaseService.GetDatabaseByID(db.ID)
+ database, err := s.databaseService.GetDatabaseByID(backupConfig.DatabaseID)
if err != nil {
return
}
for _, notifier := range database.Notifiers {
if !slices.Contains(
- database.SendNotificationsOn,
+ backupConfig.SendNotificationsOn,
notificationType,
) {
continue
@@ -276,9 +273,9 @@ func (s *BackupService) SendBackupNotification(
title := ""
switch notificationType {
- case databases.NotificationBackupFailed:
+ case backups_config.NotificationBackupFailed:
title = fmt.Sprintf("❌ Backup failed for database \"%s\"", database.Name)
- case databases.NotificationBackupSuccess:
+ case backups_config.NotificationBackupSuccess:
title = fmt.Sprintf("✅ Backup completed for database \"%s\"", database.Name)
}
@@ -319,3 +316,45 @@ func (s *BackupService) SendBackupNotification(
func (s *BackupService) GetBackup(backupID uuid.UUID) (*Backup, error) {
return s.backupRepository.FindByID(backupID)
}
+
+func (s *BackupService) deleteBackup(backup *Backup) error {
+ for _, listener := range s.backupRemoveListeners {
+ if err := listener.OnBeforeBackupRemove(backup); err != nil {
+ return err
+ }
+ }
+
+ backup.DeleteBackupFromStorage(s.logger)
+
+ return s.backupRepository.DeleteByID(backup.ID)
+}
+
+func (s *BackupService) deleteDbBackups(databaseID uuid.UUID) error {
+ dbBackupsInProgress, err := s.backupRepository.FindByDatabaseIdAndStatus(
+ databaseID,
+ BackupStatusInProgress,
+ )
+ if err != nil {
+ return err
+ }
+
+ if len(dbBackupsInProgress) > 0 {
+ return errors.New("backup is in progress, storage cannot be removed")
+ }
+
+ dbBackups, err := s.backupRepository.FindByDatabaseID(
+ databaseID,
+ )
+ if err != nil {
+ return err
+ }
+
+ for _, dbBackup := range dbBackups {
+ err := s.deleteBackup(dbBackup)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
diff --git a/backend/internal/features/backups/service_test.go b/backend/internal/features/backups/backups/service_test.go
similarity index 90%
rename from backend/internal/features/backups/service_test.go
rename to backend/internal/features/backups/backups/service_test.go
index 897e7a9d..b0d02056 100644
--- a/backend/internal/features/backups/service_test.go
+++ b/backend/internal/features/backups/backups/service_test.go
@@ -2,6 +2,7 @@ package backups
import (
"errors"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/notifiers"
"postgresus-backend/internal/features/storages"
@@ -20,6 +21,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
storage := storages.CreateTestStorage(user.UserID)
notifier := notifiers.CreateTestNotifier(user.UserID)
database := databases.CreateTestDatabase(user.UserID, storage, notifier)
+ backups_config.EnableBackupsForTestDatabase(database.ID, storage)
defer storages.RemoveTestStorage(storage.ID)
defer notifiers.RemoveTestNotifier(notifier)
@@ -33,8 +35,10 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
backupRepository,
notifiers.GetNotifierService(),
mockNotificationSender,
+ backups_config.GetBackupConfigService(),
&CreateFailedBackupUsecase{},
logger.GetLogger(),
+ []BackupRemoveListener{},
}
// Set up expectations
@@ -74,8 +78,10 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
backupRepository,
notifiers.GetNotifierService(),
mockNotificationSender,
+ backups_config.GetBackupConfigService(),
&CreateSuccessBackupUsecase{},
logger.GetLogger(),
+ []BackupRemoveListener{},
}
backupService.MakeBackup(database.ID)
@@ -92,8 +98,10 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
backupRepository,
notifiers.GetNotifierService(),
mockNotificationSender,
+ backups_config.GetBackupConfigService(),
&CreateSuccessBackupUsecase{},
logger.GetLogger(),
+ []BackupRemoveListener{},
}
// capture arguments
@@ -130,6 +138,7 @@ type CreateFailedBackupUsecase struct {
func (uc *CreateFailedBackupUsecase) Execute(
backupID uuid.UUID,
+ backupConfig *backups_config.BackupConfig,
database *databases.Database,
storage *storages.Storage,
backupProgressListener func(
@@ -145,6 +154,7 @@ type CreateSuccessBackupUsecase struct {
func (uc *CreateSuccessBackupUsecase) Execute(
backupID uuid.UUID,
+ backupConfig *backups_config.BackupConfig,
database *databases.Database,
storage *storages.Storage,
backupProgressListener func(
diff --git a/backend/internal/features/backups/usecases/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/create_backup_uc.go
similarity index 83%
rename from backend/internal/features/backups/usecases/create_backup_uc.go
rename to backend/internal/features/backups/backups/usecases/create_backup_uc.go
index b75fe5d9..75d181db 100644
--- a/backend/internal/features/backups/usecases/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/create_backup_uc.go
@@ -2,7 +2,8 @@ package usecases
import (
"errors"
- usecases_postgresql "postgresus-backend/internal/features/backups/usecases/postgresql"
+ usecases_postgresql "postgresus-backend/internal/features/backups/backups/usecases/postgresql"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/storages"
@@ -16,6 +17,7 @@ type CreateBackupUsecase struct {
// Execute creates a backup of the database and returns the backup size in MB
func (uc *CreateBackupUsecase) Execute(
backupID uuid.UUID,
+ backupConfig *backups_config.BackupConfig,
database *databases.Database,
storage *storages.Storage,
backupProgressListener func(
@@ -25,6 +27,7 @@ func (uc *CreateBackupUsecase) Execute(
if database.Type == databases.DatabaseTypePostgres {
return uc.CreatePostgresqlBackupUsecase.Execute(
backupID,
+ backupConfig,
database,
storage,
backupProgressListener,
diff --git a/backend/internal/features/backups/usecases/di.go b/backend/internal/features/backups/backups/usecases/di.go
similarity index 89%
rename from backend/internal/features/backups/usecases/di.go
rename to backend/internal/features/backups/backups/usecases/di.go
index 69fb3c1b..0bda57c7 100644
--- a/backend/internal/features/backups/usecases/di.go
+++ b/backend/internal/features/backups/backups/usecases/di.go
@@ -1,7 +1,7 @@
package usecases
import (
- usecases_postgresql "postgresus-backend/internal/features/backups/usecases/postgresql"
+ usecases_postgresql "postgresus-backend/internal/features/backups/backups/usecases/postgresql"
)
var createBackupUsecase = &CreateBackupUsecase{
diff --git a/backend/internal/features/backups/usecases/postgresql/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go
similarity index 97%
rename from backend/internal/features/backups/usecases/postgresql/create_backup_uc.go
rename to backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go
index 470e6701..383f3b25 100644
--- a/backend/internal/features/backups/usecases/postgresql/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go
@@ -14,6 +14,7 @@ import (
"time"
"postgresus-backend/internal/config"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
pgtypes "postgresus-backend/internal/features/databases/databases/postgresql"
"postgresus-backend/internal/features/storages"
@@ -29,6 +30,7 @@ type CreatePostgresqlBackupUsecase struct {
// Execute creates a backup of the database
func (uc *CreatePostgresqlBackupUsecase) Execute(
backupID uuid.UUID,
+ backupConfig *backups_config.BackupConfig,
db *databases.Database,
storage *storages.Storage,
backupProgressListener func(
@@ -43,6 +45,10 @@ func (uc *CreatePostgresqlBackupUsecase) Execute(
storage.ID,
)
+ if !backupConfig.IsBackupsEnabled {
+ return fmt.Errorf("backups are not enabled for this database: \"%s\"", db.Name)
+ }
+
pg := db.Postgresql
if pg == nil {
@@ -66,6 +72,7 @@ func (uc *CreatePostgresqlBackupUsecase) Execute(
return uc.streamToStorage(
backupID,
+ backupConfig,
tools.GetPostgresqlExecutable(
pg.Version,
"pg_dump",
@@ -83,6 +90,7 @@ func (uc *CreatePostgresqlBackupUsecase) Execute(
// streamToStorage streams pg_dump output directly to storage
func (uc *CreatePostgresqlBackupUsecase) streamToStorage(
backupID uuid.UUID,
+ backupConfig *backups_config.BackupConfig,
pgBin string,
args []string,
password string,
@@ -156,7 +164,7 @@ func (uc *CreatePostgresqlBackupUsecase) streamToStorage(
"passwordEmpty", password == "",
"pgBin", pgBin,
"usingPgpassFile", true,
- "parallelJobs", db.Postgresql.CpuCount,
+ "parallelJobs", backupConfig.CpuCount,
)
// Add PostgreSQL-specific environment variables
diff --git a/backend/internal/features/backups/usecases/postgresql/di.go b/backend/internal/features/backups/backups/usecases/postgresql/di.go
similarity index 100%
rename from backend/internal/features/backups/usecases/postgresql/di.go
rename to backend/internal/features/backups/backups/usecases/postgresql/di.go
diff --git a/backend/internal/features/backups/usecases/postgresql/interfaces.go b/backend/internal/features/backups/backups/usecases/postgresql/interfaces.go
similarity index 100%
rename from backend/internal/features/backups/usecases/postgresql/interfaces.go
rename to backend/internal/features/backups/backups/usecases/postgresql/interfaces.go
diff --git a/backend/internal/features/backups/config/controller.go b/backend/internal/features/backups/config/controller.go
new file mode 100644
index 00000000..97596522
--- /dev/null
+++ b/backend/internal/features/backups/config/controller.go
@@ -0,0 +1,144 @@
+package backups_config
+
+import (
+ "net/http"
+ "postgresus-backend/internal/features/users"
+
+ "github.com/gin-gonic/gin"
+ "github.com/google/uuid"
+)
+
+type BackupConfigController struct {
+ backupConfigService *BackupConfigService
+ userService *users.UserService
+}
+
+func (c *BackupConfigController) RegisterRoutes(router *gin.RouterGroup) {
+ router.POST("/backup-configs/save", c.SaveBackupConfig)
+ router.GET("/backup-configs/database/:id", c.GetBackupConfigByDbID)
+ router.GET("/backup-configs/storage/:id/is-using", c.IsStorageUsing)
+}
+
+// SaveBackupConfig
+// @Summary Save backup configuration
+// @Description Save or update backup configuration for a database
+// @Tags backup-configs
+// @Accept json
+// @Produce json
+// @Param request body BackupConfig true "Backup configuration data"
+// @Success 200 {object} BackupConfig
+// @Failure 400
+// @Failure 401
+// @Failure 500
+// @Router /backup-configs/save [post]
+func (c *BackupConfigController) SaveBackupConfig(ctx *gin.Context) {
+ var request BackupConfig
+ if err := ctx.ShouldBindJSON(&request); err != nil {
+ ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ return
+ }
+
+ authorizationHeader := ctx.GetHeader("Authorization")
+ if authorizationHeader == "" {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "authorization header is required"})
+ return
+ }
+
+ _, err := c.userService.GetUserFromToken(authorizationHeader)
+ if err != nil {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
+ return
+ }
+
+ savedConfig, err := c.backupConfigService.SaveBackupConfig(&request)
+ if err != nil {
+ ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ return
+ }
+
+ ctx.JSON(http.StatusOK, savedConfig)
+}
+
+// GetBackupConfigByDbID
+// @Summary Get backup configuration by database ID
+// @Description Get backup configuration for a specific database
+// @Tags backup-configs
+// @Produce json
+// @Param id path string true "Database ID"
+// @Success 200 {object} BackupConfig
+// @Failure 400
+// @Failure 401
+// @Failure 404
+// @Router /backup-configs/database/{id} [get]
+func (c *BackupConfigController) GetBackupConfigByDbID(ctx *gin.Context) {
+ id, err := uuid.Parse(ctx.Param("id"))
+ if err != nil {
+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid database ID"})
+ return
+ }
+
+ authorizationHeader := ctx.GetHeader("Authorization")
+ if authorizationHeader == "" {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "authorization header is required"})
+ return
+ }
+
+ _, err = c.userService.GetUserFromToken(authorizationHeader)
+ if err != nil {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
+ return
+ }
+
+ user, err := c.userService.GetUserFromToken(authorizationHeader)
+ if err != nil {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
+ return
+ }
+
+ backupConfig, err := c.backupConfigService.GetBackupConfigByDbIdWithAuth(user, id)
+ if err != nil {
+ ctx.JSON(http.StatusNotFound, gin.H{"error": "backup configuration not found"})
+ return
+ }
+
+ ctx.JSON(http.StatusOK, backupConfig)
+}
+
+// IsStorageUsing
+// @Summary Check if storage is being used
+// @Description Check if a storage is currently being used by any backup configuration
+// @Tags backup-configs
+// @Produce json
+// @Param id path string true "Storage ID"
+// @Success 200 {object} map[string]bool
+// @Failure 400
+// @Failure 401
+// @Failure 500
+// @Router /backup-configs/storage/{id}/is-using [get]
+func (c *BackupConfigController) IsStorageUsing(ctx *gin.Context) {
+ id, err := uuid.Parse(ctx.Param("id"))
+ if err != nil {
+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid storage ID"})
+ return
+ }
+
+ authorizationHeader := ctx.GetHeader("Authorization")
+ if authorizationHeader == "" {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "authorization header is required"})
+ return
+ }
+
+ user, err := c.userService.GetUserFromToken(authorizationHeader)
+ if err != nil {
+ ctx.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
+ return
+ }
+
+ isUsing, err := c.backupConfigService.IsStorageUsing(user, id)
+ if err != nil {
+ ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
+ return
+ }
+
+ ctx.JSON(http.StatusOK, gin.H{"isUsing": isUsing})
+}
diff --git a/backend/internal/features/backups/config/di.go b/backend/internal/features/backups/config/di.go
new file mode 100644
index 00000000..575126cf
--- /dev/null
+++ b/backend/internal/features/backups/config/di.go
@@ -0,0 +1,27 @@
+package backups_config
+
+import (
+ "postgresus-backend/internal/features/databases"
+ "postgresus-backend/internal/features/storages"
+ "postgresus-backend/internal/features/users"
+)
+
+var backupConfigRepository = &BackupConfigRepository{}
+var backupConfigService = &BackupConfigService{
+ backupConfigRepository,
+ databases.GetDatabaseService(),
+ storages.GetStorageService(),
+ nil,
+}
+var backupConfigController = &BackupConfigController{
+ backupConfigService,
+ users.GetUserService(),
+}
+
+func GetBackupConfigController() *BackupConfigController {
+ return backupConfigController
+}
+
+func GetBackupConfigService() *BackupConfigService {
+ return backupConfigService
+}
diff --git a/backend/internal/features/backups/config/enums.go b/backend/internal/features/backups/config/enums.go
new file mode 100644
index 00000000..b37455f9
--- /dev/null
+++ b/backend/internal/features/backups/config/enums.go
@@ -0,0 +1,8 @@
+package backups_config
+
+type BackupNotificationType string
+
+const (
+ NotificationBackupFailed BackupNotificationType = "BACKUP_FAILED"
+ NotificationBackupSuccess BackupNotificationType = "BACKUP_SUCCESS"
+)
diff --git a/backend/internal/features/backups/config/interfaces.go b/backend/internal/features/backups/config/interfaces.go
new file mode 100644
index 00000000..b9f6cbfa
--- /dev/null
+++ b/backend/internal/features/backups/config/interfaces.go
@@ -0,0 +1,7 @@
+package backups_config
+
+import "github.com/google/uuid"
+
+type BackupConfigStorageChangeListener interface {
+ OnBeforeBackupsStorageChange(dbID uuid.UUID, storageID uuid.UUID) error
+}
diff --git a/backend/internal/features/backups/config/model.go b/backend/internal/features/backups/config/model.go
new file mode 100644
index 00000000..bb66d7c0
--- /dev/null
+++ b/backend/internal/features/backups/config/model.go
@@ -0,0 +1,85 @@
+package backups_config
+
+import (
+ "errors"
+ "postgresus-backend/internal/features/intervals"
+ "postgresus-backend/internal/features/storages"
+ "postgresus-backend/internal/util/period"
+ "strings"
+
+ "github.com/google/uuid"
+ "gorm.io/gorm"
+)
+
+type BackupConfig struct {
+ DatabaseID uuid.UUID `json:"databaseId" gorm:"column:database_id;type:uuid;primaryKey;not null"`
+
+ IsBackupsEnabled bool `json:"isBackupsEnabled" gorm:"column:is_backups_enabled;type:boolean;not null"`
+
+ StorePeriod period.Period `json:"storePeriod" gorm:"column:store_period;type:text;not null"`
+
+ BackupIntervalID uuid.UUID `json:"backupIntervalId" gorm:"column:backup_interval_id;type:uuid;not null"`
+ BackupInterval *intervals.Interval `json:"backupInterval,omitempty" gorm:"foreignKey:BackupIntervalID"`
+
+ Storage *storages.Storage `json:"storage" gorm:"foreignKey:StorageID"`
+ StorageID *uuid.UUID `json:"storageId" gorm:"column:storage_id;type:uuid;"`
+
+ SendNotificationsOn []BackupNotificationType `json:"sendNotificationsOn" gorm:"-"`
+ SendNotificationsOnString string `json:"-" gorm:"column:send_notifications_on;type:text;not null"`
+
+ CpuCount int `json:"cpuCount" gorm:"type:int;not null"`
+}
+
+func (h *BackupConfig) TableName() string {
+ return "backup_configs"
+}
+
+func (b *BackupConfig) BeforeSave(tx *gorm.DB) error {
+ // Convert SendNotificationsOn array to string
+ if len(b.SendNotificationsOn) > 0 {
+ notificationTypes := make([]string, len(b.SendNotificationsOn))
+
+ for i, notificationType := range b.SendNotificationsOn {
+ notificationTypes[i] = string(notificationType)
+ }
+
+ b.SendNotificationsOnString = strings.Join(notificationTypes, ",")
+ } else {
+ b.SendNotificationsOnString = ""
+ }
+
+ return nil
+}
+
+func (b *BackupConfig) AfterFind(tx *gorm.DB) error {
+ // Convert SendNotificationsOnString to array
+ if b.SendNotificationsOnString != "" {
+ notificationTypes := strings.Split(b.SendNotificationsOnString, ",")
+ b.SendNotificationsOn = make([]BackupNotificationType, len(notificationTypes))
+
+ for i, notificationType := range notificationTypes {
+ b.SendNotificationsOn[i] = BackupNotificationType(notificationType)
+ }
+ } else {
+ b.SendNotificationsOn = []BackupNotificationType{}
+ }
+
+ return nil
+}
+
+func (b *BackupConfig) Validate() error {
+ // Backup interval is required either as ID or as object
+ if b.BackupIntervalID == uuid.Nil && b.BackupInterval == nil {
+ return errors.New("backup interval is required")
+ }
+
+ if b.StorePeriod == "" {
+ return errors.New("store period is required")
+ }
+
+ if b.CpuCount == 0 {
+ return errors.New("cpu count is required")
+ }
+
+ return nil
+}
diff --git a/backend/internal/features/backups/config/repository.go b/backend/internal/features/backups/config/repository.go
new file mode 100644
index 00000000..3d7c4870
--- /dev/null
+++ b/backend/internal/features/backups/config/repository.go
@@ -0,0 +1,104 @@
+package backups_config
+
+import (
+ "errors"
+ "postgresus-backend/internal/storage"
+
+ "github.com/google/uuid"
+ "gorm.io/gorm"
+)
+
+type BackupConfigRepository struct{}
+
+func (r *BackupConfigRepository) Save(
+ backupConfig *BackupConfig,
+) (*BackupConfig, error) {
+ db := storage.GetDb()
+
+ err := db.Transaction(func(tx *gorm.DB) error {
+ // Handle BackupInterval
+ if backupConfig.BackupInterval != nil {
+ if backupConfig.BackupInterval.ID == uuid.Nil {
+ if err := tx.Create(backupConfig.BackupInterval).Error; err != nil {
+ return err
+ }
+
+ backupConfig.BackupIntervalID = backupConfig.BackupInterval.ID
+ } else {
+ if err := tx.Save(backupConfig.BackupInterval).Error; err != nil {
+ return err
+ }
+
+ backupConfig.BackupIntervalID = backupConfig.BackupInterval.ID
+ }
+ }
+
+ // Set storage ID
+ if backupConfig.Storage != nil && backupConfig.Storage.ID != uuid.Nil {
+ backupConfig.StorageID = &backupConfig.Storage.ID
+ }
+
+ // Use Save which handles both create and update based on primary key
+ if err := tx.Save(backupConfig).
+ Omit("BackupInterval", "Storage").
+ Error; err != nil {
+ return err
+ }
+
+ return nil
+ })
+
+ if err != nil {
+ return nil, err
+ }
+
+ return backupConfig, nil
+}
+
+func (r *BackupConfigRepository) FindByDatabaseID(databaseID uuid.UUID) (*BackupConfig, error) {
+ var backupConfig BackupConfig
+
+ if err := storage.
+ GetDb().
+ Preload("BackupInterval").
+ Preload("Storage").
+ Where("database_id = ?", databaseID).
+ First(&backupConfig).Error; err != nil {
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, nil
+ }
+
+ return nil, err
+ }
+
+ return &backupConfig, nil
+}
+
+func (r *BackupConfigRepository) FindWithEnabledBackups() ([]*BackupConfig, error) {
+ var backupConfigs []*BackupConfig
+
+ if err := storage.
+ GetDb().
+ Preload("BackupInterval").
+ Preload("Storage").
+ Where("is_backups_enabled = ?", true).
+ Find(&backupConfigs).Error; err != nil {
+ return nil, err
+ }
+
+ return backupConfigs, nil
+}
+
+func (r *BackupConfigRepository) IsStorageUsing(storageID uuid.UUID) (bool, error) {
+ var count int64
+
+ if err := storage.
+ GetDb().
+ Table("backup_configs").
+ Where("storage_id = ?", storageID).
+ Count(&count).Error; err != nil {
+ return false, err
+ }
+
+ return count > 0, nil
+}
diff --git a/backend/internal/features/backups/config/service.go b/backend/internal/features/backups/config/service.go
new file mode 100644
index 00000000..e2670ee2
--- /dev/null
+++ b/backend/internal/features/backups/config/service.go
@@ -0,0 +1,167 @@
+package backups_config
+
+import (
+ "postgresus-backend/internal/features/databases"
+ "postgresus-backend/internal/features/intervals"
+ "postgresus-backend/internal/features/storages"
+ users_models "postgresus-backend/internal/features/users/models"
+ "postgresus-backend/internal/util/period"
+
+ "github.com/google/uuid"
+)
+
+type BackupConfigService struct {
+ backupConfigRepository *BackupConfigRepository
+ databaseService *databases.DatabaseService
+ storageService *storages.StorageService
+
+ dbStorageChangeListener BackupConfigStorageChangeListener
+}
+
+func (s *BackupConfigService) SetDatabaseStorageChangeListener(
+ dbStorageChangeListener BackupConfigStorageChangeListener,
+) {
+ s.dbStorageChangeListener = dbStorageChangeListener
+}
+
+func (s *BackupConfigService) SaveBackupConfigWithAuth(
+ user *users_models.User,
+ backupConfig *BackupConfig,
+) (*BackupConfig, error) {
+ if err := backupConfig.Validate(); err != nil {
+ return nil, err
+ }
+
+ _, err := s.databaseService.GetDatabase(user, backupConfig.DatabaseID)
+ if err != nil {
+ return nil, err
+ }
+
+ return s.SaveBackupConfig(backupConfig)
+}
+
+func (s *BackupConfigService) SaveBackupConfig(
+ backupConfig *BackupConfig,
+) (*BackupConfig, error) {
+ if err := backupConfig.Validate(); err != nil {
+ return nil, err
+ }
+
+ // Check if there's an existing backup config for this database
+ existingConfig, err := s.GetBackupConfigByDbId(backupConfig.DatabaseID)
+ if err != nil {
+ return nil, err
+ }
+
+ if existingConfig != nil {
+ // If storage is changing, notify the listener
+ if s.dbStorageChangeListener != nil &&
+ !storageIDsEqual(existingConfig.StorageID, backupConfig.StorageID) {
+ var newStorageID uuid.UUID
+
+ if backupConfig.StorageID != nil {
+ newStorageID = *backupConfig.StorageID
+ }
+
+ if err := s.dbStorageChangeListener.OnBeforeBackupsStorageChange(
+ backupConfig.DatabaseID,
+ newStorageID,
+ ); err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ if !backupConfig.IsBackupsEnabled && backupConfig.StorageID != nil {
+ if err := s.dbStorageChangeListener.OnBeforeBackupsStorageChange(
+ backupConfig.DatabaseID,
+ *backupConfig.StorageID,
+ ); err != nil {
+ return nil, err
+ }
+
+ // we clear storage for disabled backups to allow
+ // storage removal for unused storages
+ backupConfig.Storage = nil
+ backupConfig.StorageID = nil
+ }
+
+ return s.backupConfigRepository.Save(backupConfig)
+}
+
+func (s *BackupConfigService) GetBackupConfigByDbIdWithAuth(
+ user *users_models.User,
+ databaseID uuid.UUID,
+) (*BackupConfig, error) {
+ _, err := s.databaseService.GetDatabase(user, databaseID)
+ if err != nil {
+ return nil, err
+ }
+
+ return s.GetBackupConfigByDbId(databaseID)
+}
+
+func (s *BackupConfigService) GetBackupConfigByDbId(
+ databaseID uuid.UUID,
+) (*BackupConfig, error) {
+ config, err := s.backupConfigRepository.FindByDatabaseID(databaseID)
+ if err != nil {
+ return nil, err
+ }
+
+ if config == nil {
+ err = s.initializeDefaultConfig(databaseID)
+ if err != nil {
+ return nil, err
+ }
+
+ return s.backupConfigRepository.FindByDatabaseID(databaseID)
+ }
+
+ return config, nil
+}
+
+func (s *BackupConfigService) IsStorageUsing(
+ user *users_models.User,
+ storageID uuid.UUID,
+) (bool, error) {
+ _, err := s.storageService.GetStorage(user, storageID)
+ if err != nil {
+ return false, err
+ }
+
+ return s.backupConfigRepository.IsStorageUsing(storageID)
+}
+
+func (s *BackupConfigService) initializeDefaultConfig(
+ databaseID uuid.UUID,
+) error {
+ timeOfDay := "04:00"
+
+ _, err := s.backupConfigRepository.Save(&BackupConfig{
+ DatabaseID: databaseID,
+ IsBackupsEnabled: false,
+ StorePeriod: period.PeriodWeek,
+ BackupInterval: &intervals.Interval{
+ Interval: intervals.IntervalDaily,
+ TimeOfDay: &timeOfDay,
+ },
+ SendNotificationsOn: []BackupNotificationType{
+ NotificationBackupFailed,
+ NotificationBackupSuccess,
+ },
+ CpuCount: 1,
+ })
+
+ return err
+}
+
+func storageIDsEqual(id1, id2 *uuid.UUID) bool {
+ if id1 == nil && id2 == nil {
+ return true
+ }
+ if id1 == nil || id2 == nil {
+ return false
+ }
+ return *id1 == *id2
+}
diff --git a/backend/internal/features/backups/config/testing.go b/backend/internal/features/backups/config/testing.go
new file mode 100644
index 00000000..8a4c0107
--- /dev/null
+++ b/backend/internal/features/backups/config/testing.go
@@ -0,0 +1,40 @@
+package backups_config
+
+import (
+ "postgresus-backend/internal/features/intervals"
+ "postgresus-backend/internal/features/storages"
+ "postgresus-backend/internal/util/period"
+
+ "github.com/google/uuid"
+)
+
+func EnableBackupsForTestDatabase(
+ databaseID uuid.UUID,
+ storage *storages.Storage,
+) *BackupConfig {
+ timeOfDay := "16:00"
+
+ backupConfig := &BackupConfig{
+ DatabaseID: databaseID,
+ IsBackupsEnabled: true,
+ StorePeriod: period.PeriodDay,
+ BackupInterval: &intervals.Interval{
+ Interval: intervals.IntervalDaily,
+ TimeOfDay: &timeOfDay,
+ },
+ StorageID: &storage.ID,
+ Storage: storage,
+ SendNotificationsOn: []BackupNotificationType{
+ NotificationBackupFailed,
+ NotificationBackupSuccess,
+ },
+ CpuCount: 1,
+ }
+
+ backupConfig, err := GetBackupConfigService().SaveBackupConfig(backupConfig)
+ if err != nil {
+ panic(err)
+ }
+
+ return backupConfig
+}
diff --git a/backend/internal/features/databases/controller.go b/backend/internal/features/databases/controller.go
index 61da44fa..2ed4738d 100644
--- a/backend/internal/features/databases/controller.go
+++ b/backend/internal/features/databases/controller.go
@@ -22,7 +22,7 @@ func (c *DatabaseController) RegisterRoutes(router *gin.RouterGroup) {
router.POST("/databases/:id/test-connection", c.TestDatabaseConnection)
router.POST("/databases/test-connection-direct", c.TestDatabaseConnectionDirect)
router.GET("/databases/notifier/:id/is-using", c.IsNotifierUsing)
- router.GET("/databases/storage/:id/is-using", c.IsStorageUsing)
+
}
// CreateDatabase
@@ -56,12 +56,13 @@ func (c *DatabaseController) CreateDatabase(ctx *gin.Context) {
return
}
- if err := c.databaseService.CreateDatabase(user, &request); err != nil {
+ database, err := c.databaseService.CreateDatabase(user, &request)
+ if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
- ctx.JSON(http.StatusCreated, request)
+ ctx.JSON(http.StatusCreated, database)
}
// UpdateDatabase
@@ -310,52 +311,13 @@ func (c *DatabaseController) IsNotifierUsing(ctx *gin.Context) {
return
}
- _, err = c.userService.GetUserFromToken(authorizationHeader)
- if err != nil {
- ctx.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
- return
- }
-
- isUsing, err := c.databaseService.IsNotifierUsing(id)
- if err != nil {
- ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
- return
- }
-
- ctx.JSON(http.StatusOK, gin.H{"isUsing": isUsing})
-}
-
-// IsStorageUsing
-// @Summary Check if storage is being used
-// @Description Check if a storage is currently being used by any database
-// @Tags databases
-// @Produce json
-// @Param id path string true "Storage ID"
-// @Success 200 {object} map[string]bool
-// @Failure 400
-// @Failure 401
-// @Failure 500
-// @Router /databases/storage/{id}/is-using [get]
-func (c *DatabaseController) IsStorageUsing(ctx *gin.Context) {
- id, err := uuid.Parse(ctx.Param("id"))
- if err != nil {
- ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid storage ID"})
- return
- }
-
- authorizationHeader := ctx.GetHeader("Authorization")
- if authorizationHeader == "" {
- ctx.JSON(http.StatusUnauthorized, gin.H{"error": "authorization header is required"})
- return
- }
-
- _, err = c.userService.GetUserFromToken(authorizationHeader)
+ user, err := c.userService.GetUserFromToken(authorizationHeader)
if err != nil {
ctx.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
return
}
- isUsing, err := c.databaseService.IsStorageUsing(id)
+ isUsing, err := c.databaseService.IsNotifierUsing(user, id)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
diff --git a/backend/internal/features/databases/databases/postgresql/model.go b/backend/internal/features/databases/databases/postgresql/model.go
index 3be61cb0..0a3eafd9 100644
--- a/backend/internal/features/databases/databases/postgresql/model.go
+++ b/backend/internal/features/databases/databases/postgresql/model.go
@@ -27,8 +27,6 @@ type PostgresqlDatabase struct {
Password string `json:"password" gorm:"type:text;not null"`
Database *string `json:"database" gorm:"type:text"`
IsHttps bool `json:"isHttps" gorm:"type:boolean;default:false"`
-
- CpuCount int `json:"cpuCount" gorm:"type:int;not null"`
}
func (p *PostgresqlDatabase) TableName() string {
diff --git a/backend/internal/features/databases/di.go b/backend/internal/features/databases/di.go
index 38ba4ec2..59d067c6 100644
--- a/backend/internal/features/databases/di.go
+++ b/backend/internal/features/databases/di.go
@@ -12,8 +12,8 @@ var databaseService = &DatabaseService{
databaseRepository,
notifiers.GetNotifierService(),
logger.GetLogger(),
- nil,
- nil,
+ []DatabaseCreationListener{},
+ []DatabaseRemoveListener{},
}
var databaseController = &DatabaseController{
diff --git a/backend/internal/features/databases/enums.go b/backend/internal/features/databases/enums.go
index dafe700b..722115d1 100644
--- a/backend/internal/features/databases/enums.go
+++ b/backend/internal/features/databases/enums.go
@@ -1,66 +1,11 @@
package databases
-import "time"
-
type DatabaseType string
const (
DatabaseTypePostgres DatabaseType = "POSTGRES"
)
-type Period string
-
-const (
- PeriodDay Period = "DAY"
- PeriodWeek Period = "WEEK"
- PeriodMonth Period = "MONTH"
- Period3Month Period = "3_MONTH"
- Period6Month Period = "6_MONTH"
- PeriodYear Period = "YEAR"
- Period2Years Period = "2_YEARS"
- Period3Years Period = "3_YEARS"
- Period4Years Period = "4_YEARS"
- Period5Years Period = "5_YEARS"
- PeriodForever Period = "FOREVER"
-)
-
-// ToDuration converts Period to time.Duration
-func (p Period) ToDuration() time.Duration {
- switch p {
- case PeriodDay:
- return 24 * time.Hour
- case PeriodWeek:
- return 7 * 24 * time.Hour
- case PeriodMonth:
- return 30 * 24 * time.Hour
- case Period3Month:
- return 90 * 24 * time.Hour
- case Period6Month:
- return 180 * 24 * time.Hour
- case PeriodYear:
- return 365 * 24 * time.Hour
- case Period2Years:
- return 2 * 365 * 24 * time.Hour
- case Period3Years:
- return 3 * 365 * 24 * time.Hour
- case Period4Years:
- return 4 * 365 * 24 * time.Hour
- case Period5Years:
- return 5 * 365 * 24 * time.Hour
- case PeriodForever:
- return 0
- default:
- panic("unknown period: " + string(p))
- }
-}
-
-type BackupNotificationType string
-
-const (
- NotificationBackupFailed BackupNotificationType = "BACKUP_FAILED"
- NotificationBackupSuccess BackupNotificationType = "BACKUP_SUCCESS"
-)
-
type HealthStatus string
const (
diff --git a/backend/internal/features/databases/interfaces.go b/backend/internal/features/databases/interfaces.go
index d8e92c00..ba63d6ab 100644
--- a/backend/internal/features/databases/interfaces.go
+++ b/backend/internal/features/databases/interfaces.go
@@ -14,10 +14,10 @@ type DatabaseConnector interface {
TestConnection(logger *slog.Logger) error
}
-type DatabaseStorageChangeListener interface {
- OnBeforeDbStorageChange(dbID uuid.UUID, storageID uuid.UUID) error
-}
-
type DatabaseCreationListener interface {
OnDatabaseCreated(databaseID uuid.UUID)
}
+
+type DatabaseRemoveListener interface {
+ OnBeforeDatabaseRemove(databaseID uuid.UUID) error
+}
diff --git a/backend/internal/features/databases/model.go b/backend/internal/features/databases/model.go
index 2c3297d3..89fca798 100644
--- a/backend/internal/features/databases/model.go
+++ b/backend/internal/features/databases/model.go
@@ -4,34 +4,21 @@ import (
"errors"
"log/slog"
"postgresus-backend/internal/features/databases/databases/postgresql"
- "postgresus-backend/internal/features/intervals"
"postgresus-backend/internal/features/notifiers"
- "postgresus-backend/internal/features/storages"
- "strings"
"time"
"github.com/google/uuid"
- "gorm.io/gorm"
)
type Database struct {
- ID uuid.UUID `json:"id" gorm:"column:id;primaryKey;type:uuid;default:gen_random_uuid()"`
- UserID uuid.UUID `json:"userId" gorm:"column:user_id;type:uuid;not null"`
- Name string `json:"name" gorm:"column:name;type:text;not null"`
- Type DatabaseType `json:"type" gorm:"column:type;type:text;not null"`
- StorePeriod Period `json:"storePeriod" gorm:"column:store_period;type:text;not null"`
-
- BackupIntervalID uuid.UUID `json:"backupIntervalId" gorm:"column:backup_interval_id;type:uuid;not null"`
- BackupInterval *intervals.Interval `json:"backupInterval,omitempty" gorm:"foreignKey:BackupIntervalID"`
+ ID uuid.UUID `json:"id" gorm:"column:id;primaryKey;type:uuid;default:gen_random_uuid()"`
+ UserID uuid.UUID `json:"userId" gorm:"column:user_id;type:uuid;not null"`
+ Name string `json:"name" gorm:"column:name;type:text;not null"`
+ Type DatabaseType `json:"type" gorm:"column:type;type:text;not null"`
Postgresql *postgresql.PostgresqlDatabase `json:"postgresql,omitempty" gorm:"foreignKey:DatabaseID"`
- Storage storages.Storage `json:"storage" gorm:"foreignKey:StorageID"`
- StorageID uuid.UUID `json:"storageId" gorm:"column:storage_id;type:uuid;not null"`
-
- Notifiers []notifiers.Notifier `json:"notifiers" gorm:"many2many:database_notifiers;"`
- SendNotificationsOn []BackupNotificationType `json:"sendNotificationsOn" gorm:"-"`
- SendNotificationsOnString string `json:"-" gorm:"column:send_notifications_on;type:text;not null"`
+ Notifiers []notifiers.Notifier `json:"notifiers" gorm:"many2many:database_notifiers;"`
// these fields are not reliable, but
// they are used for pretty UI
@@ -41,56 +28,11 @@ type Database struct {
HealthStatus *HealthStatus `json:"healthStatus" gorm:"column:health_status;type:text;not null"`
}
-func (d *Database) BeforeSave(tx *gorm.DB) error {
- // Convert SendNotificationsOn array to string
- if len(d.SendNotificationsOn) > 0 {
- notificationTypes := make([]string, len(d.SendNotificationsOn))
-
- for i, notificationType := range d.SendNotificationsOn {
- notificationTypes[i] = string(notificationType)
- }
-
- d.SendNotificationsOnString = strings.Join(notificationTypes, ",")
- } else {
- d.SendNotificationsOnString = ""
- }
-
- return nil
-}
-
-func (d *Database) AfterFind(tx *gorm.DB) error {
- // Convert SendNotificationsOnString to array
- if d.SendNotificationsOnString != "" {
- notificationTypes := strings.Split(d.SendNotificationsOnString, ",")
- d.SendNotificationsOn = make([]BackupNotificationType, len(notificationTypes))
- for i, notificationType := range notificationTypes {
- d.SendNotificationsOn[i] = BackupNotificationType(notificationType)
- }
- } else {
- d.SendNotificationsOn = []BackupNotificationType{}
- }
-
- return nil
-}
-
func (d *Database) Validate() error {
if d.Name == "" {
return errors.New("name is required")
}
- // Backup interval is required either as ID or as object
- if d.BackupIntervalID == uuid.Nil && d.BackupInterval == nil {
- return errors.New("backup interval is required")
- }
-
- if d.StorePeriod == "" {
- return errors.New("store period is required")
- }
-
- if d.Postgresql.CpuCount == 0 {
- return errors.New("cpu count is required")
- }
-
switch d.Type {
case DatabaseTypePostgres:
return d.Postgresql.Validate()
diff --git a/backend/internal/features/databases/repository.go b/backend/internal/features/databases/repository.go
index 2cef2909..7cd827df 100644
--- a/backend/internal/features/databases/repository.go
+++ b/backend/internal/features/databases/repository.go
@@ -18,25 +18,7 @@ func (r *DatabaseRepository) Save(database *Database) (*Database, error) {
database.ID = uuid.New()
}
- database.StorageID = database.Storage.ID
-
err := db.Transaction(func(tx *gorm.DB) error {
- if database.BackupInterval != nil {
- if database.BackupInterval.ID == uuid.Nil {
- if err := tx.Create(database.BackupInterval).Error; err != nil {
- return err
- }
-
- database.BackupIntervalID = database.BackupInterval.ID
- } else {
- if err := tx.Save(database.BackupInterval).Error; err != nil {
- return err
- }
-
- database.BackupIntervalID = database.BackupInterval.ID
- }
- }
-
switch database.Type {
case DatabaseTypePostgres:
if database.Postgresql != nil {
@@ -46,13 +28,13 @@ func (r *DatabaseRepository) Save(database *Database) (*Database, error) {
if isNew {
if err := tx.Create(database).
- Omit("Postgresql", "Storage", "Notifiers", "BackupInterval").
+ Omit("Postgresql", "Notifiers").
Error; err != nil {
return err
}
} else {
if err := tx.Save(database).
- Omit("Postgresql", "Storage", "Notifiers", "BackupInterval").
+ Omit("Postgresql", "Notifiers").
Error; err != nil {
return err
}
@@ -76,7 +58,10 @@ func (r *DatabaseRepository) Save(database *Database) (*Database, error) {
}
}
- if err := tx.Model(database).Association("Notifiers").Replace(database.Notifiers); err != nil {
+ if err := tx.
+ Model(database).
+ Association("Notifiers").
+ Replace(database.Notifiers); err != nil {
return err
}
@@ -95,9 +80,7 @@ func (r *DatabaseRepository) FindByID(id uuid.UUID) (*Database, error) {
if err := storage.
GetDb().
- Preload("BackupInterval").
Preload("Postgresql").
- Preload("Storage").
Preload("Notifiers").
Where("id = ?", id).
First(&database).Error; err != nil {
@@ -112,9 +95,7 @@ func (r *DatabaseRepository) FindByUserID(userID uuid.UUID) ([]*Database, error)
if err := storage.
GetDb().
- Preload("BackupInterval").
Preload("Postgresql").
- Preload("Storage").
Preload("Notifiers").
Where("user_id = ?", userID).
Order("CASE WHEN health_status = 'UNAVAILABLE' THEN 1 WHEN health_status = 'AVAILABLE' THEN 2 WHEN health_status IS NULL THEN 3 ELSE 4 END, name ASC").
@@ -140,7 +121,9 @@ func (r *DatabaseRepository) Delete(id uuid.UUID) error {
switch database.Type {
case DatabaseTypePostgres:
- if err := tx.Where("database_id = ?", id).Delete(&postgresql.PostgresqlDatabase{}).Error; err != nil {
+ if err := tx.
+ Where("database_id = ?", id).
+ Delete(&postgresql.PostgresqlDatabase{}).Error; err != nil {
return err
}
}
@@ -167,28 +150,12 @@ func (r *DatabaseRepository) IsNotifierUsing(notifierID uuid.UUID) (bool, error)
return count > 0, nil
}
-func (r *DatabaseRepository) IsStorageUsing(storageID uuid.UUID) (bool, error) {
- var count int64
-
- if err := storage.
- GetDb().
- Table("databases").
- Where("storage_id = ?", storageID).
- Count(&count).Error; err != nil {
- return false, err
- }
-
- return count > 0, nil
-}
-
func (r *DatabaseRepository) GetAllDatabases() ([]*Database, error) {
var databases []*Database
if err := storage.
GetDb().
- Preload("BackupInterval").
Preload("Postgresql").
- Preload("Storage").
Preload("Notifiers").
Find(&databases).Error; err != nil {
return nil, err
diff --git a/backend/internal/features/databases/service.go b/backend/internal/features/databases/service.go
index 8d42226f..c0696705 100644
--- a/backend/internal/features/databases/service.go
+++ b/backend/internal/features/databases/service.go
@@ -15,14 +15,8 @@ type DatabaseService struct {
notifierService *notifiers.NotifierService
logger *slog.Logger
- dbStorageChangeListener DatabaseStorageChangeListener
- dbCreationListener []DatabaseCreationListener
-}
-
-func (s *DatabaseService) SetDatabaseStorageChangeListener(
- dbStorageChangeListener DatabaseStorageChangeListener,
-) {
- s.dbStorageChangeListener = dbStorageChangeListener
+ dbCreationListener []DatabaseCreationListener
+ dbRemoveListener []DatabaseRemoveListener
}
func (s *DatabaseService) AddDbCreationListener(
@@ -31,26 +25,32 @@ func (s *DatabaseService) AddDbCreationListener(
s.dbCreationListener = append(s.dbCreationListener, dbCreationListener)
}
+func (s *DatabaseService) AddDbRemoveListener(
+ dbRemoveListener DatabaseRemoveListener,
+) {
+ s.dbRemoveListener = append(s.dbRemoveListener, dbRemoveListener)
+}
+
func (s *DatabaseService) CreateDatabase(
user *users_models.User,
database *Database,
-) error {
+) (*Database, error) {
database.UserID = user.ID
if err := database.Validate(); err != nil {
- return err
+ return nil, err
}
database, err := s.dbRepository.Save(database)
if err != nil {
- return err
+ return nil, err
}
for _, listener := range s.dbCreationListener {
listener.OnDatabaseCreated(database.ID)
}
- return nil
+ return database, nil
}
func (s *DatabaseService) UpdateDatabase(
@@ -79,17 +79,6 @@ func (s *DatabaseService) UpdateDatabase(
return err
}
- if existingDatabase.Storage.ID != database.Storage.ID {
- err := s.dbStorageChangeListener.OnBeforeDbStorageChange(
- existingDatabase.ID,
- database.StorageID,
- )
-
- if err != nil {
- return err
- }
- }
-
_, err = s.dbRepository.Save(database)
if err != nil {
return err
@@ -111,6 +100,12 @@ func (s *DatabaseService) DeleteDatabase(
return errors.New("you have not access to this database")
}
+ for _, listener := range s.dbRemoveListener {
+ if err := listener.OnBeforeDatabaseRemove(id); err != nil {
+ return err
+ }
+ }
+
return s.dbRepository.Delete(id)
}
@@ -136,12 +131,16 @@ func (s *DatabaseService) GetDatabasesByUser(
return s.dbRepository.FindByUserID(user.ID)
}
-func (s *DatabaseService) IsNotifierUsing(notifierID uuid.UUID) (bool, error) {
- return s.dbRepository.IsNotifierUsing(notifierID)
-}
+func (s *DatabaseService) IsNotifierUsing(
+ user *users_models.User,
+ notifierID uuid.UUID,
+) (bool, error) {
+ _, err := s.notifierService.GetNotifier(user, notifierID)
+ if err != nil {
+ return false, err
+ }
-func (s *DatabaseService) IsStorageUsing(storageID uuid.UUID) (bool, error) {
- return s.dbRepository.IsStorageUsing(storageID)
+ return s.dbRepository.IsNotifierUsing(notifierID)
}
func (s *DatabaseService) TestDatabaseConnection(
diff --git a/backend/internal/features/databases/testing.go b/backend/internal/features/databases/testing.go
index 44016942..5c767e43 100644
--- a/backend/internal/features/databases/testing.go
+++ b/backend/internal/features/databases/testing.go
@@ -2,7 +2,6 @@ package databases
import (
"postgresus-backend/internal/features/databases/databases/postgresql"
- "postgresus-backend/internal/features/intervals"
"postgresus-backend/internal/features/notifiers"
"postgresus-backend/internal/features/storages"
"postgresus-backend/internal/util/tools"
@@ -15,18 +14,10 @@ func CreateTestDatabase(
storage *storages.Storage,
notifier *notifiers.Notifier,
) *Database {
- timeOfDay := "16:00"
-
database := &Database{
- UserID: userID,
- Name: "test " + uuid.New().String(),
- Type: DatabaseTypePostgres,
- StorePeriod: PeriodDay,
-
- BackupInterval: &intervals.Interval{
- Interval: intervals.IntervalDaily,
- TimeOfDay: &timeOfDay,
- },
+ UserID: userID,
+ Name: "test " + uuid.New().String(),
+ Type: DatabaseTypePostgres,
Postgresql: &postgresql.PostgresqlDatabase{
Version: tools.PostgresqlVersion16,
@@ -36,16 +27,9 @@ func CreateTestDatabase(
Password: "postgres",
},
- StorageID: storage.ID,
- Storage: *storage,
-
Notifiers: []notifiers.Notifier{
*notifier,
},
- SendNotificationsOn: []BackupNotificationType{
- NotificationBackupFailed,
- NotificationBackupSuccess,
- },
}
database, err := databaseRepository.Save(database)
diff --git a/backend/internal/features/healthcheck/attempt/check_pg_health_uc.go b/backend/internal/features/healthcheck/attempt/check_pg_health_uc.go
index 47d3ff8e..692a1af2 100644
--- a/backend/internal/features/healthcheck/attempt/check_pg_health_uc.go
+++ b/backend/internal/features/healthcheck/attempt/check_pg_health_uc.go
@@ -83,7 +83,6 @@ func (uc *CheckPgHealthUseCase) updateDatabaseHealthStatusIfChanged(
heathcheckAttempt *HealthcheckAttempt,
) error {
if &heathcheckAttempt.Status == database.HealthStatus {
- fmt.Println("Database health status is the same as the attempt status")
return nil
}
@@ -226,7 +225,7 @@ func (uc *CheckPgHealthUseCase) sendDbStatusNotification(
if newHealthStatus == databases.HealthStatusAvailable {
messageTitle = fmt.Sprintf("✅ [%s] DB is back online", database.Name)
- messageBody = fmt.Sprintf("✅ [%s] DB is back online after being unavailable", database.Name)
+ messageBody = fmt.Sprintf("✅ [%s] DB is back online", database.Name)
} else {
messageTitle = fmt.Sprintf("❌ [%s] DB is unavailable", database.Name)
messageBody = fmt.Sprintf("❌ [%s] DB is currently unavailable", database.Name)
diff --git a/backend/internal/features/healthcheck/attempt/check_pg_health_uc_test.go b/backend/internal/features/healthcheck/attempt/check_pg_health_uc_test.go
index c01130ba..66af447c 100644
--- a/backend/internal/features/healthcheck/attempt/check_pg_health_uc_test.go
+++ b/backend/internal/features/healthcheck/attempt/check_pg_health_uc_test.go
@@ -85,8 +85,8 @@ func Test_CheckPgHealthUseCase(t *testing.T) {
t,
"SendNotification",
mock.Anything,
- fmt.Sprintf("❌ DB [%s] is unavailable", database.Name),
- fmt.Sprintf("❌ The [%s] database is currently unavailable", database.Name),
+ fmt.Sprintf("❌ [%s] DB is unavailable", database.Name),
+ fmt.Sprintf("❌ [%s] DB is currently unavailable", database.Name),
)
})
@@ -150,8 +150,8 @@ func Test_CheckPgHealthUseCase(t *testing.T) {
t,
"SendNotification",
mock.Anything,
- fmt.Sprintf("❌ DB [%s] is unavailable", database.Name),
- fmt.Sprintf("❌ The [%s] database is currently unavailable", database.Name),
+ fmt.Sprintf("❌ [%s] DB is unavailable", database.Name),
+ fmt.Sprintf("❌ [%s] DB is currently unavailable", database.Name),
)
},
)
@@ -230,7 +230,7 @@ func Test_CheckPgHealthUseCase(t *testing.T) {
"SendNotification",
mock.Anything,
fmt.Sprintf("❌ [%s] DB is unavailable", database.Name),
- fmt.Sprintf("❌ [%s] Database is currently unavailable", database.Name),
+ fmt.Sprintf("❌ [%s] DB is currently unavailable", database.Name),
)
},
)
@@ -302,8 +302,8 @@ func Test_CheckPgHealthUseCase(t *testing.T) {
t,
"SendNotification",
mock.Anything,
- fmt.Sprintf("✅ DB [%s] is back online", database.Name),
- fmt.Sprintf("✅ The [%s] database is back online after being unavailable", database.Name),
+ fmt.Sprintf("✅ [%s] DB is back online", database.Name),
+ fmt.Sprintf("✅ [%s] DB is back online", database.Name),
)
})
diff --git a/backend/internal/features/restores/di.go b/backend/internal/features/restores/di.go
index fb3e5768..d107fe8f 100644
--- a/backend/internal/features/restores/di.go
+++ b/backend/internal/features/restores/di.go
@@ -1,7 +1,8 @@
package restores
import (
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/restores/usecases"
"postgresus-backend/internal/features/storages"
"postgresus-backend/internal/features/users"
@@ -13,6 +14,7 @@ var restoreService = &RestoreService{
backups.GetBackupService(),
restoreRepository,
storages.GetStorageService(),
+ backups_config.GetBackupConfigService(),
usecases.GetRestoreBackupUsecase(),
logger.GetLogger(),
}
@@ -33,3 +35,7 @@ func GetRestoreController() *RestoreController {
func GetRestoreBackgroundService() *RestoreBackgroundService {
return restoreBackgroundService
}
+
+func SetupDependencies() {
+ backups.GetBackupService().AddBackupRemoveListener(restoreService)
+}
diff --git a/backend/internal/features/restores/models/model.go b/backend/internal/features/restores/models/model.go
index 529236e1..acaf46bc 100644
--- a/backend/internal/features/restores/models/model.go
+++ b/backend/internal/features/restores/models/model.go
@@ -1,7 +1,7 @@
package models
import (
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
"postgresus-backend/internal/features/databases/databases/postgresql"
"postgresus-backend/internal/features/restores/enums"
"time"
diff --git a/backend/internal/features/restores/service.go b/backend/internal/features/restores/service.go
index 55e51a4d..cb08b6fa 100644
--- a/backend/internal/features/restores/service.go
+++ b/backend/internal/features/restores/service.go
@@ -3,7 +3,8 @@ package restores
import (
"errors"
"log/slog"
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/restores/enums"
"postgresus-backend/internal/features/restores/models"
@@ -19,10 +20,32 @@ type RestoreService struct {
backupService *backups.BackupService
restoreRepository *RestoreRepository
storageService *storages.StorageService
+ backupConfigService *backups_config.BackupConfigService
restoreBackupUsecase *usecases.RestoreBackupUsecase
logger *slog.Logger
}
+func (s *RestoreService) OnBeforeBackupRemove(backup *backups.Backup) error {
+ restores, err := s.restoreRepository.FindByBackupID(backup.ID)
+ if err != nil {
+ return err
+ }
+
+ for _, restore := range restores {
+ if restore.Status == enums.RestoreStatusInProgress {
+ return errors.New("restore is in progress, backup cannot be removed")
+ }
+ }
+
+ for _, restore := range restores {
+ if err := s.restoreRepository.DeleteByID(restore.ID); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
func (s *RestoreService) GetRestores(
user *users_models.User,
backupID uuid.UUID,
@@ -110,9 +133,17 @@ func (s *RestoreService) RestoreBackup(
return err
}
+ backupConfig, err := s.backupConfigService.GetBackupConfigByDbId(
+ backup.Database.ID,
+ )
+ if err != nil {
+ return err
+ }
+
start := time.Now().UTC()
err = s.restoreBackupUsecase.Execute(
+ backupConfig,
restore,
backup,
storage,
diff --git a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
index 928169b2..78e2603a 100644
--- a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
+++ b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
@@ -14,7 +14,8 @@ import (
"time"
"postgresus-backend/internal/config"
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
pgtypes "postgresus-backend/internal/features/databases/databases/postgresql"
"postgresus-backend/internal/features/restores/models"
@@ -29,6 +30,7 @@ type RestorePostgresqlBackupUsecase struct {
}
func (uc *RestorePostgresqlBackupUsecase) Execute(
+ backupConfig *backups_config.BackupConfig,
restore models.Restore,
backup *backups.Backup,
storage *storages.Storage,
@@ -56,7 +58,7 @@ func (uc *RestorePostgresqlBackupUsecase) Execute(
// Use parallel jobs based on CPU count (same as backup)
// Cap between 1 and 8 to avoid overwhelming the server
- parallelJobs := max(1, min(pg.CpuCount, 8))
+ parallelJobs := max(1, min(backupConfig.CpuCount, 8))
args := []string{
"-Fc", // expect custom format (same as backup)
diff --git a/backend/internal/features/restores/usecases/restore_backup_uc.go b/backend/internal/features/restores/usecases/restore_backup_uc.go
index 046c47f8..b9408788 100644
--- a/backend/internal/features/restores/usecases/restore_backup_uc.go
+++ b/backend/internal/features/restores/usecases/restore_backup_uc.go
@@ -2,7 +2,8 @@ package usecases
import (
"errors"
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
"postgresus-backend/internal/features/restores/models"
usecases_postgresql "postgresus-backend/internal/features/restores/usecases/postgresql"
@@ -14,12 +15,18 @@ type RestoreBackupUsecase struct {
}
func (uc *RestoreBackupUsecase) Execute(
+ backupConfig *backups_config.BackupConfig,
restore models.Restore,
backup *backups.Backup,
storage *storages.Storage,
) error {
if restore.Backup.Database.Type == databases.DatabaseTypePostgres {
- return uc.restorePostgresqlBackupUsecase.Execute(restore, backup, storage)
+ return uc.restorePostgresqlBackupUsecase.Execute(
+ backupConfig,
+ restore,
+ backup,
+ storage,
+ )
}
return errors.New("database type not supported")
diff --git a/backend/internal/features/storages/models/google_drive/model.go b/backend/internal/features/storages/models/google_drive/model.go
index 553ae8e8..b0c3ad1a 100644
--- a/backend/internal/features/storages/models/google_drive/model.go
+++ b/backend/internal/features/storages/models/google_drive/model.go
@@ -38,17 +38,32 @@ func (s *GoogleDriveStorage) SaveFile(
ctx := context.Background()
filename := fileID.String()
+ // Ensure the postgresus_backups folder exists
+ folderID, err := s.ensureBackupsFolderExists(ctx, driveService)
+ if err != nil {
+ return fmt.Errorf("failed to create/find backups folder: %w", err)
+ }
+
// Delete any previous copy so we keep at most one object per logical file.
- _ = s.deleteByName(ctx, driveService, filename) // ignore "not found"
+ _ = s.deleteByName(ctx, driveService, filename, folderID) // ignore "not found"
- fileMeta := &drive.File{Name: filename}
+ fileMeta := &drive.File{
+ Name: filename,
+ Parents: []string{folderID},
+ }
- _, err := driveService.Files.Create(fileMeta).Media(file).Context(ctx).Do()
+ _, err = driveService.Files.Create(fileMeta).Media(file).Context(ctx).Do()
if err != nil {
return fmt.Errorf("failed to upload file to Google Drive: %w", err)
}
- logger.Info("file uploaded to Google Drive", "name", filename)
+ logger.Info(
+ "file uploaded to Google Drive",
+ "name",
+ filename,
+ "folder",
+ "postgresus_backups",
+ )
return nil
})
}
@@ -56,7 +71,12 @@ func (s *GoogleDriveStorage) SaveFile(
func (s *GoogleDriveStorage) GetFile(fileID uuid.UUID) (io.ReadCloser, error) {
var result io.ReadCloser
err := s.withRetryOnAuth(func(driveService *drive.Service) error {
- fileIDGoogle, err := s.lookupFileID(driveService, fileID.String())
+ folderID, err := s.findBackupsFolder(driveService)
+ if err != nil {
+ return fmt.Errorf("failed to find backups folder: %w", err)
+ }
+
+ fileIDGoogle, err := s.lookupFileID(driveService, fileID.String(), folderID)
if err != nil {
return err
}
@@ -76,7 +96,12 @@ func (s *GoogleDriveStorage) GetFile(fileID uuid.UUID) (io.ReadCloser, error) {
func (s *GoogleDriveStorage) DeleteFile(fileID uuid.UUID) error {
return s.withRetryOnAuth(func(driveService *drive.Service) error {
ctx := context.Background()
- return s.deleteByName(ctx, driveService, fileID.String())
+ folderID, err := s.findBackupsFolder(driveService)
+ if err != nil {
+ return fmt.Errorf("failed to find backups folder: %w", err)
+ }
+
+ return s.deleteByName(ctx, driveService, fileID.String(), folderID)
})
}
@@ -109,8 +134,17 @@ func (s *GoogleDriveStorage) TestConnection() error {
testFilename := "test-connection-" + uuid.New().String()
testData := []byte("test")
+ // Ensure the postgresus_backups folder exists
+ folderID, err := s.ensureBackupsFolderExists(ctx, driveService)
+ if err != nil {
+ return fmt.Errorf("failed to create/find backups folder: %w", err)
+ }
+
// Test write operation
- fileMeta := &drive.File{Name: testFilename}
+ fileMeta := &drive.File{
+ Name: testFilename,
+ Parents: []string{folderID},
+ }
file, err := driveService.Files.Create(fileMeta).
Media(strings.NewReader(string(testData))).
Context(ctx).
@@ -358,8 +392,13 @@ func (s *GoogleDriveStorage) getDriveService() (*drive.Service, error) {
func (s *GoogleDriveStorage) lookupFileID(
driveService *drive.Service,
name string,
+ folderID string,
) (string, error) {
- query := fmt.Sprintf("name = '%s' and trashed = false", escapeForQuery(name))
+ query := fmt.Sprintf(
+ "name = '%s' and trashed = false and '%s' in parents",
+ escapeForQuery(name),
+ folderID,
+ )
results, err := driveService.Files.List().
Q(query).
@@ -371,7 +410,7 @@ func (s *GoogleDriveStorage) lookupFileID(
}
if len(results.Files) == 0 {
- return "", fmt.Errorf("file %q not found in Google Drive", name)
+ return "", fmt.Errorf("file %q not found in Google Drive backups folder", name)
}
return results.Files[0].Id, nil
@@ -381,8 +420,13 @@ func (s *GoogleDriveStorage) deleteByName(
ctx context.Context,
driveService *drive.Service,
name string,
+ folderID string,
) error {
- query := fmt.Sprintf("name = '%s' and trashed = false", escapeForQuery(name))
+ query := fmt.Sprintf(
+ "name = '%s' and trashed = false and '%s' in parents",
+ escapeForQuery(name),
+ folderID,
+ )
err := driveService.
Files.
@@ -409,3 +453,47 @@ func (s *GoogleDriveStorage) deleteByName(
func escapeForQuery(s string) string {
return strings.ReplaceAll(s, `'`, `\'`)
}
+
+// ensureBackupsFolderExists creates the postgresus_backups folder if it doesn't exist
+func (s *GoogleDriveStorage) ensureBackupsFolderExists(
+ ctx context.Context,
+ driveService *drive.Service,
+) (string, error) {
+ folderID, err := s.findBackupsFolder(driveService)
+ if err == nil {
+ return folderID, nil
+ }
+
+ // Folder doesn't exist, create it
+ folderMeta := &drive.File{
+ Name: "postgresus_backups",
+ MimeType: "application/vnd.google-apps.folder",
+ }
+
+ folder, err := driveService.Files.Create(folderMeta).Context(ctx).Do()
+ if err != nil {
+ return "", fmt.Errorf("failed to create postgresus_backups folder: %w", err)
+ }
+
+ return folder.Id, nil
+}
+
+// findBackupsFolder finds the postgresus_backups folder ID
+func (s *GoogleDriveStorage) findBackupsFolder(driveService *drive.Service) (string, error) {
+ query := "name = 'postgresus_backups' and mimeType = 'application/vnd.google-apps.folder' and trashed = false"
+
+ results, err := driveService.Files.List().
+ Q(query).
+ Fields("files(id)").
+ PageSize(1).
+ Do()
+ if err != nil {
+ return "", fmt.Errorf("failed to search for backups folder: %w", err)
+ }
+
+ if len(results.Files) == 0 {
+ return "", fmt.Errorf("postgresus_backups folder not found")
+ }
+
+ return results.Files[0].Id, nil
+}
diff --git a/backend/internal/features/system/healthcheck/di.go b/backend/internal/features/system/healthcheck/di.go
index df93993e..48aaa003 100644
--- a/backend/internal/features/system/healthcheck/di.go
+++ b/backend/internal/features/system/healthcheck/di.go
@@ -1,7 +1,7 @@
package system_healthcheck
import (
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
"postgresus-backend/internal/features/disk"
)
diff --git a/backend/internal/features/system/healthcheck/service.go b/backend/internal/features/system/healthcheck/service.go
index 87a29fdf..5f4baf22 100644
--- a/backend/internal/features/system/healthcheck/service.go
+++ b/backend/internal/features/system/healthcheck/service.go
@@ -2,7 +2,7 @@ package system_healthcheck
import (
"errors"
- "postgresus-backend/internal/features/backups"
+ "postgresus-backend/internal/features/backups/backups"
"postgresus-backend/internal/features/disk"
"postgresus-backend/internal/storage"
)
diff --git a/backend/internal/features/tests/postgresql_backup_restore_test.go b/backend/internal/features/tests/postgresql_backup_restore_test.go
index 922fcaf6..14544a95 100644
--- a/backend/internal/features/tests/postgresql_backup_restore_test.go
+++ b/backend/internal/features/tests/postgresql_backup_restore_test.go
@@ -5,14 +5,17 @@ import (
"os"
"path/filepath"
"postgresus-backend/internal/config"
- "postgresus-backend/internal/features/backups"
- usecases_postgresql_backup "postgresus-backend/internal/features/backups/usecases/postgresql"
+ "postgresus-backend/internal/features/backups/backups"
+ usecases_postgresql_backup "postgresus-backend/internal/features/backups/backups/usecases/postgresql"
+ backups_config "postgresus-backend/internal/features/backups/config"
"postgresus-backend/internal/features/databases"
pgtypes "postgresus-backend/internal/features/databases/databases/postgresql"
+ "postgresus-backend/internal/features/intervals"
"postgresus-backend/internal/features/restores/models"
usecases_postgresql_restore "postgresus-backend/internal/features/restores/usecases/postgresql"
"postgresus-backend/internal/features/storages"
local_storage "postgresus-backend/internal/features/storages/models/local"
+ "postgresus-backend/internal/util/period"
"postgresus-backend/internal/util/tools"
"strconv"
"testing"
@@ -99,7 +102,7 @@ func testBackupRestoreForVersion(t *testing.T, pgVersion string, port string) {
backupID := uuid.New()
pgVersionEnum := tools.GetPostgresqlVersionEnum(pgVersion)
- backupDbConfig := &databases.Database{
+ backupDb := &databases.Database{
ID: uuid.New(),
Type: databases.DatabaseTypePostgres,
Name: "Test Database",
@@ -111,10 +114,19 @@ func testBackupRestoreForVersion(t *testing.T, pgVersion string, port string) {
Password: container.Password,
Database: &container.Database,
IsHttps: false,
- CpuCount: 1,
},
}
+ storageID := uuid.New()
+ backupConfig := &backups_config.BackupConfig{
+ DatabaseID: backupDb.ID,
+ IsBackupsEnabled: true,
+ StorePeriod: period.PeriodDay,
+ BackupInterval: &intervals.Interval{Interval: intervals.IntervalDaily},
+ StorageID: &storageID,
+ CpuCount: 1,
+ }
+
storage := &storages.Storage{
UserID: uuid.New(),
Type: storages.StorageTypeLocal,
@@ -126,7 +138,8 @@ func testBackupRestoreForVersion(t *testing.T, pgVersion string, port string) {
progressTracker := func(completedMBs float64) {}
err = usecases_postgresql_backup.GetCreatePostgresqlBackupUsecase().Execute(
backupID,
- backupDbConfig,
+ backupConfig,
+ backupDb,
storage,
progressTracker,
)
@@ -150,12 +163,12 @@ func testBackupRestoreForVersion(t *testing.T, pgVersion string, port string) {
// Setup data for restore
completedBackup := &backups.Backup{
ID: backupID,
- DatabaseID: backupDbConfig.ID,
+ DatabaseID: backupDb.ID,
StorageID: storage.ID,
Status: backups.BackupStatusCompleted,
CreatedAt: time.Now().UTC(),
Storage: storage,
- Database: backupDbConfig,
+ Database: backupDb,
}
restoreID := uuid.New()
@@ -170,13 +183,12 @@ func testBackupRestoreForVersion(t *testing.T, pgVersion string, port string) {
Password: container.Password,
Database: &newDBName,
IsHttps: false,
- CpuCount: 1,
},
}
// Restore the backup
restoreBackupUC := usecases_postgresql_restore.GetRestorePostgresqlBackupUsecase()
- err = restoreBackupUC.Execute(restore, completedBackup, storage)
+ err = restoreBackupUC.Execute(backupConfig, restore, completedBackup, storage)
assert.NoError(t, err)
// Verify restored table exists
diff --git a/backend/internal/util/period/enums.go b/backend/internal/util/period/enums.go
new file mode 100644
index 00000000..e9ebfd4e
--- /dev/null
+++ b/backend/internal/util/period/enums.go
@@ -0,0 +1,49 @@
+package period
+
+import "time"
+
+type Period string
+
+const (
+ PeriodDay Period = "DAY"
+ PeriodWeek Period = "WEEK"
+ PeriodMonth Period = "MONTH"
+ Period3Month Period = "3_MONTH"
+ Period6Month Period = "6_MONTH"
+ PeriodYear Period = "YEAR"
+ Period2Years Period = "2_YEARS"
+ Period3Years Period = "3_YEARS"
+ Period4Years Period = "4_YEARS"
+ Period5Years Period = "5_YEARS"
+ PeriodForever Period = "FOREVER"
+)
+
+// ToDuration converts Period to time.Duration
+func (p Period) ToDuration() time.Duration {
+ switch p {
+ case PeriodDay:
+ return 24 * time.Hour
+ case PeriodWeek:
+ return 7 * 24 * time.Hour
+ case PeriodMonth:
+ return 30 * 24 * time.Hour
+ case Period3Month:
+ return 90 * 24 * time.Hour
+ case Period6Month:
+ return 180 * 24 * time.Hour
+ case PeriodYear:
+ return 365 * 24 * time.Hour
+ case Period2Years:
+ return 2 * 365 * 24 * time.Hour
+ case Period3Years:
+ return 3 * 365 * 24 * time.Hour
+ case Period4Years:
+ return 4 * 365 * 24 * time.Hour
+ case Period5Years:
+ return 5 * 365 * 24 * time.Hour
+ case PeriodForever:
+ return 0
+ default:
+ panic("unknown period: " + string(p))
+ }
+}
diff --git a/backend/migrations/20250710122028_create_backup_config.sql b/backend/migrations/20250710122028_create_backup_config.sql
new file mode 100644
index 00000000..120147f9
--- /dev/null
+++ b/backend/migrations/20250710122028_create_backup_config.sql
@@ -0,0 +1,94 @@
+-- +goose Up
+-- +goose StatementBegin
+
+-- Create backup_configs table
+CREATE TABLE backup_configs (
+ database_id UUID PRIMARY KEY,
+ is_backups_enabled BOOLEAN NOT NULL DEFAULT FALSE,
+ store_period TEXT NOT NULL,
+ backup_interval_id UUID NOT NULL,
+ storage_id UUID,
+ send_notifications_on TEXT NOT NULL,
+ cpu_count INT NOT NULL DEFAULT 1
+);
+
+-- Add foreign key constraint
+ALTER TABLE backup_configs
+ ADD CONSTRAINT fk_backup_config_database_id
+ FOREIGN KEY (database_id)
+ REFERENCES databases (id)
+ ON DELETE CASCADE;
+
+ALTER TABLE backup_configs
+ ADD CONSTRAINT fk_backup_config_backup_interval_id
+ FOREIGN KEY (backup_interval_id)
+ REFERENCES intervals (id);
+
+ALTER TABLE backup_configs
+ ADD CONSTRAINT fk_backup_config_storage_id
+ FOREIGN KEY (storage_id)
+ REFERENCES storages (id);
+
+-- Migrate data from databases table to backup_configs table
+INSERT INTO backup_configs (
+ database_id,
+ is_backups_enabled,
+ store_period,
+ backup_interval_id,
+ storage_id,
+ send_notifications_on,
+ cpu_count
+)
+SELECT
+ d.id,
+ TRUE,
+ d.store_period,
+ d.backup_interval_id,
+ d.storage_id,
+ d.send_notifications_on,
+ COALESCE(p.cpu_count, 1)
+FROM databases d
+LEFT JOIN postgresql_databases p ON d.id = p.database_id;
+
+-- Remove backup-related columns from databases table
+ALTER TABLE databases DROP COLUMN store_period;
+ALTER TABLE databases DROP COLUMN backup_interval_id;
+ALTER TABLE databases DROP COLUMN storage_id;
+ALTER TABLE databases DROP COLUMN send_notifications_on;
+
+-- Remove cpu_count column from postgresql_databases table
+ALTER TABLE postgresql_databases DROP COLUMN cpu_count;
+
+-- +goose StatementEnd
+
+-- +goose Down
+-- +goose StatementBegin
+
+-- Re-add backup-related columns to databases table
+ALTER TABLE databases ADD COLUMN store_period TEXT;
+ALTER TABLE databases ADD COLUMN backup_interval_id UUID;
+ALTER TABLE databases ADD COLUMN storage_id UUID;
+ALTER TABLE databases ADD COLUMN send_notifications_on TEXT;
+
+-- Re-add cpu_count column to postgresql_databases table
+ALTER TABLE postgresql_databases ADD COLUMN cpu_count INT NOT NULL DEFAULT 1;
+
+-- Migrate data back from backup_configs to databases and postgresql_databases tables
+UPDATE databases d
+SET
+ store_period = bc.store_period,
+ backup_interval_id = bc.backup_interval_id,
+ storage_id = bc.storage_id,
+ send_notifications_on = bc.send_notifications_on
+FROM backup_configs bc
+WHERE d.id = bc.database_id;
+
+UPDATE postgresql_databases p
+SET cpu_count = bc.cpu_count
+FROM backup_configs bc
+WHERE p.database_id = bc.database_id;
+
+-- Drop backup_configs table
+DROP TABLE backup_configs;
+
+-- +goose StatementEnd
diff --git a/frontend/src/entity/backups/api/backupConfigApi.ts b/frontend/src/entity/backups/api/backupConfigApi.ts
new file mode 100644
index 00000000..342e156e
--- /dev/null
+++ b/frontend/src/entity/backups/api/backupConfigApi.ts
@@ -0,0 +1,35 @@
+import { getApplicationServer } from '../../../constants';
+import RequestOptions from '../../../shared/api/RequestOptions';
+import { apiHelper } from '../../../shared/api/apiHelper';
+import type { BackupConfig } from '../model/BackupConfig';
+
+export const backupConfigApi = {
+ async saveBackupConfig(config: BackupConfig) {
+ const requestOptions: RequestOptions = new RequestOptions();
+ requestOptions.setBody(JSON.stringify(config));
+ return apiHelper.fetchPostJson<BackupConfig>(
+ `${getApplicationServer()}/api/v1/backup-configs/save`,
+ requestOptions,
+ );
+ },
+
+ async getBackupConfigByDbID(databaseId: string) {
+ return apiHelper.fetchGetJson<BackupConfig>(
+ `${getApplicationServer()}/api/v1/backup-configs/database/${databaseId}`,
+ undefined,
+ true,
+ );
+ },
+
+ async isStorageUsing(storageId: string): Promise<boolean> {
+ return await apiHelper
+ .fetchGetJson<{
+ isUsing: boolean;
+ }>(
+ `${getApplicationServer()}/api/v1/backup-configs/storage/${storageId}/is-using`,
+ undefined,
+ true,
+ )
+ .then((res) => res.isUsing);
+ },
+};
diff --git a/frontend/src/entity/backups/index.ts b/frontend/src/entity/backups/index.ts
index 08e1b879..ccf3c2a6 100644
--- a/frontend/src/entity/backups/index.ts
+++ b/frontend/src/entity/backups/index.ts
@@ -1,3 +1,6 @@
export { backupsApi } from './api/backupsApi';
+export { backupConfigApi } from './api/backupConfigApi';
export { BackupStatus } from './model/BackupStatus';
export type { Backup } from './model/Backup';
+export type { BackupConfig } from './model/BackupConfig';
+export { BackupNotificationType } from './model/BackupNotificationType';
diff --git a/frontend/src/entity/backups/model/BackupConfig.ts b/frontend/src/entity/backups/model/BackupConfig.ts
new file mode 100644
index 00000000..b40a79d2
--- /dev/null
+++ b/frontend/src/entity/backups/model/BackupConfig.ts
@@ -0,0 +1,15 @@
+import type { Period } from '../../databases/model/Period';
+import type { Interval } from '../../intervals';
+import type { Storage } from '../../storages';
+import type { BackupNotificationType } from './BackupNotificationType';
+
+export interface BackupConfig {
+ databaseId: string;
+
+ isBackupsEnabled: boolean;
+ storePeriod: Period;
+ backupInterval?: Interval;
+ storage?: Storage;
+ sendNotificationsOn: BackupNotificationType[];
+ cpuCount: number;
+}
diff --git a/frontend/src/entity/backups/model/BackupNotificationType.ts b/frontend/src/entity/backups/model/BackupNotificationType.ts
new file mode 100644
index 00000000..797e4b7a
--- /dev/null
+++ b/frontend/src/entity/backups/model/BackupNotificationType.ts
@@ -0,0 +1,4 @@
+export enum BackupNotificationType {
+ BackupFailed = 'BACKUP_FAILED',
+ BackupSuccess = 'BACKUP_SUCCESS',
+}
diff --git a/frontend/src/entity/databases/api/databaseApi.ts b/frontend/src/entity/databases/api/databaseApi.ts
index 2ce5a283..1842277c 100644
--- a/frontend/src/entity/databases/api/databaseApi.ts
+++ b/frontend/src/entity/databases/api/databaseApi.ts
@@ -77,17 +77,4 @@ export const databaseApi = {
)
.then((res) => res.isUsing);
},
-
- async isStorageUsing(storageId: string): Promise<boolean> {
- const requestOptions: RequestOptions = new RequestOptions();
- return apiHelper
- .fetchGetJson<{
- isUsing: boolean;
- }>(
- `${getApplicationServer()}/api/v1/databases/storage/${storageId}/is-using`,
- requestOptions,
- true,
- )
- .then((res) => res.isUsing);
- },
};
diff --git a/frontend/src/entity/databases/model/BackupNotificationType.ts b/frontend/src/entity/databases/model/BackupNotificationType.ts
deleted file mode 100644
index 3accac7f..00000000
--- a/frontend/src/entity/databases/model/BackupNotificationType.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export enum BackupNotificationType {
- BACKUP_FAILED = 'BACKUP_FAILED',
- BACKUP_SUCCESS = 'BACKUP_SUCCESS',
-}
diff --git a/frontend/src/entity/databases/model/Database.ts b/frontend/src/entity/databases/model/Database.ts
index baa81ca4..ec7afad6 100644
--- a/frontend/src/entity/databases/model/Database.ts
+++ b/frontend/src/entity/databases/model/Database.ts
@@ -1,26 +1,16 @@
-import type { Interval } from '../../intervals';
import type { Notifier } from '../../notifiers';
-import type { BackupNotificationType } from './BackupNotificationType';
import type { DatabaseType } from './DatabaseType';
import type { HealthStatus } from './HealthStatus';
-import type { Period } from './Period';
import type { PostgresqlDatabase } from './postgresql/PostgresqlDatabase';
export interface Database {
id: string;
name: string;
-
type: DatabaseType;
- backupInterval?: Interval;
- storePeriod: Period;
-
postgresql?: PostgresqlDatabase;
- storage: Storage;
-
notifiers: Notifier[];
- sendNotificationsOn: BackupNotificationType[];
lastBackupTime?: Date;
lastBackupErrorMessage?: string;
diff --git a/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts b/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts
index 67a8ce3a..ad1f5922 100644
--- a/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts
+++ b/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts
@@ -11,6 +11,4 @@ export interface PostgresqlDatabase {
password: string;
database?: string;
isHttps: boolean;
-
- cpuCount: number;
}
diff --git a/frontend/src/features/backups/index.ts b/frontend/src/features/backups/index.ts
index d2e5630f..fac95ab5 100644
--- a/frontend/src/features/backups/index.ts
+++ b/frontend/src/features/backups/index.ts
@@ -1 +1,3 @@
export { BackupsComponent } from './ui/BackupsComponent';
+export { EditBackupConfigComponent } from './ui/EditBackupConfigComponent';
+export { ShowBackupConfigComponent } from './ui/ShowBackupConfigComponent';
diff --git a/frontend/src/features/backups/ui/BackupsComponent.tsx b/frontend/src/features/backups/ui/BackupsComponent.tsx
index 66dad592..8a5bc5ed 100644
--- a/frontend/src/features/backups/ui/BackupsComponent.tsx
+++ b/frontend/src/features/backups/ui/BackupsComponent.tsx
@@ -6,12 +6,12 @@ import {
InfoCircleOutlined,
SyncOutlined,
} from '@ant-design/icons';
-import { Button, Modal, Table, Tooltip } from 'antd';
+import { Button, Modal, Spin, Table, Tooltip } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import dayjs from 'dayjs';
import { useEffect, useRef, useState } from 'react';
-import { type Backup, BackupStatus, backupsApi } from '../../../entity/backups';
+import { type Backup, BackupStatus, backupConfigApi, backupsApi } from '../../../entity/backups';
import type { Database } from '../../../entity/databases';
import { getUserTimeFormat } from '../../../shared/time';
import { ConfirmationComponent } from '../../../shared/ui';
@@ -22,9 +22,12 @@ interface Props {
}
export const BackupsComponent = ({ database }: Props) => {
- const [isLoading, setIsLoading] = useState(false);
+ const [isBackupsLoading, setIsBackupsLoading] = useState(false);
const [backups, setBackups] = useState<Backup[]>([]);
+ const [isBackupConfigLoading, setIsBackupConfigLoading] = useState(false);
+ const [isShowBackupConfig, setIsShowBackupConfig] = useState(false);
+
const [isMakeBackupRequestLoading, setIsMakeBackupRequestLoading] = useState(false);
const [showingBackupError, setShowingBackupError] = useState<Backup | undefined>();
@@ -86,11 +89,26 @@ export const BackupsComponent = ({ database }: Props) => {
};
useEffect(() => {
- setIsLoading(true);
- loadBackups().then(() => setIsLoading(false));
+ let isBackupsEnabled = false;
+
+ setIsBackupConfigLoading(true);
+ backupConfigApi.getBackupConfigByDbID(database.id).then((backupConfig) => {
+ setIsBackupConfigLoading(false);
+
+ if (backupConfig.isBackupsEnabled) {
+ // load backups
+ isBackupsEnabled = true;
+ setIsShowBackupConfig(true);
+
+ setIsBackupsLoading(true);
+ loadBackups().then(() => setIsBackupsLoading(false));
+ }
+ });
const interval = setInterval(() => {
- loadBackups();
+ if (isBackupsEnabled) {
+ loadBackups();
+ }
}, 1_000);
return () => clearInterval(interval);
@@ -264,8 +282,20 @@ export const BackupsComponent = ({ database }: Props) => {
},
];
+ if (isBackupConfigLoading) {
+ return (
+ <div className="mb-5 flex items-center">
+ <Spin />
+ </div>
+ );
+ }
+
+ if (!isShowBackupConfig) {
+ return <div />;
+ }
+
return (
- <div>
+ <div className="mt-5 w-full rounded bg-white p-5 shadow">
<h2 className="text-xl font-bold">Backups</h2>
<div className="mt-5" />
@@ -288,7 +318,7 @@ export const BackupsComponent = ({ database }: Props) => {
columns={columns}
dataSource={backups}
rowKey="id"
- loading={isLoading}
+ loading={isBackupsLoading}
size="small"
pagination={false}
/>
diff --git a/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx b/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
new file mode 100644
index 00000000..5274a40f
--- /dev/null
+++ b/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
@@ -0,0 +1,483 @@
+import { InfoCircleOutlined } from '@ant-design/icons';
+import {
+ Button,
+ Checkbox,
+ InputNumber,
+ Modal,
+ Select,
+ Spin,
+ Switch,
+ TimePicker,
+ Tooltip,
+} from 'antd';
+import dayjs, { Dayjs } from 'dayjs';
+import { useEffect, useMemo, useState } from 'react';
+
+import { type BackupConfig, backupConfigApi } from '../../../entity/backups';
+import { BackupNotificationType } from '../../../entity/backups/model/BackupNotificationType';
+import type { Database } from '../../../entity/databases';
+import { Period } from '../../../entity/databases/model/Period';
+import { type Interval, IntervalType } from '../../../entity/intervals';
+import { type Storage, getStorageLogoFromType, storageApi } from '../../../entity/storages';
+import {
+ getLocalDayOfMonth,
+ getLocalWeekday,
+ getUserTimeFormat,
+ getUtcDayOfMonth,
+ getUtcWeekday,
+} from '../../../shared/time/utils';
+import { ConfirmationComponent } from '../../../shared/ui';
+import { EditStorageComponent } from '../../storages/ui/edit/EditStorageComponent';
+
+interface Props {
+ database: Database;
+
+ isShowBackButton: boolean;
+ onBack: () => void;
+
+ isShowCancelButton?: boolean;
+ onCancel: () => void;
+
+ saveButtonText?: string;
+ isSaveToApi: boolean;
+ onSaved: (backupConfig: BackupConfig) => void;
+}
+
+const weekdayOptions = [
+ { value: 1, label: 'Mon' },
+ { value: 2, label: 'Tue' },
+ { value: 3, label: 'Wed' },
+ { value: 4, label: 'Thu' },
+ { value: 5, label: 'Fri' },
+ { value: 6, label: 'Sat' },
+ { value: 7, label: 'Sun' },
+];
+
+export const EditBackupConfigComponent = ({
+ database,
+
+ isShowBackButton,
+ onBack,
+
+ isShowCancelButton,
+ onCancel,
+ saveButtonText,
+ isSaveToApi,
+ onSaved,
+}: Props) => {
+ const [backupConfig, setBackupConfig] = useState<BackupConfig>();
+ const [isUnsaved, setIsUnsaved] = useState(false);
+ const [isSaving, setIsSaving] = useState(false);
+
+ const [storages, setStorages] = useState<Storage[]>([]);
+ const [isStoragesLoading, setIsStoragesLoading] = useState(false);
+ const [isShowCreateStorage, setShowCreateStorage] = useState(false);
+
+ const [isShowWarn, setIsShowWarn] = useState(false);
+
+ const timeFormat = useMemo(() => {
+ const is12 = getUserTimeFormat();
+ return { use12Hours: is12, format: is12 ? 'h:mm A' : 'HH:mm' };
+ }, []);
+
+ const updateBackupConfig = (patch: Partial<BackupConfig>) => {
+ setBackupConfig((prev) => (prev ? { ...prev, ...patch } : prev));
+ setIsUnsaved(true);
+ };
+
+ const saveInterval = (patch: Partial<Interval>) => {
+ setBackupConfig((prev) => {
+ if (!prev) return prev;
+
+ const updatedBackupInterval = { ...(prev.backupInterval ?? {}), ...patch };
+
+ if (!updatedBackupInterval.id && prev.backupInterval?.id) {
+ updatedBackupInterval.id = prev.backupInterval.id;
+ }
+
+ return { ...prev, backupInterval: updatedBackupInterval as Interval };
+ });
+
+ setIsUnsaved(true);
+ };
+
+ const saveBackupConfig = async () => {
+ if (!backupConfig) return;
+
+ if (isSaveToApi) {
+ setIsSaving(true);
+ try {
+ await backupConfigApi.saveBackupConfig(backupConfig);
+ setIsUnsaved(false);
+ } catch (e) {
+ alert((e as Error).message);
+ }
+ setIsSaving(false);
+ }
+
+ onSaved(backupConfig);
+ };
+
+ const loadStorages = async () => {
+ setIsStoragesLoading(true);
+
+ try {
+ const storages = await storageApi.getStorages();
+ setStorages(storages);
+ } catch (e) {
+ alert((e as Error).message);
+ }
+
+ setIsStoragesLoading(false);
+ };
+
+ useEffect(() => {
+ if (database.id) {
+ backupConfigApi.getBackupConfigByDbID(database.id).then((res) => {
+ setBackupConfig(res);
+ setIsUnsaved(false);
+ setIsSaving(false);
+ });
+ } else {
+ setBackupConfig({
+ databaseId: database.id,
+ isBackupsEnabled: true,
+ backupInterval: {
+ id: undefined as unknown as string,
+ interval: IntervalType.DAILY,
+ timeOfDay: '00:00',
+ },
+ storage: undefined,
+ cpuCount: 1,
+ storePeriod: Period.WEEK,
+ sendNotificationsOn: [],
+ });
+ }
+ loadStorages();
+ }, [database]);
+
+ if (!backupConfig) return <div />;
+
+ if (isStoragesLoading) {
+ return (
+ <div className="mb-5 flex items-center">
+ <Spin />
+ </div>
+ );
+ }
+
+ const { backupInterval } = backupConfig;
+
+ // UTC → local conversions for display
+ const localTime: Dayjs | undefined = backupInterval?.timeOfDay
+ ? dayjs.utc(backupInterval.timeOfDay, 'HH:mm').local()
+ : undefined;
+
+ const displayedWeekday: number | undefined =
+ backupInterval?.interval === IntervalType.WEEKLY &&
+ backupInterval.weekday &&
+ backupInterval.timeOfDay
+ ? getLocalWeekday(backupInterval.weekday, backupInterval.timeOfDay)
+ : backupInterval?.weekday;
+
+ const displayedDayOfMonth: number | undefined =
+ backupInterval?.interval === IntervalType.MONTHLY &&
+ backupInterval.dayOfMonth &&
+ backupInterval.timeOfDay
+ ? getLocalDayOfMonth(backupInterval.dayOfMonth, backupInterval.timeOfDay)
+ : backupInterval?.dayOfMonth;
+
+ // mandatory-field check
+ const isAllFieldsFilled =
+ !backupConfig.isBackupsEnabled ||
+ (Boolean(backupConfig.storePeriod) &&
+ Boolean(backupConfig.storage?.id) &&
+ Boolean(backupConfig.cpuCount) &&
+ Boolean(backupInterval?.interval) &&
+ (!backupInterval ||
+ ((backupInterval.interval !== IntervalType.WEEKLY || displayedWeekday) &&
+ (backupInterval.interval !== IntervalType.MONTHLY || displayedDayOfMonth))));
+
+ return (
+ <div>
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backups enabled</div>
+ <Switch
+ checked={backupConfig.isBackupsEnabled}
+ onChange={(checked) => updateBackupConfig({ isBackupsEnabled: checked })}
+ size="small"
+ />
+ </div>
+
+ {backupConfig.isBackupsEnabled && (
+ <>
+ <div className="mt-4 mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup interval</div>
+ <Select
+ value={backupInterval?.interval}
+ onChange={(v) => saveInterval({ interval: v })}
+ size="small"
+ className="max-w-[200px] grow"
+ options={[
+ { label: 'Hourly', value: IntervalType.HOURLY },
+ { label: 'Daily', value: IntervalType.DAILY },
+ { label: 'Weekly', value: IntervalType.WEEKLY },
+ { label: 'Monthly', value: IntervalType.MONTHLY },
+ ]}
+ />
+ </div>
+
+ {backupInterval?.interval === IntervalType.WEEKLY && (
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup weekday</div>
+ <Select
+ value={displayedWeekday}
+ onChange={(localWeekday) => {
+ if (!localWeekday) return;
+ const ref = localTime ?? dayjs();
+ saveInterval({ weekday: getUtcWeekday(localWeekday, ref) });
+ }}
+ size="small"
+ className="max-w-[200px] grow"
+ options={weekdayOptions}
+ />
+ </div>
+ )}
+
+ {backupInterval?.interval === IntervalType.MONTHLY && (
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup day of month</div>
+ <InputNumber
+ min={1}
+ max={31}
+ value={displayedDayOfMonth}
+ onChange={(localDom) => {
+ if (!localDom) return;
+ const ref = localTime ?? dayjs();
+ saveInterval({ dayOfMonth: getUtcDayOfMonth(localDom, ref) });
+ }}
+ size="small"
+ className="max-w-[200px] grow"
+ />
+ </div>
+ )}
+
+ {backupInterval?.interval !== IntervalType.HOURLY && (
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup time of day</div>
+ <TimePicker
+ value={localTime}
+ format={timeFormat.format}
+ use12Hours={timeFormat.use12Hours}
+ allowClear={false}
+ size="small"
+ className="max-w-[200px] grow"
+ onChange={(t) => {
+ if (!t) return;
+ const patch: Partial<Interval> = { timeOfDay: t.utc().format('HH:mm') };
+
+ if (backupInterval?.interval === IntervalType.WEEKLY && displayedWeekday) {
+ patch.weekday = getUtcWeekday(displayedWeekday, t);
+ }
+ if (backupInterval?.interval === IntervalType.MONTHLY && displayedDayOfMonth) {
+ patch.dayOfMonth = getUtcDayOfMonth(displayedDayOfMonth, t);
+ }
+
+ saveInterval(patch);
+ }}
+ />
+ </div>
+ )}
+
+ <div className="mt-5 mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">CPU count</div>
+ <InputNumber
+ min={1}
+ max={16}
+ value={backupConfig.cpuCount}
+ onChange={(value) => updateBackupConfig({ cpuCount: value || 1 })}
+ size="small"
+ className="max-w-[200px] grow"
+ />
+
+ <Tooltip
+ className="cursor-pointer"
+ title="Number of CPU cores to use for backup processing. Higher values may speed up backups but use more resources."
+ >
+ <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
+ </Tooltip>
+ </div>
+
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Store period</div>
+ <Select
+ value={backupConfig.storePeriod}
+ onChange={(v) => updateBackupConfig({ storePeriod: v })}
+ size="small"
+ className="max-w-[200px] grow"
+ options={[
+ { label: '1 day', value: Period.DAY },
+ { label: '1 week', value: Period.WEEK },
+ { label: '1 month', value: Period.MONTH },
+ { label: '3 months', value: Period.THREE_MONTH },
+ { label: '6 months', value: Period.SIX_MONTH },
+ { label: '1 year', value: Period.YEAR },
+ { label: '2 years', value: Period.TWO_YEARS },
+ { label: '3 years', value: Period.THREE_YEARS },
+ { label: '4 years', value: Period.FOUR_YEARS },
+ { label: '5 years', value: Period.FIVE_YEARS },
+ { label: 'Forever', value: Period.FOREVER },
+ ]}
+ />
+
+ <Tooltip
+ className="cursor-pointer"
+ title="How long to keep the backups? Make sure you have enough storage space."
+ >
+ <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
+ </Tooltip>
+ </div>
+
+ <div className="mt-5 mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Storage</div>
+ <Select
+ value={backupConfig.storage?.id}
+ onChange={(storageId) => {
+ if (storageId.includes('create-new-storage')) {
+ setShowCreateStorage(true);
+ return;
+ }
+
+ const selectedStorage = storages.find((s) => s.id === storageId);
+ updateBackupConfig({ storage: selectedStorage });
+
+ if (backupConfig.storage?.id) {
+ setIsShowWarn(true);
+ }
+ }}
+ size="small"
+ className="mr-2 max-w-[200px] grow"
+ options={[
+ ...storages.map((s) => ({ label: s.name, value: s.id })),
+ { label: 'Create new storage', value: 'create-new-storage' },
+ ]}
+ placeholder="Select storage"
+ />
+
+ {backupConfig.storage?.type && (
+ <img
+ src={getStorageLogoFromType(backupConfig.storage.type)}
+ alt="storageIcon"
+ className="ml-1 h-4 w-4"
+ />
+ )}
+ </div>
+
+ <div className="mt-4 mb-1 flex w-full items-start">
+ <div className="mt-1 min-w-[150px]">Notifications</div>
+ <div className="flex flex-col space-y-2">
+ <Checkbox
+ checked={backupConfig.sendNotificationsOn.includes(
+ BackupNotificationType.BackupSuccess,
+ )}
+ onChange={(e) => {
+ const notifications = [...backupConfig.sendNotificationsOn];
+ const index = notifications.indexOf(BackupNotificationType.BackupSuccess);
+ if (e.target.checked && index === -1) {
+ notifications.push(BackupNotificationType.BackupSuccess);
+ } else if (!e.target.checked && index > -1) {
+ notifications.splice(index, 1);
+ }
+ updateBackupConfig({ sendNotificationsOn: notifications });
+ }}
+ >
+ Backup success
+ </Checkbox>
+
+ <Checkbox
+ checked={backupConfig.sendNotificationsOn.includes(
+ BackupNotificationType.BackupFailed,
+ )}
+ onChange={(e) => {
+ const notifications = [...backupConfig.sendNotificationsOn];
+ const index = notifications.indexOf(BackupNotificationType.BackupFailed);
+ if (e.target.checked && index === -1) {
+ notifications.push(BackupNotificationType.BackupFailed);
+ } else if (!e.target.checked && index > -1) {
+ notifications.splice(index, 1);
+ }
+ updateBackupConfig({ sendNotificationsOn: notifications });
+ }}
+ >
+ Backup failed
+ </Checkbox>
+ </div>
+ </div>
+ </>
+ )}
+
+ <div className="mt-5 flex">
+ {isShowBackButton && (
+ <Button className="mr-1" onClick={onBack}>
+ Back
+ </Button>
+ )}
+
+ {isShowCancelButton && (
+ <Button danger ghost className="mr-1" onClick={onCancel}>
+ Cancel
+ </Button>
+ )}
+
+ <Button
+ type="primary"
+ className={`${isShowCancelButton ? 'ml-1' : 'ml-auto'} mr-5`}
+ onClick={saveBackupConfig}
+ loading={isSaving}
+ disabled={!isUnsaved || !isAllFieldsFilled}
+ >
+ {saveButtonText || 'Save'}
+ </Button>
+ </div>
+
+ {isShowCreateStorage && (
+ <Modal
+ title="Add storage"
+ footer={<div />}
+ open={isShowCreateStorage}
+ onCancel={() => setShowCreateStorage(false)}
+ >
+ <div className="my-3 max-w-[275px] text-gray-500">
+ Storage - is a place where backups will be stored (local disk, S3, Google Drive, etc.)
+ </div>
+
+ <EditStorageComponent
+ isShowName
+ isShowClose={false}
+ onClose={() => setShowCreateStorage(false)}
+ onChanged={() => {
+ loadStorages();
+ setShowCreateStorage(false);
+ }}
+ />
+ </Modal>
+ )}
+
+ {isShowWarn && (
+ <ConfirmationComponent
+ onConfirm={() => {
+ setIsShowWarn(false);
+ }}
+ onDecline={() => {
+ setIsShowWarn(false);
+ }}
+ description="If you change the storage, all backups in this storage will be deleted."
+ actionButtonColor="red"
+ actionText="I understand"
+ cancelText="Cancel"
+ hideCancelButton
+ />
+ )}
+ </div>
+ );
+};
diff --git a/frontend/src/features/backups/ui/ShowBackupConfigComponent.tsx b/frontend/src/features/backups/ui/ShowBackupConfigComponent.tsx
new file mode 100644
index 00000000..03a61bb8
--- /dev/null
+++ b/frontend/src/features/backups/ui/ShowBackupConfigComponent.tsx
@@ -0,0 +1,172 @@
+import dayjs from 'dayjs';
+import { useMemo } from 'react';
+import { useEffect, useState } from 'react';
+
+import { type BackupConfig, backupConfigApi } from '../../../entity/backups';
+import { BackupNotificationType } from '../../../entity/backups/model/BackupNotificationType';
+import type { Database } from '../../../entity/databases';
+import { Period } from '../../../entity/databases/model/Period';
+import { IntervalType } from '../../../entity/intervals';
+import { getStorageLogoFromType } from '../../../entity/storages/models/getStorageLogoFromType';
+import { getLocalDayOfMonth, getLocalWeekday, getUserTimeFormat } from '../../../shared/time/utils';
+
+interface Props {
+ database: Database;
+}
+
+const weekdayLabels = {
+ 1: 'Mon',
+ 2: 'Tue',
+ 3: 'Wed',
+ 4: 'Thu',
+ 5: 'Fri',
+ 6: 'Sat',
+ 7: 'Sun',
+};
+
+const intervalLabels = {
+ [IntervalType.HOURLY]: 'Hourly',
+ [IntervalType.DAILY]: 'Daily',
+ [IntervalType.WEEKLY]: 'Weekly',
+ [IntervalType.MONTHLY]: 'Monthly',
+};
+
+const periodLabels = {
+ [Period.DAY]: '1 day',
+ [Period.WEEK]: '1 week',
+ [Period.MONTH]: '1 month',
+ [Period.THREE_MONTH]: '3 months',
+ [Period.SIX_MONTH]: '6 months',
+ [Period.YEAR]: '1 year',
+ [Period.TWO_YEARS]: '2 years',
+ [Period.THREE_YEARS]: '3 years',
+ [Period.FOUR_YEARS]: '4 years',
+ [Period.FIVE_YEARS]: '5 years',
+ [Period.FOREVER]: 'Forever',
+};
+
+const notificationLabels = {
+ [BackupNotificationType.BackupFailed]: 'Backup failed',
+ [BackupNotificationType.BackupSuccess]: 'Backup success',
+};
+
+export const ShowBackupConfigComponent = ({ database }: Props) => {
+ const [backupConfig, setBackupConfig] = useState<BackupConfig>();
+
+ // Detect user's preferred time format (12-hour vs 24-hour)
+ const timeFormat = useMemo(() => {
+ const is12Hour = getUserTimeFormat();
+ return {
+ use12Hours: is12Hour,
+ format: is12Hour ? 'h:mm A' : 'HH:mm',
+ };
+ }, []);
+
+ useEffect(() => {
+ if (database.id) {
+ backupConfigApi.getBackupConfigByDbID(database.id).then((res) => {
+ setBackupConfig(res);
+ });
+ }
+ }, [database]);
+
+ if (!backupConfig) return <div />;
+
+ const { backupInterval } = backupConfig;
+
+ const localTime = backupInterval?.timeOfDay
+ ? dayjs.utc(backupInterval.timeOfDay, 'HH:mm').local()
+ : undefined;
+
+ const formattedTime = localTime ? localTime.format(timeFormat.format) : '';
+
+ // Convert UTC weekday/day-of-month to local equivalents for display
+ const displayedWeekday: number | undefined =
+ backupInterval?.interval === IntervalType.WEEKLY &&
+ backupInterval.weekday &&
+ backupInterval.timeOfDay
+ ? getLocalWeekday(backupInterval.weekday, backupInterval.timeOfDay)
+ : backupInterval?.weekday;
+
+ const displayedDayOfMonth: number | undefined =
+ backupInterval?.interval === IntervalType.MONTHLY &&
+ backupInterval.dayOfMonth &&
+ backupInterval.timeOfDay
+ ? getLocalDayOfMonth(backupInterval.dayOfMonth, backupInterval.timeOfDay)
+ : backupInterval?.dayOfMonth;
+
+ return (
+ <div>
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backups enabled</div>
+ <div>{backupConfig.isBackupsEnabled ? 'Yes' : 'No'}</div>
+ </div>
+
+ {backupConfig.isBackupsEnabled ? (
+ <>
+ <div className="mt-4 mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup interval</div>
+ <div>{backupInterval?.interval ? intervalLabels[backupInterval.interval] : ''}</div>
+ </div>
+
+ {backupInterval?.interval === IntervalType.WEEKLY && (
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup weekday</div>
+ <div>
+ {displayedWeekday
+ ? weekdayLabels[displayedWeekday as keyof typeof weekdayLabels]
+ : ''}
+ </div>
+ </div>
+ )}
+
+ {backupInterval?.interval === IntervalType.MONTHLY && (
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup day of month</div>
+ <div>{displayedDayOfMonth || ''}</div>
+ </div>
+ )}
+
+ {backupInterval?.interval !== IntervalType.HOURLY && (
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Backup time of day</div>
+ <div>{formattedTime}</div>
+ </div>
+ )}
+
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Store period</div>
+ <div>{backupConfig.storePeriod ? periodLabels[backupConfig.storePeriod] : ''}</div>
+ </div>
+
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Storage</div>
+ <div className="flex items-center">
+ <div>{backupConfig.storage?.name || ''}</div>
+ {backupConfig.storage?.type && (
+ <img
+ src={getStorageLogoFromType(backupConfig.storage.type)}
+ alt="storageIcon"
+ className="ml-1 h-4 w-4"
+ />
+ )}
+ </div>
+ </div>
+
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Notifications</div>
+ <div>
+ {backupConfig.sendNotificationsOn.length > 0
+ ? backupConfig.sendNotificationsOn
+ .map((type) => notificationLabels[type])
+ .join(', ')
+ : 'None'}
+ </div>
+ </div>
+ </>
+ ) : (
+ <div />
+ )}
+ </div>
+ );
+};
diff --git a/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx b/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx
index 1448264d..b6b989f1 100644
--- a/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx
+++ b/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx
@@ -1,6 +1,6 @@
import { useState } from 'react';
-import { backupsApi } from '../../../entity/backups';
+import { type BackupConfig, backupConfigApi, backupsApi } from '../../../entity/backups';
import {
type Database,
DatabaseType,
@@ -8,10 +8,10 @@ import {
type PostgresqlDatabase,
databaseApi,
} from '../../../entity/databases';
+import { EditBackupConfigComponent } from '../../backups';
import { EditDatabaseBaseInfoComponent } from './edit/EditDatabaseBaseInfoComponent';
import { EditDatabaseNotifiersComponent } from './edit/EditDatabaseNotifiersComponent';
import { EditDatabaseSpecificDataComponent } from './edit/EditDatabaseSpecificDataComponent';
-import { EditDatabaseStorageComponent } from './edit/EditDatabaseStorageComponent';
interface Props {
onCreated: () => void;
@@ -21,6 +21,7 @@ interface Props {
export const CreateDatabaseComponent = ({ onCreated, onClose }: Props) => {
const [isCreating, setIsCreating] = useState(false);
+ const [backupConfig, setBackupConfig] = useState<BackupConfig | undefined>();
const [database, setDatabase] = useState<Database>({
id: undefined as unknown as string,
name: '',
@@ -38,18 +39,23 @@ export const CreateDatabaseComponent = ({ onCreated, onClose }: Props) => {
sendNotificationsOn: [],
} as Database);
- const [step, setStep] = useState<'base-info' | 'db-settings' | 'storages' | 'notifiers'>(
+ const [step, setStep] = useState<'base-info' | 'db-settings' | 'backup-config' | 'notifiers'>(
'base-info',
);
- const createDatabase = async (database: Database) => {
+ const createDatabase = async (database: Database, backupConfig: BackupConfig) => {
setIsCreating(true);
try {
const createdDatabase = await databaseApi.createDatabase(database);
setDatabase({ ...createdDatabase });
- await backupsApi.makeBackup(createdDatabase.id);
+ backupConfig.databaseId = createdDatabase.id;
+ await backupConfigApi.saveBackupConfig(backupConfig);
+ if (backupConfig.isBackupsEnabled) {
+ await backupsApi.makeBackup(createdDatabase.id);
+ }
+
onCreated();
onClose();
} catch (error) {
@@ -89,25 +95,24 @@ export const CreateDatabaseComponent = ({ onCreated, onClose }: Props) => {
isSaveToApi={false}
onSaved={(database) => {
setDatabase({ ...database });
- setStep('storages');
+ setStep('backup-config');
}}
/>
);
}
- if (step === 'storages') {
+ if (step === 'backup-config') {
return (
- <EditDatabaseStorageComponent
+ <EditBackupConfigComponent
database={database}
isShowCancelButton={false}
onCancel={() => onClose()}
isShowBackButton
onBack={() => setStep('db-settings')}
- isShowSaveOnlyForUnsaved={false}
saveButtonText="Continue"
isSaveToApi={false}
- onSaved={(database) => {
- setDatabase({ ...database });
+ onSaved={(backupConfig) => {
+ setBackupConfig(backupConfig);
setStep('notifiers');
}}
/>
@@ -121,7 +126,7 @@ export const CreateDatabaseComponent = ({ onCreated, onClose }: Props) => {
isShowCancelButton={false}
onCancel={() => onClose()}
isShowBackButton
- onBack={() => setStep('storages')}
+ onBack={() => setStep('backup-config')}
isShowSaveOnlyForUnsaved={false}
saveButtonText="Complete"
isSaveToApi={false}
@@ -129,7 +134,7 @@ export const CreateDatabaseComponent = ({ onCreated, onClose }: Props) => {
if (isCreating) return;
setDatabase({ ...database });
- createDatabase(database);
+ createDatabase(database, backupConfig!);
}}
/>
);
diff --git a/frontend/src/features/databases/ui/DatabaseCardComponent.tsx b/frontend/src/features/databases/ui/DatabaseCardComponent.tsx
index 148e55dc..b04ca8ca 100644
--- a/frontend/src/features/databases/ui/DatabaseCardComponent.tsx
+++ b/frontend/src/features/databases/ui/DatabaseCardComponent.tsx
@@ -3,7 +3,6 @@ import dayjs from 'dayjs';
import { type Database, DatabaseType } from '../../../entity/databases';
import { HealthStatus } from '../../../entity/databases/model/HealthStatus';
-import { getStorageLogoFromType } from '../../../entity/storages';
import { getUserShortTimeFormat } from '../../../shared/time/getUserTimeFormat';
interface Props {
@@ -52,16 +51,6 @@ export const DatabaseCardComponent = ({
<img src={databaseIcon} alt="databaseIcon" className="ml-1 h-4 w-4" />
</div>
- <div className="mb flex items-center">
- <div className="text-sm text-gray-500">Store to: {database.storage?.name} </div>
-
- <img
- src={getStorageLogoFromType(database.storage?.type)}
- alt="databaseIcon"
- className="ml-1 h-4 w-4"
- />
- </div>
-
{database.lastBackupTime && (
<div className="mt-3 mb-1 text-xs text-gray-500">
<span className="font-bold">Last backup</span>
diff --git a/frontend/src/features/databases/ui/DatabaseComponent.tsx b/frontend/src/features/databases/ui/DatabaseComponent.tsx
index 40182007..0c5d89ab 100644
--- a/frontend/src/features/databases/ui/DatabaseComponent.tsx
+++ b/frontend/src/features/databases/ui/DatabaseComponent.tsx
@@ -6,20 +6,20 @@ import { useEffect } from 'react';
import { type Database, databaseApi } from '../../../entity/databases';
import { ToastHelper } from '../../../shared/toast';
import { ConfirmationComponent } from '../../../shared/ui';
-import { BackupsComponent } from '../../backups';
+import {
+ BackupsComponent,
+ EditBackupConfigComponent,
+ ShowBackupConfigComponent,
+} from '../../backups';
import {
EditHealthcheckConfigComponent,
HealthckeckAttemptsComponent,
ShowHealthcheckConfigComponent,
} from '../../healthcheck';
-import { EditDatabaseBaseInfoComponent } from './edit/EditDatabaseBaseInfoComponent';
import { EditDatabaseNotifiersComponent } from './edit/EditDatabaseNotifiersComponent';
import { EditDatabaseSpecificDataComponent } from './edit/EditDatabaseSpecificDataComponent';
-import { EditDatabaseStorageComponent } from './edit/EditDatabaseStorageComponent';
-import { ShowDatabaseBaseInfoComponent } from './show/ShowDatabaseBaseInfoComponent';
import { ShowDatabaseNotifiersComponent } from './show/ShowDatabaseNotifiersComponent';
import { ShowDatabaseSpecificDataComponent } from './show/ShowDatabaseSpecificDataComponent';
-import { ShowDatabaseStorageComponent } from './show/ShowDatabaseStorageComponent';
interface Props {
contentHeight: number;
@@ -37,10 +37,9 @@ export const DatabaseComponent = ({
const [database, setDatabase] = useState<Database | undefined>();
const [isEditName, setIsEditName] = useState(false);
- const [isEditBaseSettings, setIsEditBaseSettings] = useState(false);
const [isEditDatabaseSpecificDataSettings, setIsEditDatabaseSpecificDataSettings] =
useState(false);
- const [isEditStorageSettings, setIsEditStorageSettings] = useState(false);
+ const [isEditBackupConfig, setIsEditBackupConfig] = useState(false);
const [isEditNotifiersSettings, setIsEditNotifiersSettings] = useState(false);
const [isEditHealthcheckSettings, setIsEditHealthcheckSettings] = useState(false);
@@ -95,14 +94,11 @@ export const DatabaseComponent = ({
});
};
- const startEdit = (
- type: 'name' | 'settings' | 'database' | 'storage' | 'notifiers' | 'healthcheck',
- ) => {
+ const startEdit = (type: 'name' | 'database' | 'backup-config' | 'notifiers' | 'healthcheck') => {
setEditDatabase(JSON.parse(JSON.stringify(database)));
setIsEditName(type === 'name');
- setIsEditBaseSettings(type === 'settings');
setIsEditDatabaseSpecificDataSettings(type === 'database');
- setIsEditStorageSettings(type === 'storage');
+ setIsEditBackupConfig(type === 'backup-config');
setIsEditNotifiersSettings(type === 'notifiers');
setIsEditHealthcheckSettings(type === 'healthcheck');
setIsNameUnsaved(false);
@@ -222,41 +218,6 @@ export const DatabaseComponent = ({
)}
<div className="flex flex-wrap gap-10">
- <div className="w-[350px]">
- <div className="mt-5 flex items-center font-bold">
- <div>Backup settings</div>
-
- {!isEditBaseSettings ? (
- <div
- className="ml-2 h-4 w-4 cursor-pointer"
- onClick={() => startEdit('settings')}
- >
- <img src="/icons/pen-gray.svg" />
- </div>
- ) : (
- <div />
- )}
- </div>
-
- <div className="mt-1 text-sm">
- {isEditBaseSettings ? (
- <EditDatabaseBaseInfoComponent
- isShowName={false}
- database={database}
- isShowCancelButton
- onCancel={() => {
- setIsEditBaseSettings(false);
- loadSettings();
- }}
- isSaveToApi={true}
- onSaved={onDatabaseChanged}
- />
- ) : (
- <ShowDatabaseBaseInfoComponent database={database} />
- )}
- </div>
- </div>
-
<div className="w-[350px]">
<div className="mt-5 flex items-center font-bold">
<div>Database settings</div>
@@ -292,17 +253,15 @@ export const DatabaseComponent = ({
)}
</div>
</div>
- </div>
- <div className="flex flex-wrap gap-10">
<div className="w-[350px]">
<div className="mt-5 flex items-center font-bold">
- <div>Storage settings</div>
+ <div>Backup config</div>
- {!isEditStorageSettings ? (
+ {!isEditBackupConfig ? (
<div
className="ml-2 h-4 w-4 cursor-pointer"
- onClick={() => startEdit('storage')}
+ onClick={() => startEdit('backup-config')}
>
<img src="/icons/pen-gray.svg" />
</div>
@@ -313,35 +272,36 @@ export const DatabaseComponent = ({
<div>
<div className="mt-1 text-sm">
- {isEditStorageSettings ? (
- <EditDatabaseStorageComponent
+ {isEditBackupConfig ? (
+ <EditBackupConfigComponent
database={database}
isShowCancelButton
- isShowBackButton={false}
- isShowSaveOnlyForUnsaved={true}
- onBack={() => {}}
onCancel={() => {
- setIsEditStorageSettings(false);
+ setIsEditBackupConfig(false);
loadSettings();
}}
isSaveToApi={true}
- onSaved={onDatabaseChanged}
+ onSaved={() => onDatabaseChanged(database)}
+ isShowBackButton={false}
+ onBack={() => {}}
/>
) : (
- <ShowDatabaseStorageComponent database={database} />
+ <ShowBackupConfigComponent database={database} />
)}
</div>
</div>
</div>
+ </div>
+ <div className="flex flex-wrap gap-10">
<div className="w-[350px]">
<div className="mt-5 flex items-center font-bold">
- <div>Notifiers settings</div>
+ <div>Healthcheck settings</div>
- {!isEditNotifiersSettings ? (
+ {!isEditHealthcheckSettings ? (
<div
className="ml-2 h-4 w-4 cursor-pointer"
- onClick={() => startEdit('notifiers')}
+ onClick={() => startEdit('healthcheck')}
>
<img src="/icons/pen-gray.svg" />
</div>
@@ -351,37 +311,28 @@ export const DatabaseComponent = ({
</div>
<div className="mt-1 text-sm">
- {isEditNotifiersSettings ? (
- <EditDatabaseNotifiersComponent
- database={database}
- isShowCancelButton
- isShowBackButton={false}
- isShowSaveOnlyForUnsaved={true}
- onBack={() => {}}
- onCancel={() => {
- setIsEditNotifiersSettings(false);
+ {isEditHealthcheckSettings ? (
+ <EditHealthcheckConfigComponent
+ databaseId={database.id}
+ onClose={() => {
+ setIsEditHealthcheckSettings(false);
loadSettings();
}}
- isSaveToApi={true}
- saveButtonText="Save"
- onSaved={onDatabaseChanged}
/>
) : (
- <ShowDatabaseNotifiersComponent database={database} />
+ <ShowHealthcheckConfigComponent databaseId={database.id} />
)}
</div>
</div>
- </div>
- <div className="flex flex-wrap gap-10">
<div className="w-[350px]">
<div className="mt-5 flex items-center font-bold">
- <div>Healthcheck settings</div>
+ <div>Notifiers settings</div>
- {!isEditHealthcheckSettings ? (
+ {!isEditNotifiersSettings ? (
<div
className="ml-2 h-4 w-4 cursor-pointer"
- onClick={() => startEdit('healthcheck')}
+ onClick={() => startEdit('notifiers')}
>
<img src="/icons/pen-gray.svg" />
</div>
@@ -391,16 +342,23 @@ export const DatabaseComponent = ({
</div>
<div className="mt-1 text-sm">
- {isEditHealthcheckSettings ? (
- <EditHealthcheckConfigComponent
- databaseId={database.id}
- onClose={() => {
- setIsEditHealthcheckSettings(false);
+ {isEditNotifiersSettings ? (
+ <EditDatabaseNotifiersComponent
+ database={database}
+ isShowCancelButton
+ isShowBackButton={false}
+ isShowSaveOnlyForUnsaved={true}
+ onBack={() => {}}
+ onCancel={() => {
+ setIsEditNotifiersSettings(false);
loadSettings();
}}
+ isSaveToApi={true}
+ saveButtonText="Save"
+ onSaved={onDatabaseChanged}
/>
) : (
- <ShowHealthcheckConfigComponent databaseId={database.id} />
+ <ShowDatabaseNotifiersComponent database={database} />
)}
</div>
</div>
@@ -445,13 +403,8 @@ export const DatabaseComponent = ({
)}
</div>
- <div className="mt-5 w-full rounded bg-white p-5 shadow">
- {database && <HealthckeckAttemptsComponent database={database} />}
- </div>
-
- <div className="mt-5 w-full rounded bg-white p-5 shadow">
- {database && <BackupsComponent database={database} />}
- </div>
+ {database && <HealthckeckAttemptsComponent database={database} />}
+ {database && <BackupsComponent database={database} />}
</div>
);
};
diff --git a/frontend/src/features/databases/ui/edit/EditDatabaseBaseInfoComponent.tsx b/frontend/src/features/databases/ui/edit/EditDatabaseBaseInfoComponent.tsx
index efd23a2d..d3aa33d2 100644
--- a/frontend/src/features/databases/ui/edit/EditDatabaseBaseInfoComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditDatabaseBaseInfoComponent.tsx
@@ -1,28 +1,7 @@
-import { InfoCircleOutlined } from '@ant-design/icons';
-import { Button, Input, InputNumber, Select, TimePicker, Tooltip } from 'antd';
-import dayjs, { Dayjs } from 'dayjs';
-import { useEffect, useMemo, useState } from 'react';
+import { Button, Input } from 'antd';
+import { useEffect, useState } from 'react';
import { type Database, databaseApi } from '../../../../entity/databases';
-import { Period } from '../../../../entity/databases/model/Period';
-import { type Interval, IntervalType } from '../../../../entity/intervals';
-import {
- getLocalDayOfMonth,
- getLocalWeekday,
- getUserTimeFormat,
- getUtcDayOfMonth,
- getUtcWeekday,
-} from '../../../../shared/time/utils';
-
-const weekdayOptions = [
- { value: 1, label: 'Mon' },
- { value: 2, label: 'Tue' },
- { value: 3, label: 'Wed' },
- { value: 4, label: 'Thu' },
- { value: 5, label: 'Fri' },
- { value: 6, label: 'Sat' },
- { value: 7, label: 'Sun' },
-];
interface Props {
database: Database;
@@ -49,32 +28,11 @@ export const EditDatabaseBaseInfoComponent = ({
const [isUnsaved, setIsUnsaved] = useState(false);
const [isSaving, setIsSaving] = useState(false);
- const timeFormat = useMemo(() => {
- const is12 = getUserTimeFormat();
- return { use12Hours: is12, format: is12 ? 'h:mm A' : 'HH:mm' };
- }, []);
-
const updateDatabase = (patch: Partial<Database>) => {
setEditingDatabase((prev) => (prev ? { ...prev, ...patch } : prev));
setIsUnsaved(true);
};
- const saveInterval = (patch: Partial<Interval>) => {
- setEditingDatabase((prev) => {
- if (!prev) return prev;
-
- const updatedBackupInterval = { ...(prev.backupInterval ?? {}), ...patch };
-
- if (!updatedBackupInterval.id && prev.backupInterval?.id) {
- updatedBackupInterval.id = prev.backupInterval.id;
- }
-
- return { ...prev, backupInterval: updatedBackupInterval as Interval };
- });
-
- setIsUnsaved(true);
- };
-
const saveDatabase = async () => {
if (!editingDatabase) return;
if (isSaveToApi) {
@@ -97,35 +55,9 @@ export const EditDatabaseBaseInfoComponent = ({
}, [database]);
if (!editingDatabase) return null;
- const { backupInterval } = editingDatabase;
-
- // UTC → local conversions for display
- const localTime: Dayjs | undefined = backupInterval?.timeOfDay
- ? dayjs.utc(backupInterval.timeOfDay, 'HH:mm').local()
- : undefined;
-
- const displayedWeekday: number | undefined =
- backupInterval?.interval === IntervalType.WEEKLY &&
- backupInterval.weekday &&
- backupInterval.timeOfDay
- ? getLocalWeekday(backupInterval.weekday, backupInterval.timeOfDay)
- : backupInterval?.weekday;
-
- const displayedDayOfMonth: number | undefined =
- backupInterval?.interval === IntervalType.MONTHLY &&
- backupInterval.dayOfMonth &&
- backupInterval.timeOfDay
- ? getLocalDayOfMonth(backupInterval.dayOfMonth, backupInterval.timeOfDay)
- : backupInterval?.dayOfMonth;
// mandatory-field check
- const isAllFieldsFilled =
- Boolean(editingDatabase.name) &&
- Boolean(editingDatabase.storePeriod) &&
- Boolean(backupInterval?.interval) &&
- (!backupInterval ||
- ((backupInterval.interval !== IntervalType.WEEKLY || displayedWeekday) &&
- (backupInterval.interval !== IntervalType.MONTHLY || displayedDayOfMonth)));
+ const isAllFieldsFilled = Boolean(editingDatabase.name);
return (
<div>
@@ -142,119 +74,13 @@ export const EditDatabaseBaseInfoComponent = ({
</div>
)}
- <div className="mt-4 mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup interval</div>
- <Select
- value={backupInterval?.interval}
- onChange={(v) => saveInterval({ interval: v })}
- size="small"
- className="max-w-[200px] grow"
- options={[
- { label: 'Hourly', value: IntervalType.HOURLY },
- { label: 'Daily', value: IntervalType.DAILY },
- { label: 'Weekly', value: IntervalType.WEEKLY },
- { label: 'Monthly', value: IntervalType.MONTHLY },
- ]}
- />
- </div>
-
- {backupInterval?.interval === IntervalType.WEEKLY && (
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup weekday</div>
- <Select
- value={displayedWeekday}
- onChange={(localWeekday) => {
- if (!localWeekday) return;
- const ref = localTime ?? dayjs();
- saveInterval({ weekday: getUtcWeekday(localWeekday, ref) });
- }}
- size="small"
- className="max-w-[200px] grow"
- options={weekdayOptions}
- />
- </div>
- )}
-
- {backupInterval?.interval === IntervalType.MONTHLY && (
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup day of month</div>
- <InputNumber
- min={1}
- max={31}
- value={displayedDayOfMonth}
- onChange={(localDom) => {
- if (!localDom) return;
- const ref = localTime ?? dayjs();
- saveInterval({ dayOfMonth: getUtcDayOfMonth(localDom, ref) });
- }}
- size="small"
- className="max-w-[200px] grow"
- />
- </div>
- )}
-
- {backupInterval?.interval !== IntervalType.HOURLY && (
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup time of day</div>
- <TimePicker
- value={localTime}
- format={timeFormat.format}
- use12Hours={timeFormat.use12Hours}
- allowClear={false}
- size="small"
- className="max-w-[200px] grow"
- onChange={(t) => {
- if (!t) return;
- const patch: Partial<Interval> = { timeOfDay: t.utc().format('HH:mm') };
-
- if (backupInterval?.interval === IntervalType.WEEKLY && displayedWeekday) {
- patch.weekday = getUtcWeekday(displayedWeekday, t);
- }
- if (backupInterval?.interval === IntervalType.MONTHLY && displayedDayOfMonth) {
- patch.dayOfMonth = getUtcDayOfMonth(displayedDayOfMonth, t);
- }
-
- saveInterval(patch);
- }}
- />
- </div>
- )}
-
- <div className="mt-4 mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Store period</div>
- <Select
- value={editingDatabase.storePeriod}
- onChange={(v) => updateDatabase({ storePeriod: v })}
- size="small"
- className="max-w-[200px] grow"
- options={[
- { label: '1 day', value: Period.DAY },
- { label: '1 week', value: Period.WEEK },
- { label: '1 month', value: Period.MONTH },
- { label: '3 months', value: Period.THREE_MONTH },
- { label: '6 months', value: Period.SIX_MONTH },
- { label: '1 year', value: Period.YEAR },
- { label: '2 years', value: Period.TWO_YEARS },
- { label: '3 years', value: Period.THREE_YEARS },
- { label: '4 years', value: Period.FOUR_YEARS },
- { label: '5 years', value: Period.FIVE_YEARS },
- { label: 'Forever', value: Period.FOREVER },
- ]}
- />
- <Tooltip
- className="cursor-pointer"
- title="How long to keep the backups? Make sure you have enough storage space."
- >
- <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
- </Tooltip>
- </div>
-
<div className="mt-5 flex">
{isShowCancelButton && (
<Button danger ghost className="mr-1" onClick={onCancel}>
Cancel
</Button>
)}
+
<Button
type="primary"
className={`${isShowCancelButton ? 'ml-1' : 'ml-auto'} mr-5`}
diff --git a/frontend/src/features/databases/ui/edit/EditDatabaseNotifiersComponent.tsx b/frontend/src/features/databases/ui/edit/EditDatabaseNotifiersComponent.tsx
index 7a8ac3cf..73d6182c 100644
--- a/frontend/src/features/databases/ui/edit/EditDatabaseNotifiersComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditDatabaseNotifiersComponent.tsx
@@ -2,7 +2,6 @@ import { Button, Modal, Select, Spin } from 'antd';
import { useEffect, useState } from 'react';
import { type Database, databaseApi } from '../../../../entity/databases';
-import { BackupNotificationType } from '../../../../entity/databases/model/BackupNotificationType';
import { type Notifier, notifierApi } from '../../../../entity/notifiers';
import { EditNotifierComponent } from '../../../notifiers/ui/edit/EditNotifierComponent';
@@ -99,35 +98,6 @@ export const EditDatabaseNotifiersComponent = ({
You can select several notifiers, notifications will be sent to all of them.
</div>
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Sent notification when</div>
-
- <Select
- mode="multiple"
- value={editingDatabase.sendNotificationsOn}
- onChange={(sendNotificationsOn) => {
- setEditingDatabase({
- ...editingDatabase,
- sendNotificationsOn,
- } as unknown as Database);
-
- setIsUnsaved(true);
- }}
- size="small"
- className="max-w-[200px] grow"
- options={[
- {
- label: 'Backup failed',
- value: BackupNotificationType.BACKUP_FAILED,
- },
- {
- label: 'Backup success',
- value: BackupNotificationType.BACKUP_SUCCESS,
- },
- ]}
- />
- </div>
-
<div className="mb-5 flex w-full items-center">
<div className="min-w-[150px]">Notifiers</div>
diff --git a/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
index e1639eaf..3bbc42fc 100644
--- a/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
@@ -26,6 +26,7 @@ interface Props {
isShowDbVersionHint?: boolean;
isShowDbName?: boolean;
+ isBlockDbName?: boolean;
}
export const EditDatabaseSpecificDataComponent = ({
@@ -43,6 +44,8 @@ export const EditDatabaseSpecificDataComponent = ({
isShowDbVersionHint = true,
isShowDbName = true,
+
+ isBlockDbName = false,
}: Props) => {
const [editingDatabase, setEditingDatabase] = useState<Database>();
const [isSaving, setIsSaving] = useState(false);
@@ -263,6 +266,7 @@ export const EditDatabaseSpecificDataComponent = ({
size="small"
className="max-w-[200px] grow"
placeholder="Enter PG database name (optional)"
+ disabled={isBlockDbName}
/>
</div>
)}
@@ -283,33 +287,6 @@ export const EditDatabaseSpecificDataComponent = ({
size="small"
/>
</div>
-
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">CPU count</div>
- <InputNumber
- value={editingDatabase.postgresql?.cpuCount}
- onChange={(e) => {
- if (!editingDatabase.postgresql || e === null) return;
-
- setEditingDatabase({
- ...editingDatabase,
- postgresql: { ...editingDatabase.postgresql, cpuCount: e },
- });
- setIsConnectionTested(false);
- }}
- size="small"
- className="max-w-[200px] grow"
- placeholder="Enter PG CPU count"
- min={1}
- step={1}
- />
- <Tooltip
- className="cursor-pointer"
- title="The amount of CPU can be utilized for backuping or restoring"
- >
- <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
- </Tooltip>
- </div>
</>
)}
diff --git a/frontend/src/features/databases/ui/edit/EditDatabaseStorageComponent.tsx b/frontend/src/features/databases/ui/edit/EditDatabaseStorageComponent.tsx
deleted file mode 100644
index 79b3bf19..00000000
--- a/frontend/src/features/databases/ui/edit/EditDatabaseStorageComponent.tsx
+++ /dev/null
@@ -1,199 +0,0 @@
-import { Button, Modal, Select, Spin } from 'antd';
-import { useEffect, useState } from 'react';
-
-import { type Database, databaseApi } from '../../../../entity/databases';
-import { type Storage, storageApi } from '../../../../entity/storages';
-import { ConfirmationComponent } from '../../../../shared/ui';
-import { EditStorageComponent } from '../../../storages/ui/edit/EditStorageComponent';
-
-interface Props {
- database: Database;
-
- isShowCancelButton?: boolean;
- onCancel: () => void;
-
- isShowBackButton: boolean;
- onBack: () => void;
-
- isShowSaveOnlyForUnsaved: boolean;
- saveButtonText?: string;
- isSaveToApi: boolean;
- onSaved: (database: Database) => void;
-}
-
-export const EditDatabaseStorageComponent = ({
- database,
-
- isShowCancelButton,
- onCancel,
-
- isShowBackButton,
- onBack,
-
- isShowSaveOnlyForUnsaved,
- saveButtonText,
- isSaveToApi,
- onSaved,
-}: Props) => {
- const [editingDatabase, setEditingDatabase] = useState<Database>();
- const [isUnsaved, setIsUnsaved] = useState(false);
- const [isSaving, setIsSaving] = useState(false);
-
- const [storages, setStorages] = useState<Storage[]>([]);
- const [isStoragesLoading, setIsStoragesLoading] = useState(false);
- const [isShowCreateStorage, setShowCreateStorage] = useState(false);
-
- const [isShowWarn, setIsShowWarn] = useState(false);
-
- const saveDatabase = async () => {
- if (!editingDatabase) return;
-
- if (isSaveToApi) {
- setIsSaving(true);
-
- try {
- await databaseApi.updateDatabase(editingDatabase);
- setIsUnsaved(false);
- } catch (e) {
- alert((e as Error).message);
- }
-
- setIsSaving(false);
- }
-
- onSaved(editingDatabase);
- };
-
- const loadStorages = async () => {
- setIsStoragesLoading(true);
-
- try {
- const storages = await storageApi.getStorages();
- setStorages(storages);
- } catch (e) {
- alert((e as Error).message);
- }
-
- setIsStoragesLoading(false);
- };
-
- useEffect(() => {
- setIsSaving(false);
- setEditingDatabase({ ...database });
- loadStorages();
-
- if (database.id) {
- setIsShowWarn(true);
- }
- }, [database]);
-
- if (!editingDatabase) return null;
-
- if (isStoragesLoading)
- return (
- <div className="mb-5 flex items-center">
- <Spin />
- </div>
- );
-
- return (
- <div>
- <div className="mb-5 max-w-[275px] text-gray-500">
- Storage - is a place where backups will be stored (local disk, S3, Google Drive, etc.)
- </div>
-
- <div className="mb-5 flex w-full items-center">
- <div className="min-w-[150px]">Storages</div>
-
- <Select
- value={editingDatabase.storage.id}
- onChange={(storageId) => {
- if (storageId.includes('create-new-storage')) {
- setShowCreateStorage(true);
- return;
- }
-
- setEditingDatabase({
- ...editingDatabase,
- storage: storages.find((s) => s.id === storageId),
- } as unknown as Database);
-
- setIsUnsaved(true);
- }}
- size="small"
- className="max-w-[200px] grow"
- options={[
- ...storages.map((s) => ({ label: s.name, value: s.id })),
- { label: 'Create new storage', value: 'create-new-storage' },
- ]}
- placeholder="Select storages"
- />
- </div>
-
- <div className="mt-5 flex">
- {isShowCancelButton && (
- <Button className="mr-1" danger ghost onClick={() => onCancel()}>
- Cancel
- </Button>
- )}
-
- {isShowBackButton && (
- <Button className="mr-auto" type="primary" ghost onClick={() => onBack()}>
- Back
- </Button>
- )}
-
- {(!isShowSaveOnlyForUnsaved || isUnsaved) && (
- <Button
- type="primary"
- onClick={() => saveDatabase()}
- loading={isSaving}
- disabled={isSaving || !editingDatabase.storage.id}
- className="mr-5"
- >
- {saveButtonText || 'Save'}
- </Button>
- )}
- </div>
-
- {isShowCreateStorage && (
- <Modal
- title="Add storage"
- footer={<div />}
- open={isShowCreateStorage}
- onCancel={() => setShowCreateStorage(false)}
- >
- <div className="my-3 max-w-[275px] text-gray-500">
- Storage - is a place where backups will be stored (local disk, S3, Google Drive, etc.)
- </div>
-
- <EditStorageComponent
- isShowName
- isShowClose={false}
- onClose={() => setShowCreateStorage(false)}
- onChanged={() => {
- loadStorages();
- setShowCreateStorage(false);
- }}
- />
- </Modal>
- )}
-
- {isShowWarn && (
- <ConfirmationComponent
- onConfirm={() => {
- setIsShowWarn(false);
- }}
- onDecline={() => {
- setIsShowWarn(false);
- }}
- description="If you change the storage, all backups in this storage will be deleted."
- actionButtonColor="red"
- actionText="I understand"
- cancelText="Cancel"
- hideCancelButton
- />
- )}
- </div>
- );
-};
diff --git a/frontend/src/features/databases/ui/show/ShowDatabaseBaseInfoComponent.tsx b/frontend/src/features/databases/ui/show/ShowDatabaseBaseInfoComponent.tsx
index 2b666ecc..ca3c8bff 100644
--- a/frontend/src/features/databases/ui/show/ShowDatabaseBaseInfoComponent.tsx
+++ b/frontend/src/features/databases/ui/show/ShowDatabaseBaseInfoComponent.tsx
@@ -1,84 +1,11 @@
-import dayjs from 'dayjs';
-import { useMemo } from 'react';
-
import { type Database } from '../../../../entity/databases';
-import { Period } from '../../../../entity/databases/model/Period';
-import { IntervalType } from '../../../../entity/intervals';
-import {
- getLocalDayOfMonth,
- getLocalWeekday,
- getUserTimeFormat,
-} from '../../../../shared/time/utils';
interface Props {
database: Database;
isShowName?: boolean;
}
-const weekdayLabels = {
- 1: 'Mon',
- 2: 'Tue',
- 3: 'Wed',
- 4: 'Thu',
- 5: 'Fri',
- 6: 'Sat',
- 7: 'Sun',
-};
-
-const intervalLabels = {
- [IntervalType.HOURLY]: 'Hourly',
- [IntervalType.DAILY]: 'Daily',
- [IntervalType.WEEKLY]: 'Weekly',
- [IntervalType.MONTHLY]: 'Monthly',
-};
-
-const periodLabels = {
- [Period.DAY]: '1 day',
- [Period.WEEK]: '1 week',
- [Period.MONTH]: '1 month',
- [Period.THREE_MONTH]: '3 months',
- [Period.SIX_MONTH]: '6 months',
- [Period.YEAR]: '1 year',
- [Period.TWO_YEARS]: '2 years',
- [Period.THREE_YEARS]: '3 years',
- [Period.FOUR_YEARS]: '4 years',
- [Period.FIVE_YEARS]: '5 years',
- [Period.FOREVER]: 'Forever',
-};
-
export const ShowDatabaseBaseInfoComponent = ({ database, isShowName }: Props) => {
- // Detect user's preferred time format (12-hour vs 24-hour)
- const timeFormat = useMemo(() => {
- const is12Hour = getUserTimeFormat();
- return {
- use12Hours: is12Hour,
- format: is12Hour ? 'h:mm A' : 'HH:mm',
- };
- }, []);
-
- const { backupInterval } = database;
-
- const localTime = backupInterval?.timeOfDay
- ? dayjs.utc(backupInterval.timeOfDay, 'HH:mm').local()
- : undefined;
-
- const formattedTime = localTime ? localTime.format(timeFormat.format) : '';
-
- // Convert UTC weekday/day-of-month to local equivalents for display
- const displayedWeekday: number | undefined =
- backupInterval?.interval === IntervalType.WEEKLY &&
- backupInterval.weekday &&
- backupInterval.timeOfDay
- ? getLocalWeekday(backupInterval.weekday, backupInterval.timeOfDay)
- : backupInterval?.weekday;
-
- const displayedDayOfMonth: number | undefined =
- backupInterval?.interval === IntervalType.MONTHLY &&
- backupInterval.dayOfMonth &&
- backupInterval.timeOfDay
- ? getLocalDayOfMonth(backupInterval.dayOfMonth, backupInterval.timeOfDay)
- : backupInterval?.dayOfMonth;
-
return (
<div>
{isShowName && (
@@ -87,39 +14,6 @@ export const ShowDatabaseBaseInfoComponent = ({ database, isShowName }: Props) =
<div>{database.name || ''}</div>
</div>
)}
-
- <div className="mt-4 mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup interval</div>
- <div>{backupInterval?.interval ? intervalLabels[backupInterval.interval] : ''}</div>
- </div>
-
- {backupInterval?.interval === IntervalType.WEEKLY && (
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup weekday</div>
- <div>
- {displayedWeekday ? weekdayLabels[displayedWeekday as keyof typeof weekdayLabels] : ''}
- </div>
- </div>
- )}
-
- {backupInterval?.interval === IntervalType.MONTHLY && (
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup day of month</div>
- <div>{displayedDayOfMonth || ''}</div>
- </div>
- )}
-
- {backupInterval?.interval !== IntervalType.HOURLY && (
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Backup time of day</div>
- <div>{formattedTime}</div>
- </div>
- )}
-
- <div className="mt-4 mb-1 flex w-full items-center">
- <div className="min-w-[150px]">Store period</div>
- <div>{database.storePeriod ? periodLabels[database.storePeriod] : ''}</div>
- </div>
</div>
);
};
diff --git a/frontend/src/features/databases/ui/show/ShowDatabaseNotifiersComponent.tsx b/frontend/src/features/databases/ui/show/ShowDatabaseNotifiersComponent.tsx
index d0661b03..dde93b75 100644
--- a/frontend/src/features/databases/ui/show/ShowDatabaseNotifiersComponent.tsx
+++ b/frontend/src/features/databases/ui/show/ShowDatabaseNotifiersComponent.tsx
@@ -1,40 +1,27 @@
import { type Database } from '../../../../entity/databases';
-import { BackupNotificationType } from '../../../../entity/databases/model/BackupNotificationType';
import { getNotifierLogoFromType } from '../../../../entity/notifiers/models/getNotifierLogoFromType';
interface Props {
database: Database;
}
-const notificationTypeLabels = {
- [BackupNotificationType.BACKUP_FAILED]: 'backup failed',
- [BackupNotificationType.BACKUP_SUCCESS]: 'backup success',
-};
-
export const ShowDatabaseNotifiersComponent = ({ database }: Props) => {
- const notificationLabels =
- database.sendNotificationsOn?.map((type) => notificationTypeLabels[type]).join(', ') || '';
-
return (
<div>
- <div className="mb-2 flex w-full">
- <div className="min-w-[150px]">Send notification when</div>
- <div>
- {notificationLabels.split(', ').map((label) => (
- <div key={label}>- {label}</div>
- ))}
- </div>
- </div>
-
<div className="flex w-full">
<div className="min-w-[150px]">Notify to</div>
+
<div>
- {database.notifiers?.map((notifier) => (
- <div className="flex items-center" key={notifier.id}>
- <div>- {notifier.name}</div>
- <img src={getNotifierLogoFromType(notifier?.notifierType)} className="ml-1 h-4 w-4" />
- </div>
- ))}
+ {database.notifiers && database.notifiers.length > 0 ? (
+ database.notifiers.map((notifier) => (
+ <div className="flex items-center" key={notifier.id}>
+ <div>- {notifier.name}</div>
+ <img src={getNotifierLogoFromType(notifier?.notifierType)} className="ml-1 h-4 w-4" />
+ </div>
+ ))
+ ) : (
+ <div className="text-gray-500">No notifiers configured</div>
+ )}
</div>
</div>
</div>
diff --git a/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx b/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx
index 212e634c..097058ee 100644
--- a/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx
@@ -64,11 +64,6 @@ export const ShowDatabaseSpecificDataComponent = ({ database }: Props) => {
<div className="min-w-[150px]">Use HTTPS</div>
<div>{database.postgresql?.isHttps ? 'Yes' : 'No'}</div>
</div>
-
- <div className="mb-1 flex w-full items-center">
- <div className="min-w-[150px]">CPU count</div>
- <div>{database.postgresql?.cpuCount || ''}</div>
- </div>
</>
)}
</div>
diff --git a/frontend/src/features/databases/ui/show/ShowDatabaseStorageComponent.tsx b/frontend/src/features/databases/ui/show/ShowDatabaseStorageComponent.tsx
deleted file mode 100644
index 3c4e59ea..00000000
--- a/frontend/src/features/databases/ui/show/ShowDatabaseStorageComponent.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import { type Database } from '../../../../entity/databases';
-import { getStorageLogoFromType } from '../../../../entity/storages/models/getStorageLogoFromType';
-
-interface Props {
- database: Database;
-}
-
-export const ShowDatabaseStorageComponent = ({ database }: Props) => {
- return (
- <div>
- <div className="mb-5 flex w-full items-center">
- <div className="min-w-[150px]">Storage</div>
- <div>{database.storage?.name || ''}</div>{' '}
- <img
- src={getStorageLogoFromType(database.storage?.type)}
- alt="storageIcon"
- className="ml-1 h-4 w-4"
- />
- </div>
- </div>
- );
-};
diff --git a/frontend/src/features/healthcheck/ui/HealthckeckAttemptsComponent.tsx b/frontend/src/features/healthcheck/ui/HealthckeckAttemptsComponent.tsx
index 34e77a27..dca84a3b 100644
--- a/frontend/src/features/healthcheck/ui/HealthckeckAttemptsComponent.tsx
+++ b/frontend/src/features/healthcheck/ui/HealthckeckAttemptsComponent.tsx
@@ -4,7 +4,11 @@ import { useEffect, useState } from 'react';
import type { Database } from '../../../entity/databases';
import { HealthStatus } from '../../../entity/databases/model/HealthStatus';
-import { type HealthcheckAttempt, healthcheckAttemptApi } from '../../../entity/healthcheck';
+import {
+ type HealthcheckAttempt,
+ healthcheckAttemptApi,
+ healthcheckConfigApi,
+} from '../../../entity/healthcheck';
import { getUserShortTimeFormat } from '../../../shared/time/getUserTimeFormat';
interface Props {
@@ -36,6 +40,9 @@ const getAfterDateByPeriod = (period: 'today' | '7d' | '30d' | 'all'): Date => {
};
export const HealthckeckAttemptsComponent = ({ database }: Props) => {
+ const [isHealthcheckConfigLoading, setIsHealthcheckConfigLoading] = useState(false);
+ const [isShowHealthcheckConfig, setIsShowHealthcheckConfig] = useState(false);
+
const [isLoading, setIsLoading] = useState(false);
const [healthcheckAttempts, setHealthcheckAttempts] = useState<HealthcheckAttempt[]>([]);
const [period, setPeriod] = useState<'today' | '7d' | '30d' | 'all'>('today');
@@ -71,21 +78,45 @@ export const HealthckeckAttemptsComponent = ({ database }: Props) => {
};
useEffect(() => {
- loadHealthcheckAttempts();
- }, [database, period]);
+ let isHealthcheckEnabled = false;
+
+ setIsHealthcheckConfigLoading(true);
+ healthcheckConfigApi.getHealthcheckConfig(database.id).then((healthcheckConfig) => {
+ setIsHealthcheckConfigLoading(false);
+
+ if (healthcheckConfig.isHealthcheckEnabled) {
+ isHealthcheckEnabled = true;
+ setIsShowHealthcheckConfig(true);
+
+ loadHealthcheckAttempts();
+ }
+ });
- useEffect(() => {
if (period === 'today') {
- const interval = setInterval(() => {
- loadHealthcheckAttempts(false);
- }, 60_000); // 1 minute
+ if (isHealthcheckEnabled) {
+ const interval = setInterval(() => {
+ loadHealthcheckAttempts(false);
+ }, 60_000); // 1 minute
- return () => clearInterval(interval);
+ return () => clearInterval(interval);
+ }
}
}, [period]);
+ if (isHealthcheckConfigLoading) {
+ return (
+ <div className="mb-5 flex items-center">
+ <Spin />
+ </div>
+ );
+ }
+
+ if (!isShowHealthcheckConfig) {
+ return <div />;
+ }
+
return (
- <div>
+ <div className="mt-5 w-full rounded bg-white p-5 shadow">
<h2 className="text-xl font-bold">Healthcheck attempts</h2>
<div className="mt-4 flex items-center gap-2">
@@ -111,7 +142,7 @@ export const HealthckeckAttemptsComponent = ({ database }: Props) => {
<Spin size="small" />
</div>
) : (
- <div className="flex max-w-[750px] flex-wrap gap-1">
+ <div className="flex flex-wrap gap-1">
{healthcheckAttempts.length > 0 ? (
healthcheckAttempts.map((healthcheckAttempt) => (
<Tooltip
@@ -128,7 +159,7 @@ export const HealthckeckAttemptsComponent = ({ database }: Props) => {
</Tooltip>
))
) : (
- <div className="text-xs text-gray-400">No data</div>
+ <div className="text-xs text-gray-400">No data yet</div>
)}
</div>
)}
diff --git a/frontend/src/features/restores/ui/RestoresComponent.tsx b/frontend/src/features/restores/ui/RestoresComponent.tsx
index f5c6caa3..73ae4e2c 100644
--- a/frontend/src/features/restores/ui/RestoresComponent.tsx
+++ b/frontend/src/features/restores/ui/RestoresComponent.tsx
@@ -108,6 +108,7 @@ export const RestoresComponent = ({ database, backup }: Props) => {
restore(database);
}}
isShowDbVersionHint={false}
+ isBlockDbName
/>
</>
);
diff --git a/frontend/src/features/storages/StorageComponent.tsx b/frontend/src/features/storages/StorageComponent.tsx
index 4365b1f7..e979a4b6 100644
--- a/frontend/src/features/storages/StorageComponent.tsx
+++ b/frontend/src/features/storages/StorageComponent.tsx
@@ -3,7 +3,7 @@ import { Button, Input, Spin } from 'antd';
import { useState } from 'react';
import { useEffect } from 'react';
-import { databaseApi } from '../../entity/databases';
+import { backupConfigApi } from '../../entity/backups';
import { storageApi } from '../../entity/storages';
import type { Storage } from '../../entity/storages';
import { ToastHelper } from '../../shared/toast';
@@ -63,7 +63,7 @@ export const StorageComponent = ({ storageId, onStorageChanged, onStorageDeleted
setIsRemoving(true);
try {
- const isStorageUsing = await databaseApi.isStorageUsing(storage.id);
+ const isStorageUsing = await backupConfigApi.isStorageUsing(storage.id);
if (isStorageUsing) {
alert('Storage is used by some databases. Please remove the storage from databases first.');
setIsShowRemoveConfirm(false);
@@ -260,7 +260,7 @@ export const StorageComponent = ({ storageId, onStorageChanged, onStorageDeleted
<ConfirmationComponent
onConfirm={remove}
onDecline={() => setIsShowRemoveConfirm(false)}
- description="Are you sure you want to remove this storage? This action cannot be undone."
+ description="Are you sure you want to remove this storage? This action cannot be undone. If some backups are using this storage, they will be removed too."
actionText="Remove"
actionButtonColor="red"
/>