Beispiel #1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            rtxtOutput.ResetText();

            string schemas = cmbUsers.Text;

            if (string.IsNullOrWhiteSpace(schemas))
            {
                return;
            }

            string fileName = txtFileName.Text.Trim();

            if (string.IsNullOrWhiteSpace(fileName))
            {
                return;
            }

            string command = $"EXPDP USERID={Vars.UserId}/\"\"\"{Vars.Password}\"\"\"@{Vars.Server} schemas={schemas} directory=DATA_PUMP_DIR dumpfile={fileName}.dmp logfile={fileName}.log";

            this.IsWorking = true;

            Task task = new Task(() =>
            {
                CommandUtility.Execute2(command, a =>
                {
                    UpdateUIInThread(() => richTextBoxOutputer.AppendText(a));
                });
            });

            task.Start();

            task.ContinueWith((a) =>
            {
                this.IsWorking = false;

                MessageBox.Show(this, "导出完成");
            });
        }
Beispiel #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            rtxtOutput.ResetText();

            string destSchema = txtDestUser.Text.Trim();

            if (string.IsNullOrWhiteSpace(destSchema))
            {
                return;
            }

            string targetSchema = cmbUsers.Text;

            if (string.IsNullOrWhiteSpace(targetSchema))
            {
                return;
            }

            string dumpfile = cmbDmps.Text;

            if (string.IsNullOrWhiteSpace(dumpfile))
            {
                return;
            }

            // 确定导入到现有用户还是创建新用户
            bool userExists = DatabaseUtility.UserExists(targetSchema);

            string command = string.Empty;

            if (destSchema.Equals(targetSchema, StringComparison.CurrentCultureIgnoreCase))
            {
                command = $"IMPDP USERID={Vars.UserId}/\"\"\"{Vars.Password}\"\"\"@{Vars.Server} directory=DATA_PUMP_DIR dumpfile={dumpfile}.dmp logfile={dumpfile}.log";
            }
            else
            {
                command = $"IMPDP USERID={Vars.UserId}/\"\"\"{Vars.Password}\"\"\"@{Vars.Server} directory=DATA_PUMP_DIR dumpfile={dumpfile}.dmp logfile={dumpfile}.log remap_schema={destSchema}:{targetSchema}";
            }

            this.IsWorking = true;

            Task task = new Task(() =>
            {
                CommandUtility.Execute2(command, a =>
                {
                    UpdateUIInThread(() => richTextBoxOutputer.AppendText(a));
                });
            });

            task.Start();

            task.ContinueWith((a) =>
            {
                // 如果是创建新用户,则在导入后赋予权限以及设置默认密码
                if (!userExists && DatabaseUtility.UserExists(targetSchema))
                {
                    DatabaseUtility.GrantRole(targetSchema, "DBA");
                    DatabaseUtility.GrantRole(targetSchema, "CONNECT");
                    DatabaseUtility.GrantRole(targetSchema, "RESOURCE");
                    DatabaseUtility.GrantRole(targetSchema, "UNLIMITED TABLESPACE");

                    DatabaseUtility.UpdatePassword(targetSchema, Vars.DefaultPassword);
                }

                this.IsWorking = false;

                MessageBox.Show(this, "导入完成");
            });
        }