Browse Source

feat: 数据库备份 还原

wanggaokun 1 year ago
parent
commit
fd1c96d742

+ 10 - 10
src/api/modules/manage/backupRestore.ts

@@ -14,7 +14,7 @@ export const listBackupRestoreLogApi = (query: any) => {
  * @returns returns
  */
 export const backupApi = (data?: any) => {
-  return http.post<any>('/manage/backupRestore/file/backup', data, { loading: false })
+  return http.post<any>('/manage/backupRestore/file/backup', data, { loading: true })
 }
 
 /**
@@ -22,8 +22,8 @@ export const backupApi = (data?: any) => {
  * @param data data
  * @returns returns
  */
-export const restoreApi = (data?: any) => {
-  return http.post<any>('/manage/backupRestore/file/restore', data, { loading: false })
+export const restoreApi = (id: any) => {
+  return http.get<any>(`/manage/backupRestore/file/restore/${id}`, { loading: true })
 }
 
 /**
@@ -38,27 +38,27 @@ export const exportBackupRestoreLogApi = (data: any) => {
  * @returns returns
  */
 export const syncFileDataApi = (data: any) => {
-  return http.post('/manage/backupRestore/syncFileData', data)
+  return http.post('/manage/backupRestore/syncFileData', data, { loading: true })
 }
 /**
- * @name 同步
+ * @name 备份
  * @returns returns
  */
 export const dbBackupApi = (data: any) => {
-  return http.post('/manage/backupRestore/db/backup', data)
+  return http.post('/manage/backupRestore/db/backup', data, { loading: true })
 }
 /**
- * @name 同步
+ * @name 备份
  * @returns returns
  */
 export const dbBackupAllApi = (data: any) => {
-  return http.post('/manage/backupRestore/db/backup/all', data)
+  return http.post('/manage/backupRestore/db/backup/all', data, { loading: true })
 }
 
 /**
  * @name 数据库恢复
  * @returns returns
  */
-export const dbRestoreApi = () => {
-  return http.get('/manage/backupRestore/db/restore')
+export const dbRestoreApi = (id: string | number) => {
+  return http.get(`/manage/backupRestore/db/restore/${id}`, { loading: true })
 }

+ 18 - 3
src/views/manage/backupRestore/index.vue

@@ -18,7 +18,15 @@
         <el-button type="primary" link icon="View" v-auth="['manage:backupRestore:query']" @click="openDialog(3, '备份恢复日志查看', scope.row)">
           查看
         </el-button>
-        <el-button type="primary" v-if="scope.row.operateType === '备份'" link icon="View" @click="restore()"> 恢复 </el-button>
+        <el-button
+          type="primary"
+          v-if="scope.row.operateType === '备份' && scope.row.restoreStatus !== '成功'"
+          link
+          icon="View"
+          @click="restore(scope.row)"
+        >
+          恢复
+        </el-button>
       </template>
     </ProTable>
     <FormDialog ref="formDialogRef" />
@@ -59,8 +67,8 @@ const backup = () => {
     }
   })
 }
-const restore = () => {
-  restoreApi().then(res => {
+const restore = (val: any) => {
+  restoreApi(val.id).then(res => {
     if (res.code === 200) {
       proTable.value?.getTableList()
       ElMessage.success('恢复成功')
@@ -137,6 +145,13 @@ const setItemsOptions = () => {
         placeholder: '请输入数据类型'
       }
     },
+    {
+      label: '目标',
+      prop: 'target',
+      compOptions: {
+        placeholder: '请输入操作方式'
+      }
+    },
     {
       label: '操作方式',
       prop: 'operateType',

+ 78 - 16
src/views/manage/dbBackupRestore/index.vue

@@ -10,18 +10,27 @@
     >
       <!-- 表格 header 按钮 -->
       <template #tableHeader>
-        <el-button type="primary" v-auth="['manage:backupRestore:sync']" @click="backup()"> 备份文件 </el-button>
-        <el-button type="primary" v-auth="['manage:faultCase:sync']" icon="Refresh" @click="syncFileData()"> 同步文件至服务器 </el-button>
+        <el-button type="primary" v-auth="['manage:backupRestore:sync']" @click="backupAll()"> 全量备份 </el-button>
+        <el-button type="primary" v-auth="['manage:faultCase:sync']" @click="backup()"> 增量备份 </el-button>
       </template>
       <!-- 表格操作 -->
       <template #operation="scope">
         <el-button type="primary" link icon="View" v-auth="['manage:backupRestore:query']" @click="openDialog(3, '备份恢复日志查看', scope.row)">
           查看
         </el-button>
-        <el-button type="primary" v-if="scope.row.operateType === '备份'" link icon="View" @click="restore()"> 恢复 </el-button>
+        <el-button
+          type="primary"
+          v-if="scope.row.operateType === '备份' && scope.row.restoreStatus !== '成功'"
+          link
+          icon="View"
+          @click="restore(scope.row)"
+        >
+          恢复
+        </el-button>
       </template>
     </ProTable>
     <FormDialog ref="formDialogRef" />
+    <TableDialog ref="tableDialogRef" @submit-form="submitForm" />
   </div>
 </template>
 
@@ -30,8 +39,10 @@ import { ref, reactive } from 'vue'
 import { ElMessage } from 'element-plus'
 import ProTable from '@/components/ProTable/index.vue'
 import FormDialog from '@/components/FormDialog/index.vue'
+import TableDialog from '@/components/TableDialog/index.vue'
 import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
-import { listBackupRestoreLogApi, dbBackupAllApi, dbRestoreApi, syncFileDataApi } from '@/api/modules/manage/backupRestore'
+import { listBackupRestoreLogApi, dbBackupAllApi, dbRestoreApi, dbBackupApi } from '@/api/modules/manage/backupRestore'
+import { listDbTableApi } from '@/api/modules/tool/gen'
 
 // ProTable 实例
 const proTable = ref<ProTableInstance>()
@@ -49,7 +60,7 @@ const dataType = [
   { label: '数据库', value: 2 }
 ]
 const initParam = reactive({ type: 2 })
-const backup = () => {
+const backupAll = () => {
   dbBackupAllApi({}).then(res => {
     if (res.code === 200) {
       proTable.value?.getTableList()
@@ -59,8 +70,8 @@ const backup = () => {
     }
   })
 }
-const restore = () => {
-  dbRestoreApi().then(res => {
+const restore = (val: any) => {
+  dbRestoreApi(val.id).then(res => {
     if (res.code === 200) {
       proTable.value?.getTableList()
       ElMessage.success('恢复成功')
@@ -69,15 +80,33 @@ const restore = () => {
     }
   })
 }
-const syncFileData = () => {
-  syncFileDataApi({}).then(res => {
-    if (res.code === 200) {
-      ElMessage.success('同步成功')
-      proTable.value?.getTableList()
-    } else {
-      ElMessage.error(res.msg)
-    }
-  })
+// const syncFileData = () => {
+//   syncFileDataApi({}).then(res => {
+//     if (res.code === 200) {
+//       ElMessage.success('同步成功')
+//       proTable.value?.getTableList()
+//     } else {
+//       ElMessage.error(res.msg)
+//     }
+//   })
+// }
+// 表格弹框提交
+const submitForm = () => {
+  proTable.value?.getTableList()
+}
+// 批量添加表信息
+const tableDialogRef = ref<InstanceType<typeof TableDialog> | null>(null)
+const backup = () => {
+  const params = {
+    title: '备份表',
+    width: 880,
+    toolButton: false,
+    rowKey: 'tableName',
+    columns: subColumns,
+    api: dbBackupApi,
+    getTableList: listDbTableApi
+  }
+  tableDialogRef.value?.openDialog(params)
 }
 
 const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
@@ -114,6 +143,10 @@ const columns = reactive<ColumnProps<any>[]>([
       el: 'input'
     }
   },
+  {
+    prop: 'target',
+    label: '目标'
+  },
   {
     prop: 'status',
     label: '备份状态'
@@ -137,6 +170,13 @@ const setItemsOptions = () => {
         placeholder: '请输入数据类型'
       }
     },
+    {
+      label: '目标',
+      prop: 'target',
+      compOptions: {
+        placeholder: '请输入操作方式'
+      }
+    },
     {
       label: '操作方式',
       prop: 'operateType',
@@ -153,4 +193,26 @@ const setItemsOptions = () => {
     }
   ]
 }
+// 表格配置项
+const subColumns: ColumnProps[] = [
+  { type: 'selection', fixed: 'left', width: 60 },
+  {
+    prop: 'tableName',
+    label: '表名称',
+    search: {
+      el: 'input'
+    }
+  },
+  {
+    prop: 'tableComment',
+    label: '表描述',
+    search: {
+      el: 'input'
+    }
+  },
+  {
+    prop: 'createTime',
+    label: '创建时间'
+  }
+]
 </script>