Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(frontend): database backup setting improvement (#1938)

Liu Ji3a1a8dd1042c
diff --git a/frontend/src/bbkit/BBSelect.vue b/frontend/src/bbkit/BBSelect.vue
index 2fc45c98fe..99f4283846 100644
--- a/frontend/src/bbkit/BBSelect.vue
+++ b/frontend/src/bbkit/BBSelect.vue
@@ -13,7 +13,7 @@
@click="toggle"
>
<div class="whitespace-nowrap hide-scrollbar overflow-x-auto">
- <template v-if="state.selectedItem">
+ <template v-if="typeof state.selectedItem !== 'undefined'">
<slot
name="menuItem"
:item="state.selectedItem"
diff --git a/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue b/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue
new file mode 100644
index 0000000000..ad9418341e
--- /dev/null
+++ b/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue
@@ -0,0 +1,417 @@
+<template>
+ <div class="w-[30rem] max-w-full flex flex-col items-center">
+ <div class="py-0.5 space-y-6">
+ <div class="flex flex-col gap-y-2">
+ <label class="textlabel">
+ {{ $t("database.backup-setting.form.schedule") }}
+ </label>
+ <NPopover
+ trigger="manual"
+ :show="state.showBackupPolicyEnforcement"
+ :show-arrow="false"
+ placement="bottom-start"
+ >
+ <template #trigger>
+ <div class="flex items-center gap-x-2 text-sm">
+ <label
+ v-for="schedule in PLAN_SCHEDULES"
+ :key="schedule"
+ class="flex items-center gap-x-2"
+ :class="
+ !isAllowedScheduleByPolicy(schedule) &&
+ 'opacity-50 cursor-not-allowed'
+ "
+ @click="setSchedule(schedule)"
+ >
+ <input
+ type="radio"
+ :value="schedule"
+ :checked="schedule === checkedSchedule"
+ :disabled="!isAllowedScheduleByPolicy(schedule)"
+ />
+ <span>{{ nameOfSchedule(schedule) }}</span>
+ </label>
+ </div>
+ </template>
+
+ <router-link
+ class="normal-link text-sm"
+ :to="`/environment/${database.instance.environment.id}`"
+ >
+ {{
+ $t("database.backuppolicy-backup-enforced-and-cant-be-disabled", [
+ $t(`database.backup-policy.${backupPolicy}`),
+ ])
+ }}
+ </router-link>
+ </NPopover>
+ </div>
+
+ <div v-if="checkedSchedule === 'WEEKLY'" class="flex flex-col gap-y-2">
+ <label class="textlabel">
+ {{ $t("database.backup-setting.form.day-of-week") }}
+ </label>
+ <div class="w-[16rem]">
+ <BBSelect
+ :selected-item="
+ localFromUTC(state.setting.hour, state.setting.dayOfWeek)
+ .dayOfWeek
+ "
+ :item-list="AVAILABLE_DAYS_OF_WEEK"
+ @select-item="setDayOfWeek"
+ >
+ <template #menuItem="{ item: day }">
+ {{ nameOfDay(day) }}
+ </template>
+ </BBSelect>
+ </div>
+ </div>
+
+ <div
+ v-if="checkedSchedule === 'WEEKLY' || checkedSchedule === 'DAILY'"
+ class="flex flex-col gap-y-2"
+ >
+ <label class="textlabel">
+ <span>
+ {{ $t("database.backup-setting.form.time-of-day") }}
+ </span>
+ <span class="ml-1 textinfolabel">
+ ({{ Intl.DateTimeFormat().resolvedOptions().timeZone }})
+ </span>
+ </label>
+ <div class="w-[16rem]">
+ <BBSelect
+ :selected-item="
+ localFromUTC(state.setting.hour, state.setting.dayOfWeek).hour
+ "
+ :item-list="AVAILABLE_HOURS_OF_DAY"
+ @select-item="setHour"
+ >
+ <template #menuItem="{ item: hour }">
+ {{ nameOfHour(hour) }}
+ </template>
+ </BBSelect>
+ </div>
+ </div>
+
+ <div
+ v-if="checkedSchedule === 'WEEKLY' || checkedSchedule === 'DAILY'"
+ class="flex flex-col gap-y-2"
+ >
+ <label class="textlabel">
+ {{ $t("database.backup-setting.form.retention-period") }}
+ </label>
+ <div class="w-[16rem]">
+ <input
+ type="text"
+ :value="retentionPeriodDaysInputValue"
+ class="textfield w-full"
+ :class="
+ state.setting.retentionPeriodTs <= 0 &&
+ '!border-red-600 focus:!ring-red-600'
+ "
+ @input="(e: any) => setRetentionPeriodDays(e.target.value)"
+ />
+ </div>
+ </div>
+ </div>
+
+ <div class="w-full mt-5 pt-4 flex justify-end border-t border-block-border">
+ <button
+ type="button"
+ class="btn-normal py-2 px-4"
+ @click.prevent="$emit('cancel')"
+ >
+ {{ $t("common.cancel") }}
+ </button>
+ <button
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ :disabled="!isValid"
+ @click.prevent="handleSave"
+ >
+ {{ $t("common.save") }}
+ </button>
+ </div>
+
+ <div
+ v-if="state.loading"
+ class="absolute inset-0 z-10 bg-white/70 flex items-center justify-center rounded-lg"
+ >
+ <BBSpin />
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, PropType, reactive, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { NPopover } from "naive-ui";
+import {
+ BackupPlanPolicySchedule,
+ BackupSetting,
+ BackupSettingUpsert,
+ Database,
+ unknown,
+} from "@/types";
+import {
+ AVAILABLE_DAYS_OF_WEEK,
+ AVAILABLE_HOURS_OF_DAY,
+ PLAN_SCHEDULES,
+ DEFAULT_BACKUP_RETENTION_PERIOD_TS,
+ levelOfSchedule,
+ localFromUTC,
+ localToUTC,
+ parseScheduleFromBackupSetting,
+ BackupSettingEdit,
+} from "./utils";
+import { pushNotification, useBackupStore } from "@/store";
+
+type LocalState = {
+ setting: BackupSettingEdit;
+ showBackupPolicyEnforcement: boolean;
+ loading: boolean;
+};
+
+const BACKUP_POLICY_ENFORCEMENT_POPUP_DURATION = 5000;
+
+const props = defineProps({
+ database: {
+ required: true,
+ type: Object as PropType<Database>,
+ },
+ allowAdmin: {
+ required: true,
+ type: Boolean,
+ },
+ backupPolicy: {
+ type: String as PropType<BackupPlanPolicySchedule>,
+ default: "UNSET",
+ },
+ backupSetting: {
+ type: Object as PropType<BackupSetting>,
+ default: () => unknown("BACKUP_SETTING"),
+ },
+});
+
+const emit = defineEmits<{
+ (event: "cancel"): void;
+ (event: "update", setting: BackupSetting): void;
+}>();
+
+const state = reactive<LocalState>({
+ setting: extractEditValue(props.backupSetting),
+ showBackupPolicyEnforcement: false,
+ loading: false,
+});
+
+const backupStore = useBackupStore();
+const { t } = useI18n();
+
+const allowDisableAutoBackup = computed(() => {
+ return props.allowAdmin && props.backupPolicy == "UNSET";
+});
+
+const daysOfWeek = computed(() => [
+ t("database.week.Sunday"),
+ t("database.week.Monday"),
+ t("database.week.Tuesday"),
+ t("database.week.Wednesday"),
+ t("database.week.Thursday"),
+ t("database.week.Friday"),
+ t("database.week.Saturday"),
+]);
+
+watch(
+ () => props.backupSetting,
+ () => {
+ state.setting = extractEditValue(props.backupSetting);
+ },
+ { deep: true }
+);
+
+const checkedSchedule = computed((): BackupPlanPolicySchedule => {
+ return parseScheduleFromBackupSetting(state.setting);
+});
+
+const retentionPeriodDaysInputValue = computed((): string => {
+ const seconds = state.setting.retentionPeriodTs;
+ if (!seconds || seconds <= 0) return "";
+ return String(Math.floor(seconds / 3600 / 24));
+});
+
+const isValid = computed((): boolean => {
+ const schedule = checkedSchedule.value;
+ if (!isAllowedScheduleByPolicy(schedule)) {
+ return false;
+ }
+
+ const { setting } = state;
+ if (!setting.enabled) {
+ return true;
+ }
+
+ if (!setting.retentionPeriodTs || setting.retentionPeriodTs <= 0) {
+ return false;
+ }
+
+ return true;
+});
+
+const handleSave = async () => {
+ if (!isValid.value) {
+ return;
+ }
+
+ const { setting } = state;
+
+ const newBackupSetting: BackupSettingUpsert = {
+ databaseId: props.database.id,
+ ...setting,
+ hookUrl: props.backupSetting.hookUrl, // won't modify hookUrl
+ };
+ try {
+ state.loading = true;
+ const updatedBackupSetting = await backupStore.upsertBackupSetting({
+ newBackupSetting,
+ });
+
+ const action = setting.enabled
+ ? t("database.enabled")
+ : t("database.disabled");
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t(
+ "database.action-automatic-backup-for-database-props-database-name",
+ [action, props.database.name]
+ ),
+ });
+
+ emit("update", updatedBackupSetting);
+ } finally {
+ state.loading = false;
+ }
+};
+
+function setSchedule(schedule: BackupPlanPolicySchedule) {
+ if (!isAllowedScheduleByPolicy(schedule)) {
+ // show a popup and automatically disappear after several seconds
+ state.showBackupPolicyEnforcement = true;
+ setTimeout(
+ () => (state.showBackupPolicyEnforcement = false),
+ BACKUP_POLICY_ENFORCEMENT_POPUP_DURATION
+ );
+ return;
+ }
+
+ state.showBackupPolicyEnforcement = false;
+
+ const { setting } = state;
+
+ const normalizeHour = () => {
+ const local = localFromUTC(setting.hour, setting.dayOfWeek);
+ const minHour = AVAILABLE_HOURS_OF_DAY[0];
+ const maxHour = AVAILABLE_HOURS_OF_DAY[AVAILABLE_HOURS_OF_DAY.length - 1];
+ if (local.hour < minHour) local.hour = minHour;
+ if (local.hour > maxHour) local.hour = maxHour;
+ const utc = localToUTC(local.hour, local.dayOfWeek);
+ setting.hour = utc.hour;
+ setting.dayOfWeek = utc.dayOfWeek;
+ };
+
+ switch (schedule) {
+ case "UNSET":
+ setting.enabled = false;
+ break;
+ case "WEEKLY":
+ setting.enabled = true;
+ if (setting.dayOfWeek < 0) {
+ setting.dayOfWeek = 0;
+ }
+ if (!setting.retentionPeriodTs || setting.retentionPeriodTs <= 0) {
+ setting.retentionPeriodTs = DEFAULT_BACKUP_RETENTION_PERIOD_TS;
+ }
+ normalizeHour();
+ break;
+ case "DAILY":
+ setting.enabled = true;
+ setting.dayOfWeek = -1;
+ if (!setting.retentionPeriodTs || setting.retentionPeriodTs <= 0) {
+ setting.retentionPeriodTs = DEFAULT_BACKUP_RETENTION_PERIOD_TS;
+ }
+ normalizeHour();
+ break;
+ }
+}
+
+function setDayOfWeek(dayOfWeek: number) {
+ // Combine the old local hour with the newly selected local dayOfWeek
+ // and convert them to UTC.
+ const local = localFromUTC(state.setting.hour, state.setting.dayOfWeek);
+ const utc = localToUTC(local.hour, dayOfWeek);
+ state.setting.hour = utc.hour;
+ state.setting.dayOfWeek = utc.dayOfWeek;
+}
+
+function setHour(hour: number) {
+ // Combine the old local dayOfWeek with the newly selected local hour
+ // and convert them to UTC.
+ const local = localFromUTC(state.setting.hour, state.setting.dayOfWeek);
+ const utc = localToUTC(hour, local.dayOfWeek);
+ state.setting.hour = utc.hour;
+ state.setting.dayOfWeek = utc.dayOfWeek;
+}
+
+function setRetentionPeriodDays(input: string) {
+ const days = parseInt(input, 10);
+ if (days <= 0 || Number.isNaN(days)) {
+ state.setting.retentionPeriodTs = -1;
+ } else {
+ state.setting.retentionPeriodTs = days * 3600 * 24;
+ }
+}
+
+function extractEditValue(backupSetting: BackupSetting): BackupSettingEdit {
+ return {
+ enabled: backupSetting.enabled,
+ dayOfWeek: backupSetting.dayOfWeek,
+ hour: backupSetting.hour,
+ retentionPeriodTs: backupSetting.retentionPeriodTs,
+ };
+}
+
+function isAllowedScheduleByPolicy(
+ schedule: BackupPlanPolicySchedule
+): boolean {
+ if (schedule === "UNSET") {
+ return allowDisableAutoBackup.value;
+ }
+
+ // In the future, a db's backup setting and its environment's backup policy
+ // can be set separately.
+ // Now, the database backup policy can be configured when its environment
+ // backup policy is "Not enforced"
+ return props.backupPolicy === schedule || props.backupPolicy === "UNSET";
+}
+
+function nameOfSchedule(schedule: BackupPlanPolicySchedule): string {
+ switch (schedule) {
+ case "UNSET":
+ return t("database.backup-setting.schedule.disabled");
+ case "WEEKLY":
+ return t("database.backup-setting.schedule.weekly");
+ case "DAILY":
+ return t("database.backup-setting.schedule.daily");
+ }
+ console.assert(false, "should never reach this line");
+}
+
+function nameOfDay(day: number): string {
+ if (day >= 0 && day < daysOfWeek.value.length) return daysOfWeek.value[day];
+ return `Invalid day of week: ${day}`;
+}
+
+function nameOfHour(hour: number): string {
+ return `${String(hour).padStart(2, "0")}:00`;
+}
+</script>
diff --git a/frontend/src/components/DatabaseBackup/index.ts b/frontend/src/components/DatabaseBackup/index.ts
new file mode 100644
index 0000000000..797bb71072
--- /dev/null
+++ b/frontend/src/components/DatabaseBackup/index.ts
@@ -0,0 +1,5 @@
+import DatabaseBackupSettingForm from "./DatabaseBackupSettingForm.vue";
+
+export * from "./utils";
+
+export { DatabaseBackupSettingForm };
diff --git a/frontend/src/components/DatabaseBackup/utils.ts b/frontend/src/components/DatabaseBackup/utils.ts
new file mode 100644
index 0000000000..9832a3c2e3
--- /dev/null
+++ b/frontend/src/components/DatabaseBackup/utils.ts
@@ -0,0 +1,60 @@
+import { BackupPlanPolicySchedule, BackupSetting } from "@/types";
+
+export type BackupSettingEdit = Pick<
+ BackupSetting,
+ "enabled" | "dayOfWeek" | "hour" | "retentionPeriodTs"
+>;
+
+export const PLAN_SCHEDULES: BackupPlanPolicySchedule[] = [
+ "UNSET",
+ "WEEKLY",
+ "DAILY",
+];
+
+export const AVAILABLE_DAYS_OF_WEEK = [...Array(7).keys()]; // [0...6]
+export const AVAILABLE_HOURS_OF_DAY = [...Array(24).keys()]; // [0...23]
+
+export const DEFAULT_BACKUP_RETENTION_PERIOD_TS = 7 * 3600 * 24; // 7 days
+
+export function parseScheduleFromBackupSetting(
+ backupSetting: BackupSettingEdit
+) {
+ if (!backupSetting.enabled) return "UNSET";
+ if (backupSetting.dayOfWeek === -1) return "DAILY";
+ return "WEEKLY";
+}
+
+export function levelOfSchedule(schedule: BackupPlanPolicySchedule) {
+ return PLAN_SCHEDULES.indexOf(schedule) || 0;
+}
+
+export function localToUTC(hour: number, dayOfWeek: number) {
+ return alignUTC(hour, dayOfWeek, new Date().getTimezoneOffset() * 60);
+}
+
+export function localFromUTC(hour: number, dayOfWeek: number) {
+ return alignUTC(hour, dayOfWeek, -new Date().getTimezoneOffset() * 60);
+}
+
+export function alignUTC(
+ hour: number,
+ dayOfWeek: number,
+ offsetInSecond: number
+) {
+ if (hour != -1) {
+ hour = hour + offsetInSecond / 60 / 60;
+ let dayOffset = 0;
+ if (hour > 23) {
+ hour = hour - 24;
+ dayOffset = 1;
+ }
+ if (hour < 0) {
+ hour = hour + 24;
+ dayOffset = -1;
+ }
+ if (dayOfWeek != -1) {
+ dayOfWeek = (7 + dayOfWeek + dayOffset) % 7;
+ }
+ }
+ return { hour, dayOfWeek };
+}
diff --git a/frontend/src/components/DatabaseBackupPanel.vue b/frontend/src/components/DatabaseBackupPanel.vue
index c09f6f4d4a..597cae6c2a 100644
--- a/frontend/src/components/DatabaseBackupPanel.vue
+++ b/frontend/src/components/DatabaseBackupPanel.vue
@@ -6,30 +6,30 @@
<div
class="flex items-center text-lg leading-6 font-medium text-main"
>
- {{ automaticBackupTitle }}
+ {{ $t("database.automatic-backup") }}
<span class="ml-1 text-success">
{{ $t("database.backup.enabled") }}
</span>
</div>
- <button
- v-if="allowDisableAutoBackup"
- type="button"
- class="ml-4 btn-normal"
- @click.prevent="toggleAutoBackup(false)"
- >
- {{ $t("database.disable-automatic-backup") }}
- </button>
- <router-link
- v-else
- class="normal-link text-sm"
- :to="`/environment/${database.instance.environment.id}`"
- >
- {{
- $t("database.backuppolicy-backup-enforced-and-cant-be-disabled", [
- $t(`database.backup-policy.${backupPolicy}`),
- ])
- }}
- </router-link>
+ <div class="flex items-center">
+ <router-link
+ v-if="hasBackupPolicyViolation"
+ class="flex items-center normal-link text-sm"
+ :to="`/environment/${database.instance.environment.id}`"
+ >
+ <heroicons-outline:exclamation-circle class="w-4 h-4 mr-1" />
+ <span>{{ $t("database.backup-policy-violation") }}</span>
+ </router-link>
+ <button
+ type="button"
+ class="ml-4 btn-normal"
+ @click.prevent="state.showBackupSettingModal = true"
+ >
+ {{
+ hasBackupPolicyViolation ? $t("common.fix") : $t("common.edit")
+ }}
+ </button>
+ </div>
</div>
<div class="mt-2 text-control">
<i18n-t keypath="database.backup-info.template">
@@ -71,7 +71,7 @@
/>
<button
class="btn-primary mt-2"
- :disabled="!allowEdit || !UrlChanged"
+ :disabled="!allowEdit || !urlChanged"
@click.prevent="updateBackupHookUrl()"
>
{{ $t("common.update") }}
@@ -82,7 +82,7 @@
v-else
class="flex items-center text-lg leading-6 font-medium text-main"
>
- {{ automaticBackupTitle }}
+ {{ $t("database.automatic-backup") }}
<span class="ml-1 text-control-light">{{
$t("database.backup.disabled")
}}</span>
@@ -90,7 +90,7 @@
v-if="allowAdmin && !state.autoBackupEnabled"
type="button"
class="ml-4 btn-primary"
- @click.prevent="toggleAutoBackup(true)"
+ @click.prevent="state.showBackupSettingModal = true"
>
{{ $t("database.enable-backup") }}
</button>
@@ -125,6 +125,22 @@
:allow-edit="allowEdit"
/>
</div>
+
+ <BBModal
+ v-if="state.showBackupSettingModal"
+ :title="$t('database.automatic-backup')"
+ @close="state.showBackupSettingModal = false"
+ >
+ <DatabaseBackupSettingForm
+ :database="database"
+ :allow-admin="allowAdmin"
+ :backup-policy="backupPolicy"
+ :backup-setting="state.backupSetting"
+ @cancel="state.showBackupSettingModal = false"
+ @update="updateBackupSetting"
+ />
+ </BBModal>
+
<BBModal
v-if="state.showCreateBackupModal"
:title="$t('database.create-a-manual-backup')"
@@ -152,6 +168,7 @@ import {
onUnmounted,
PropType,
defineComponent,
+ onBeforeMount,
} from "vue";
import {
Backup,
@@ -170,6 +187,12 @@ import DatabaseBackupCreateForm from "../components/DatabaseBackupCreateForm.vue
import { cloneDeep, isEqual } from "lodash-es";
import { useI18n } from "vue-i18n";
import { pushNotification, useBackupStore, usePolicyStore } from "@/store";
+import {
+ DatabaseBackupSettingForm,
+ levelOfSchedule,
+ localFromUTC,
+ parseScheduleFromBackupSetting,
+} from "@/components/DatabaseBackup/";
interface LocalState {
showCreateBackupModal: boolean;
@@ -180,6 +203,8 @@ interface LocalState {
autoBackupHookUrl: string;
autoBackupUpdatedHookUrl: string;
pollBackupsTimer?: ReturnType<typeof setTimeout>;
+ showBackupSettingModal: boolean;
+ backupSetting: BackupSetting | undefined;
}
export default defineComponent({
@@ -187,6 +212,7 @@ export default defineComponent({
components: {
BackupTable,
DatabaseBackupCreateForm,
+ DatabaseBackupSettingForm,
},
props: {
database: {
@@ -215,6 +241,8 @@ export default defineComponent({
autoBackupRetentionPeriodTs: 0,
autoBackupHookUrl: "",
autoBackupUpdatedHookUrl: "",
+ showBackupSettingModal: false,
+ backupSetting: undefined,
});
onUnmounted(() => {
@@ -245,6 +273,8 @@ export default defineComponent({
state.autoBackupRetentionPeriodTs = backupSetting.retentionPeriodTs;
state.autoBackupHookUrl = backupSetting.hookUrl;
state.autoBackupUpdatedHookUrl = backupSetting.hookUrl;
+
+ state.backupSetting = backupSetting;
};
// List PENDING_CREATE backups first, followed by backups in createdTs descending order.
@@ -322,11 +352,19 @@ export default defineComponent({
return (payload as BackupPlanPolicyPayload | undefined)?.schedule;
});
- const allowDisableAutoBackup = computed(() => {
- return props.allowAdmin && backupPolicy.value == "UNSET";
+ const hasBackupPolicyViolation = computed((): boolean => {
+ if (!state.backupSetting) return false;
+ if (!backupPolicy.value) return false;
+ const schedule = parseScheduleFromBackupSetting(state.backupSetting);
+ return levelOfSchedule(schedule) < levelOfSchedule(backupPolicy.value);
});
- const UrlChanged = computed(() => {
+ const updateBackupSetting = (setting: BackupSetting) => {
+ state.showBackupSettingModal = false;
+ assignBackupSetting(setting);
+ };
+
+ const urlChanged = computed(() => {
return !isEqual(state.autoBackupHookUrl, state.autoBackupUpdatedHookUrl);
});
@@ -379,47 +417,7 @@ export default defineComponent({
});
};
- watchEffect(prepareBackupSetting);
-
- const toggleAutoBackup = (on: boolean) => {
- // For now, we hard code the backup time to a time between 0:00 AM ~ 6:00 AM on Sunday local time.
- // Choose a new random time everytime we re-enabling the auto backup. This is a workaround for
- // user to choose a desired backup window.
- const DEFAULT_BACKUP_HOUR = () => Math.floor(Math.random() * 7);
- const DEFAULT_BACKUP_DAYOFWEEK = 0;
- const { hour, dayOfWeek } = localToUTC(
- DEFAULT_BACKUP_HOUR(),
- DEFAULT_BACKUP_DAYOFWEEK
- );
- const newBackupSetting: BackupSettingUpsert = {
- databaseId: props.database.id,
- enabled: on,
- hour: on ? hour : state.autoBackupHour,
- dayOfWeek: on
- ? backupPolicy.value == "DAILY"
- ? -1
- : dayOfWeek
- : state.autoBackupDayOfWeek,
- retentionPeriodTs: on ? 7 * 24 * 3600 : 0,
- hookUrl: "",
- };
- backupStore
- .upsertBackupSetting({
- newBackupSetting: newBackupSetting,
- })
- .then((backupSetting: BackupSetting) => {
- assignBackupSetting(backupSetting);
- const action = on ? t("database.enabled") : t("database.disabled");
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t(
- "database.action-automatic-backup-for-database-props-database-name",
- [action, props.database.name]
- ),
- });
- });
- };
+ onBeforeMount(prepareBackupSetting);
const updateBackupHookUrl = () => {
const newBackupSetting: BackupSettingUpsert = {
@@ -447,56 +445,18 @@ export default defineComponent({
});
};
- function localToUTC(hour: number, dayOfWeek: number) {
- return alignUTC(hour, dayOfWeek, new Date().getTimezoneOffset() * 60);
- }
-
- function localFromUTC(hour: number, dayOfWeek: number) {
- return alignUTC(hour, dayOfWeek, -new Date().getTimezoneOffset() * 60);
- }
-
- function alignUTC(hour: number, dayOfWeek: number, offsetInSecond: number) {
- if (hour != -1) {
- hour = hour + offsetInSecond / 60 / 60;
- var dayOffset = 0;
- if (hour > 23) {
- hour = hour - 24;
- dayOffset = 1;
- }
- if (hour < 0) {
- hour = hour + 24;
- dayOffset = -1;
- }
- if (dayOfWeek != -1) {
- dayOfWeek = (7 + dayOfWeek + dayOffset) % 7;
- }
- }
- return { hour, dayOfWeek };
- }
-
- const automaticBackupTitle = computed((): string => {
- if (backupPolicy.value === "DAILY" || backupPolicy.value === "WEEKLY") {
- return t("database.automatic-x-backup", {
- freq: t(`database.backup-policy.${backupPolicy.value}`).toLowerCase(),
- });
- }
-
- return t("database.automatic-backup");
- });
-
return {
state,
backupList,
autoBackupWeekdayText,
autoBackupHourText,
autoBackupRetentionDays,
- allowDisableAutoBackup,
backupPolicy,
+ hasBackupPolicyViolation,
createBackup,
- toggleAutoBackup,
- UrlChanged,
+ updateBackupSetting,
+ urlChanged,
updateBackupHookUrl,
- automaticBackupTitle,
};
},
});
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 9f76b8f0fb..3f0a42d4f0 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -202,6 +202,7 @@
"backup-and-restore": "Backup and restore",
"write-only": "write only",
"pitr": "PITR",
+ "fix": "Fix",
"go-now": "Go now"
},
"error-page": {
@@ -825,7 +826,21 @@
"no-later-than-now": "Restore point-in-time cannot be later than now."
},
"show-reserved-tables": "Show Bytebase reserved tables",
- "show-reserved-databases": "Show Bytebase reserved databases"
+ "show-reserved-databases": "Show Bytebase reserved databases",
+ "backup-setting": {
+ "schedule": {
+ "disabled": "Disabled",
+ "weekly": "Every week",
+ "daily": "Every day"
+ },
+ "form": {
+ "schedule": "Schedule",
+ "day-of-week": "Day of week",
+ "time-of-day": "Time of day",
+ "retention-period": "Retention period(days)"
+ }
+ },
+ "backup-policy-violation": "Backup policy violation"
},
"repository": {
"branch-observe-file-change": "The branch where Bytebase observes the file change.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 65fdd1146c..2e5b5d8d17 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -202,6 +202,7 @@
"backup-and-restore": "备份与恢复",
"write-only": "仅写入",
"pitr": "PITR",
+ "fix": "修复",
"go-now": "立即前往"
},
"error-page": {
@@ -826,7 +827,21 @@
"no-later-than-now": "恢复的时间点不能晚于当前时间。"
},
"show-reserved-tables": "显示 Bytebase 保留的表",
- "show-reserved-databases": "显示 Bytebase 保留的数据库"
+ "show-reserved-databases": "显示 Bytebase 保留的数据库",
+ "backup-setting": {
+ "schedule": {
+ "disabled": "关闭",
+ "weekly": "每周",
+ "daily": "每天"
+ },
+ "form": {
+ "schedule": "计划",
+ "day-of-week": "星期",
+ "time-of-day": "时间",
+ "retention-period": "保留时长(天)"
+ }
+ },
+ "backup-policy-violation": "违反了备份策略"
},
"repository": {
"branch-observe-file-change": "Bytebase 跟踪文件变更的分支。",