我需要使用命令行指令备份数据库。我从Azure DevOps发布管道启动备份指令,将我的SQL server数据库备份到另一台服务器上的共享文件夹中。以下是我的部署组和任务:
echo Current user: %username%
whoami
SqlCmd -S myserver1 -U myuser -P mypassword -Q "BACKUP DATABASE [mydatabase] TO DISK='\\Server7\DatabaseBackup\Backup.bak' WITH INIT"
这是我的这些说明日志:
2023-03-09T00:49:26.6349085Z ##[section]Starting: Backup Prod Database
2023-03-09T00:49:26.6973085Z ==============================================================================
2023-03-09T00:49:26.6973085Z Task : Command line
2023-03-09T00:49:26.6973085Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2023-03-09T00:49:26.6973085Z Version : 2.212.0
2023-03-09T00:49:26.6973085Z Author : Microsoft Corporation
2023-03-09T00:49:26.6973085Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2023-03-09T00:49:26.6973085Z ==============================================================================
2023-03-09T00:49:27.4461085Z Generating script.
2023-03-09T00:49:27.4773085Z ========================== Starting Command Output ===========================
2023-03-09T00:49:27.4929085Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\azagent\A1\_work\_temp\013b8436-8475-40dd-9d49-f6166ea509cd.cmd""
2023-03-09T00:49:27.5085085Z Current user: SERVER15$
2023-03-09T00:49:27.5397085Z nt authority\system
2023-03-09T00:49:27.7269085Z Msg 3201, Level 16, State 1, Server SERVER6, Line 1
2023-03-09T00:49:27.7269085Z Cannot open backup device '\\server7\DatabaseBackup\Backup.bak'. Operating system error 5(Access is denied.).
2023-03-09T00:49:27.7269085Z Msg 3013, Level 16, State 1, Server SERVER6, Line 1
2023-03-09T00:49:27.7269085Z BACKUP DATABASE is terminating abnormally.
2023-03-09T00:49:27.7737085Z ##[section]Finishing: Backup Prod Database
似乎我们的问题与共享文件夹的访问有关。我在服务器7上创建了共享文件夹。
以下是我的共享规则:
怎么了?当然,我在一个活动目录域中。如果需要,我也可以访问AD服务器。