can someone please help me on this thanks and regards, Praveen Singh
On Mon, Feb 22, 2021 at 6:11 AM Praveen Kumar Singh <[email protected]> wrote: > Hello Everyone, > > I am trying to create a playbook to perform the three below mentioned > tasks. I am able to accomplish the first 2 tasks but for the third one > which is to restore the Database I need to change the host server as > windows server 2. So I am not sure how I can achieve it. The playbook I am > using is below: > > 1) Taking backup on remote windows server 1. > 2) Copying that backup to another remote windows server 2. > 3) Restoring that backup to remote windows server 2. > > --- > - hosts: SQLSERVER > vars: > DbName_Source: > ansible_become_user: Ansible > ansible_become_pass: xyz@123 > DbName_Destination: > > vars_prompt: > - name: DbName_Source > private: no > prompt: Source Database > default: > > - name: DbName_Destination > private: no > prompt: destination Database > default: > > > tasks: > - name: DB Backup > win_shell: | > $Backup = "BACKUP DATABASE {{ DbName_Source }} TO DISK = > 'E:\Backup\{{ DbName_Source }}-Databasebackup.bak'" > Invoke-SqlCmd -Query $Backup > > - name: Sync SQLSERVER to SQLSERVER2 > become: yes > become_method: runas > become_flags: logon_type=new_credentials > logon_flags=netcredentials_only > win_copy: > src: E:\BACKUP\ > dest: \\xx.xxx.xxx.xx\E$\BACKUP\ > remote_src: yes > > - name: DB Restore > win_shell: | > $Restore = "RESTORE DATABASE {{ DbName_Destination }} FROM > DISK = N'E:\BACKUP\{{ DbName_Source > }}-Databasebackup.bak' > WITH FILE = 1, > MOVE N'{{ DbName_Source }}' TO > N'D:\SQLDATA\MSSQL15.MSSQLSERVER\MSSQL\DATA\{{ DbName_Destination }}.mdf', > MOVE N'{{ DbName_Source }}_log' TO N'L:\SQLLOG\{{ > DbName_Destination }}_log.ldf', > NOUNLOAD, REPLACE, STATS = 5" > Invoke-SqlCmd -Query $Restore > > Thanks and Regards, > Praveen Singh > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dw%2BOX_ELaLe287Dqih3nvN8vTdgPhY1cP2sFa%2B5-VOyag%40mail.gmail.com.
