服务器上的mysql自动备份到本地计算机,将数据库从远程服务器备份到本地计算机。...

Hi,

i am taking backup of database from remote server using smo but my problem is backup file is getting stored on remote machine.i want same backup file should be created on local machine instead of remote machine in C# using smo.

how can i achive this using smo in C#.

解决方案

First, typically it''s not a good idea to create a backup on remote computer. If this is just a single case, then fine. But if you''re going to do this repeatedly what''s going to happen for example in case of a network failure, you don''t have a backup at all...

But to the answer. This can be done in numerous ways. The easiest way is direct the backup to remote computer is to use UNC paths. You can use them in the backup command or you can predefine a dump device. Te get more info, have a look at sp_addumpdevice[^] and especially example B.

SQL Server can only ever back up to a drive physically attached to the actual SQL Server machine. You cannot under any circumstances back up a remote SQL Server to your local harddisk - just not possible (neither in SMO, or in SQL Server Management Studio).

As a workaround you can make that your database call a command line program in the host, that send the file by ftp, copy it to some shared folder.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
备份 MySQL 数据并将备份文件上传到远程服务器,你可以使用 Shell 脚本结合 mysqldump 和 scp 命令来实现。以下是一个示例脚本: ```bash #!/bin/bash # MySQL设置 db_user="your_username" db_password="your_password" db_name="your_database_name" # 备份配置 backup_directory="/path/to/backup/directory" backup_filename="backup_$(date +%Y%m%d%H%M%S).sql" remote_user="remote_user" remote_host="remote_host" remote_directory="/path/to/remote/directory" # 创建备份目录 mkdir -p $backup_directory # 使用mysqldump备份MySQL数据库 mysqldump -u $db_user -p$db_password $db_name > $backup_directory/$backup_filename # 将备份文件上传到远程服务器 scp $backup_directory/$backup_filename $remote_user@$remote_host:$remote_directory # 清理本地备份文件 rm $backup_directory/$backup_filename ``` 在上面的脚本中,你需要根据实际情况配置以下变量: - `your_username`:MySQL 用户名 - `your_password`:MySQL 密码 - `your_database_name`:要备份数据库名称 - `/path/to/backup/directory`:本地备份文件存储目录 - `remote_user`:远程服务器用户名 - `remote_host`:远程服务器主机名或 IP 地址 - `/path/to/remote/directory`:远程服务器存储备份文件的目录 脚本首先创建一个用于存储备份文件的目录,然后使用 `mysqldump` 命令将 MySQL 数据库备份到指定的文件中。接下来,使用 `scp` 命令将备份文件上传到远程服务器。最后,脚本清理本地备份文件。 你可以将以上脚本保存为一个文件(例如 `backup_mysql.sh`),然后使用 `chmod +x backup_mysql.sh` 命令赋予脚本执行权限。运行脚本时,它将备份 MySQL 数据并将备份文件上传到远程服务器上指定的目录。 请确保在使用脚本之前进行测试,并注意脚本执行的权限和安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值