namespace BackUpSql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//开始备份
private void button2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox5.Text))
{
MessageBox.Show("请选择备份保存地址");
return;
}
string host = textBox1.Text;
string port = textBox2.Text;
string user = textBox3.Text;
string password = textBox4.Text;
string database = textBox6.Text;
string bakPath = textBox5.Text;
if (string.IsNullOrEmpty(textBox1.Text)||string.IsNullOrEmpty(textBox2.Text)||string.IsNullOrEmpty(textBox3.Text)||string.IsNullOrEmpty(textBox4.Text)||string.IsNullOrEmpty(textBox6.Text))
{
MessageBox.Show("表单不能为空");
return;
}
string cmdStr = "/c mysqldump -h" + host + " -P" + port + " -u" + user + " -p" + password + " " + database + " > " + bakPath;
try
{
System.Diagnostics.Process.Start("cmd", cmdStr);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
//选择文件
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog(this) == DialogResult.OK)
{
string FolderName = folderBrowserDialog.SelectedPath;
textBox5.Text = FolderName+"\\"+DateTime.Now.ToString("yyyyMMddHHmmss")+".sql";
}
}
}
}