问题
I am trying to grab a MySQL database from a Linux box, and, with a little help from others, I have learned that the best way to grab the database is to do a mysqldump command. After looking at the Session.ExecuteCommand function, here is my code so far
static void Main(string[] args)
{
SessionOptions sessionSettings = new SessionOptions
{
Protocol = Protocol.SCP,
HostName = "*****",
UserName = "userName",
Password = "password",
SshHostKeyFingerprint = "ssh-rsa 2048 ******************"
};
using (Session session = new Session())
{
session.Open(sessionSettings);
string strFilePath = @"/tmp/mySqlDatabases.gz";
string strCommand = string.Format("mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}",
sessionSettings.UserName, sessionSettings.Password, tempFilePath);
session.ExecuteCommand(strCommand).Check();
session.GetFiles(strFilePath, @"C:\temp\mySqlDatabases.gz").Check();
}
}
When this runs, I am able to get the gz file with no issues, however I am not sure what I am suppose to do with the new file. When I extract it, I am given a 1 KB file that I have no clue how to use nor does it look like a database. Do I need to restore this dump file in order to get the database I want or is there another step to this that I am missing?
来源:https://stackoverflow.com/questions/39598774/winscp-issue-grabbing-mysql-database